Skip to content

Commit

Permalink
More refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
totof3110 committed Mar 10, 2015
1 parent 15fede6 commit 2c30f1f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.appdirect.isv.wicket.application;

import lombok.Getter;

import org.apache.wicket.Application;
import org.apache.wicket.Page;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.openid.OpenIDConsumer;
Expand All @@ -28,6 +31,8 @@ public class ISVApplication extends AuthenticatedWebApplication {
@Override
protected void init() {
super.init();
// Allow wicket to inject spring beans into components using @SpringBean annotation
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
new AnnotatedMountScanner().scanPackage("com.appdirect.isv").mount(this);
getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);
}
Expand All @@ -54,64 +59,27 @@ protected Class<? extends AuthenticatedWebSession> getWebSessionClass() {
/*
* Spring Beans
*/
protected OpenIDConsumer openIdConsumer;
protected AuthenticationManager authenticationManager;
protected ISVService isvService;
protected IntegrationService integrationService;
protected ServerConfiguration serverConfiguration;
protected OAuthUrlSigner oauthUrlSigner;

public OpenIDConsumer getOpenIdConsumer() {
return openIdConsumer;
}

@Getter
@Autowired
public void setOpenIdConsumer(OpenIDConsumer openIdConsumer) {
this.openIdConsumer = openIdConsumer;
}

public AuthenticationManager getAuthenticationManager() {
return authenticationManager;
}
private OpenIDConsumer openIdConsumer;

@Getter
@Autowired
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}

public ISVService getIsvService() {
return isvService;
}
private AuthenticationManager authenticationManager;

@Getter
@Autowired
public void setIsvService(ISVService isvService) {
this.isvService = isvService;
}

public IntegrationService getIntegrationService() {
return integrationService;
}
private ISVService isvService;

@Getter
@Autowired
public void setIntegrationService(IntegrationService integrationService) {
this.integrationService = integrationService;
}

public ServerConfiguration getServerConfiguration() {
return serverConfiguration;
}
private IntegrationService integrationService;

@Getter
@Autowired
public void setServerConfiguration(ServerConfiguration serverConfiguration) {
this.serverConfiguration = serverConfiguration;
}

public OAuthUrlSigner getOauthUrlSigner() {
return oauthUrlSigner;
}
private ServerConfiguration serverConfiguration;

@Getter
@Autowired
public void setOauthUrlSigner(OAuthUrlSigner oauthUrlSigner) {
this.oauthUrlSigner = oauthUrlSigner;
}
private OAuthUrlSigner oauthUrlSigner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BaseWebPage(PageParameters parameters) {
// Account or user was deleted.
currentAccount = null;
}
add(new BookmarkablePageLink<Void>("home", ISVApplication.get().getHomePage()));
add(new BookmarkablePageLink<Void>("home", getApplication().getHomePage()));
PageParameters accountPageParameters = new PageParameters();
if (currentAccount != null) {
accountPageParameters.set(AccountPage.ACCOUNT_ID_PARAM, currentAccount.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AccountPage(final PageParameters parameters) {
@Override
public void onClick(AjaxRequestTarget target) {
ISVApplication.get().getIsvService().delete(accountBean);
setResponsePage(ISVApplication.get().getHomePage());
setResponsePage(getApplication().getHomePage());
}
});
final DataView<AddonBean> addonDataView = new DataView<AddonBean>("addonrow", new ListDataProvider<AddonBean>(accountBean.getAddons())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public OpenIDReturnPage(PageParameters parameters) {
if (ISVSession.get().authenticate(token)) {
getSession().info("Welcome back!");
continueToOriginalDestination();
throw new RedirectToPageException(ISVApplication.get().getHomePage());
throw new RedirectToPageException(getApplication().getHomePage());
}
} catch (UsernameNotFoundException e) {
getSession().error(String.format("There is no user with OpenID %s", token.getIdentityUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
import org.apache.commons.lang3.NotImplementedException;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.request.Request;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.hibernate.ObjectNotFoundException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import com.appdirect.isv.backend.security.service.UserDetailsImpl;
import com.appdirect.isv.backend.user.vo.UserBean;
import com.appdirect.isv.wicket.application.ISVApplication;

/**
* Our custom web session implementation.
*/
public class ISVSession extends AuthenticatedWebSession {
private static final long serialVersionUID = -3035882552790674791L;

@SpringBean(name = "authenticationManager")
private AuthenticationManager authenticationManager;

public ISVSession(Request request) {
super(request);
Injector.get().inject(this);
}

@Override
Expand All @@ -32,7 +38,7 @@ public boolean authenticate(String username, String password) {
public boolean authenticate(Authentication token) {
boolean authenticated = false;
try {
Authentication authentication = ISVApplication.get().getAuthenticationManager().authenticate(token);
Authentication authentication = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(authentication);
authenticated = authentication.isAuthenticated();
} catch (AuthenticationException e) {
Expand Down

0 comments on commit 2c30f1f

Please sign in to comment.