Skip to content

Commit

Permalink
- Refactor UserAuthorizationService
Browse files Browse the repository at this point in the history
- Show message on login page
- Add missing translations
  • Loading branch information
n4devca committed May 15, 2019
1 parent 478c9ae commit a87e7fb
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import ca.n4dev.aegaeon.server.security.AccessTokenAuthenticationProvider;
import ca.n4dev.aegaeon.server.security.PromptAwareAuthenticationFilter;
import ca.n4dev.aegaeon.server.service.AuthenticationService;
import ca.n4dev.aegaeon.server.service.AuthorizationService;
import ca.n4dev.aegaeon.server.service.UserAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -190,14 +190,14 @@ public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityCon
private ControllerErrorInterceptor controllerErrorInterceptor;

@Autowired
private AuthorizationService authorizationService;
private UserAuthorizationService userAuthorizationService;

@Autowired
private PasswordEncoder passwordEncoder;


public PromptAwareAuthenticationFilter promptAwareAuthenticationFilter() {
return new PromptAwareAuthenticationFilter(this.authorizationService, this.controllerErrorInterceptor);
return new PromptAwareAuthenticationFilter(this.userAuthorizationService, this.controllerErrorInterceptor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import ca.n4dev.aegaeon.api.protocol.FlowUtils;
import ca.n4dev.aegaeon.api.protocol.GrantType;
import ca.n4dev.aegaeon.api.protocol.Prompt;
import ca.n4dev.aegaeon.api.token.OAuthUser;
import ca.n4dev.aegaeon.server.controller.exception.InternalAuthorizationException;
import ca.n4dev.aegaeon.server.controller.exception.InvalidClientIdException;
import ca.n4dev.aegaeon.server.controller.exception.InvalidClientRedirectionException;
Expand All @@ -43,7 +42,6 @@
import ca.n4dev.aegaeon.server.controller.exception.InvalidScopeException;
import ca.n4dev.aegaeon.server.security.AegaeonUserDetails;
import ca.n4dev.aegaeon.server.service.AuthorizationCodeService;
import ca.n4dev.aegaeon.server.service.AuthorizationService;
import ca.n4dev.aegaeon.server.service.BaseTokenService;
import ca.n4dev.aegaeon.server.service.ScopeService;
import ca.n4dev.aegaeon.server.service.TokenServicesFacade;
Expand Down Expand Up @@ -87,20 +85,17 @@ public class AuthorizationController {

private UserAuthorizationService userAuthorizationService;
private AuthorizationCodeService authorizationCodeService;
private AuthorizationService authorizationService;
private TokenServicesFacade tokenServicesFacade;
private ScopeService scopeService;
private UserService userService;

@Autowired
public AuthorizationController(AuthorizationService pAuthorizationService,
UserAuthorizationService pUserAuthorizationService,
public AuthorizationController(UserAuthorizationService pUserAuthorizationService,
AuthorizationCodeService pAuthorizationCodeService,
ScopeService pScopeService,
TokenServicesFacade pTokenServicesFacade,
UserService pUserService) {

authorizationService = pAuthorizationService;
userAuthorizationService = pUserAuthorizationService;
authorizationCodeService = pAuthorizationCodeService;
scopeService = pScopeService;
Expand Down Expand Up @@ -136,7 +131,7 @@ public ModelAndView authorize(@RequestParam(value = "response_type", required =
Assert.notEmpty(pRedirectUri, () -> new InvalidClientRedirectionException(authRequest));

// Make sure the client and redirection is valid
if (!authorizationService.isClientInfoValid(pClientPublicId, pRedirectUri)) {
if (!userAuthorizationService.isClientInfoValid(pClientPublicId, pRedirectUri)) {
throw new InvalidClientRedirectionException(authRequest);
}

Expand All @@ -157,10 +152,10 @@ public ModelAndView authorize(@RequestParam(value = "response_type", required =

Assert.notNull(grantType, () -> new InvalidFlowException(authRequest));

boolean isAlreadyAuthorized = this.authorizationService.isAuthorized(pAuthentication,
pClientPublicId,
pRedirectUri,
pScope);
boolean isAlreadyAuthorized = this.userAuthorizationService.isAuthorized(pAuthentication,
pClientPublicId,
pRedirectUri,
pScope);

try {
if (authRequest.getPromptType() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
*/
package ca.n4dev.aegaeon.server.controller;

import ca.n4dev.aegaeon.server.utils.Utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import ca.n4dev.aegaeon.server.utils.Utils;

/**
* SimpleHomeController.java
*
*
* A simple controller managing the homepage or redirecting to user-account if the home is disabled.
*
*
* @author by rguillemette
* @since Jul 14, 2017
*/
Expand All @@ -42,29 +41,30 @@
//@ConditionalOnProperty(prefix = "aegaeon.modules", name = "home", havingValue = "true", matchIfMissing = false)
public class SimpleHomeController {

public static final String URL = "/";

private String homeModule;

/**
* Default Constructor.
* @param pHomeModuleEnable If home is enabled.
*/
public SimpleHomeController(@Value("${aegaeon.modules.home:false}") String pHomeModuleEnable) {
this.homeModule = pHomeModuleEnable;
}

public static final String URL = "/";

private String homeModule;

/**
* Default Constructor.
*
* @param pHomeModuleEnable If home is enabled.
*/
public SimpleHomeController(@Value("${aegaeon.modules.home:false}") String pHomeModuleEnable) {
this.homeModule = pHomeModuleEnable;
}

/**
* @return Aegaeon home page.
*/
@RequestMapping("")
public ModelAndView home() {
if (Utils.FALSE.equalsIgnoreCase(homeModule)) {
// home is disabled
return new ModelAndView(new RedirectView(SimpleUserAccountController.URL, true));
}
return new ModelAndView("homepage");

if (Utils.FALSE.equalsIgnoreCase(homeModule)) {
// home is disabled
return new ModelAndView(new RedirectView(SimpleUserAccountController.URL, true));
}

return new ModelAndView("homepage");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import ca.n4dev.aegaeon.server.controller.exception.InvalidGrantTypeException;
import ca.n4dev.aegaeon.server.controller.exception.InvalidRequestMethodException;
import ca.n4dev.aegaeon.server.controller.exception.InvalidScopeException;
import ca.n4dev.aegaeon.server.service.AuthorizationService;
import ca.n4dev.aegaeon.server.service.TokenServicesFacade;
import ca.n4dev.aegaeon.server.service.UserAuthorizationService;
import ca.n4dev.aegaeon.server.utils.Assert;
import ca.n4dev.aegaeon.server.utils.Utils;
import ca.n4dev.aegaeon.server.view.TokenResponse;
Expand Down Expand Up @@ -65,18 +65,18 @@ public class TokensController {
public static final String URL = "/token";
private static final Logger LOGGER = LoggerFactory.getLogger(TokensController.class);
private TokenServicesFacade tokenServicesFacade;
private AuthorizationService authorizationService;
private UserAuthorizationService userAuthorizationService;

/**
* Default Constructor.
*
* @param pTokenServicesFacade The token service facade.
* @param pAuthorizationService The authorization service..
* @param pUserAuthorizationService The authorization service.
*/
@Autowired
public TokensController(TokenServicesFacade pTokenServicesFacade,
AuthorizationService pAuthorizationService) {
authorizationService = pAuthorizationService;
UserAuthorizationService pUserAuthorizationService) {
userAuthorizationService = pUserAuthorizationService;
tokenServicesFacade = pTokenServicesFacade;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public ResponseEntity<TokenResponse> token(
Assert.notEmpty(pRedirectUri, () -> new InvalidClientRedirectionException(tokenRequest));

// Make sure the client and redirection is valid
if (!authorizationService.isClientInfoValid(clientPublicId, pRedirectUri)) {
if (!userAuthorizationService.isClientInfoValid(clientPublicId, pRedirectUri)) {
throw new InvalidClientRedirectionException(tokenRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import ca.n4dev.aegaeon.api.protocol.Prompt;
import ca.n4dev.aegaeon.server.controller.AuthorizationController;
import ca.n4dev.aegaeon.server.controller.ControllerErrorInterceptor;
import ca.n4dev.aegaeon.server.service.AuthorizationService;
import ca.n4dev.aegaeon.server.service.UserAuthorizationService;
import ca.n4dev.aegaeon.server.utils.UriBuilder;
import ca.n4dev.aegaeon.server.utils.Utils;
import org.slf4j.Logger;
Expand All @@ -64,19 +64,19 @@ public class PromptAwareAuthenticationFilter extends GenericFilterBean {

private static final Logger LOGGER = LoggerFactory.getLogger(PromptAwareAuthenticationFilter.class);

private AuthorizationService authorizationService;
private UserAuthorizationService userAuthorizationService;
private ControllerErrorInterceptor controllerErrorInterceptor;

/**
* Constructor.
*
* @param pAuthorizationService The authorization service.
* @param pUserAuthorizationService The authorization service.
* @param pControllerErrorInterceptor The ControllerErrorInterceptor to handle error.
*/
@Autowired
public PromptAwareAuthenticationFilter(AuthorizationService pAuthorizationService,
public PromptAwareAuthenticationFilter(UserAuthorizationService pUserAuthorizationService,
ControllerErrorInterceptor pControllerErrorInterceptor) {
authorizationService = pAuthorizationService;
userAuthorizationService = pUserAuthorizationService;
controllerErrorInterceptor = pControllerErrorInterceptor;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private boolean isAuthorizedAlready(String pClientId, String pRedirectionUrl, St
Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();

if (existingAuth == null) {
return authorizationService.isAuthorized(existingAuth, pClientId, pRedirectionUrl, pScopeParam);
return userAuthorizationService.isAuthorized(existingAuth, pClientId, pRedirectionUrl, pScopeParam);
}

return false;
Expand All @@ -199,7 +199,7 @@ private boolean isValidRequest(AuthRequest pAuthRequest) {

if (hasProperParams) {
// OK, then, check the client
return authorizationService.isClientInfoValid(pAuthRequest.getClientId(), pAuthRequest.getRedirectUri());
return userAuthorizationService.isClientInfoValid(pAuthRequest.getClientId(), pAuthRequest.getRedirectUri());
}

return false;
Expand Down
Loading

0 comments on commit a87e7fb

Please sign in to comment.