@Test public void test_checkAppTokenAccess_noToken() throws Throwable { setUpTokenMocking("test"); User user = new User(); prepareMethodCalls(null, "token", user); AppTokenCheck check = createAppTokenAccessCheckAnnotation("token"); Object returnObj = aspectToTest.checkAppTokenAccess(joinPoint, check); Assert.assertEquals(ResponseEntity.class, returnObj.getClass()); Assert.assertEquals(HttpStatus.UNAUTHORIZED, ((ResponseEntity) returnObj).getStatusCode()); }
@Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") public Object checkAppTokenAccess(ProceedingJoinPoint joinPoint, AppTokenCheck tokenCheck) throws Throwable { logger.debug("Checking App access token for REST endpoint."); UserTokenObject userTokenObj = extractUserTokenInfo(joinPoint, tokenCheck.value(), tokenCheck.providerToken()); User user = userTokenObj.user; String token = userTokenObj.token; String providerToken = userTokenObj.parameter; if (user == null) { throw new AspectMisconfigurationException( "User object is missing in method."); } TokenHolder holder = new TokenHolder(); ResponseEntity<String> authResult = checkAuthorization(token, AppTokenChecker.ID, holder, null); if (authResult != null) { return authResult; } IAppToken appToken = ((IAppToken)holder.tokenContents); String checkerId = identityProviderRegistry.getCheckerId(appToken.getProviderId(), appToken.getAuthorizationType()); if (checkerId == null) { logger.warn("Token references non existing identity provider."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The token you sent references an identity provider that is not registered with Giles."); return generateResponse(msgs, HttpStatus.UNAUTHORIZED); } TokenHolder apiTokenHolder = new TokenHolder(); ResponseEntity<String> apiTokenAuthResult = checkAuthorization(providerToken, checkerId, apiTokenHolder, appToken.getAppId()); if (apiTokenAuthResult != null) { return apiTokenAuthResult; } IApiTokenContents tokenContents = (IApiTokenContents) apiTokenHolder.tokenContents; User userInToken = userManager.findUserByProviderUserId(tokenContents.getUsername(), appToken.getProviderId()); if (userInToken == null) { logger.info("The user doesn't seem to have a Giles account."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user doesn't seem to have a Giles account."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } if (userInToken.getAccountStatus() != AccountStatus.APPROVED) { logger.info("The user account you are using has not been approved. Please contact a Giles administrator."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user account you are using has not been approved. Please contact a Giles administrator."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } fillUser(userInToken, user); return joinPoint.proceed(); }
RestSecurityAspect { @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") public Object checkAppTokenAccess(ProceedingJoinPoint joinPoint, AppTokenCheck tokenCheck) throws Throwable { logger.debug("Checking App access token for REST endpoint."); UserTokenObject userTokenObj = extractUserTokenInfo(joinPoint, tokenCheck.value(), tokenCheck.providerToken()); User user = userTokenObj.user; String token = userTokenObj.token; String providerToken = userTokenObj.parameter; if (user == null) { throw new AspectMisconfigurationException( "User object is missing in method."); } TokenHolder holder = new TokenHolder(); ResponseEntity<String> authResult = checkAuthorization(token, AppTokenChecker.ID, holder, null); if (authResult != null) { return authResult; } IAppToken appToken = ((IAppToken)holder.tokenContents); String checkerId = identityProviderRegistry.getCheckerId(appToken.getProviderId(), appToken.getAuthorizationType()); if (checkerId == null) { logger.warn("Token references non existing identity provider."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The token you sent references an identity provider that is not registered with Giles."); return generateResponse(msgs, HttpStatus.UNAUTHORIZED); } TokenHolder apiTokenHolder = new TokenHolder(); ResponseEntity<String> apiTokenAuthResult = checkAuthorization(providerToken, checkerId, apiTokenHolder, appToken.getAppId()); if (apiTokenAuthResult != null) { return apiTokenAuthResult; } IApiTokenContents tokenContents = (IApiTokenContents) apiTokenHolder.tokenContents; User userInToken = userManager.findUserByProviderUserId(tokenContents.getUsername(), appToken.getProviderId()); if (userInToken == null) { logger.info("The user doesn't seem to have a Giles account."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user doesn't seem to have a Giles account."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } if (userInToken.getAccountStatus() != AccountStatus.APPROVED) { logger.info("The user account you are using has not been approved. Please contact a Giles administrator."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user account you are using has not been approved. Please contact a Giles administrator."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } fillUser(userInToken, user); return joinPoint.proceed(); } }
RestSecurityAspect { @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") public Object checkAppTokenAccess(ProceedingJoinPoint joinPoint, AppTokenCheck tokenCheck) throws Throwable { logger.debug("Checking App access token for REST endpoint."); UserTokenObject userTokenObj = extractUserTokenInfo(joinPoint, tokenCheck.value(), tokenCheck.providerToken()); User user = userTokenObj.user; String token = userTokenObj.token; String providerToken = userTokenObj.parameter; if (user == null) { throw new AspectMisconfigurationException( "User object is missing in method."); } TokenHolder holder = new TokenHolder(); ResponseEntity<String> authResult = checkAuthorization(token, AppTokenChecker.ID, holder, null); if (authResult != null) { return authResult; } IAppToken appToken = ((IAppToken)holder.tokenContents); String checkerId = identityProviderRegistry.getCheckerId(appToken.getProviderId(), appToken.getAuthorizationType()); if (checkerId == null) { logger.warn("Token references non existing identity provider."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The token you sent references an identity provider that is not registered with Giles."); return generateResponse(msgs, HttpStatus.UNAUTHORIZED); } TokenHolder apiTokenHolder = new TokenHolder(); ResponseEntity<String> apiTokenAuthResult = checkAuthorization(providerToken, checkerId, apiTokenHolder, appToken.getAppId()); if (apiTokenAuthResult != null) { return apiTokenAuthResult; } IApiTokenContents tokenContents = (IApiTokenContents) apiTokenHolder.tokenContents; User userInToken = userManager.findUserByProviderUserId(tokenContents.getUsername(), appToken.getProviderId()); if (userInToken == null) { logger.info("The user doesn't seem to have a Giles account."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user doesn't seem to have a Giles account."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } if (userInToken.getAccountStatus() != AccountStatus.APPROVED) { logger.info("The user account you are using has not been approved. Please contact a Giles administrator."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user account you are using has not been approved. Please contact a Giles administrator."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } fillUser(userInToken, user); return joinPoint.proceed(); }  }
RestSecurityAspect { @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") public Object checkAppTokenAccess(ProceedingJoinPoint joinPoint, AppTokenCheck tokenCheck) throws Throwable { logger.debug("Checking App access token for REST endpoint."); UserTokenObject userTokenObj = extractUserTokenInfo(joinPoint, tokenCheck.value(), tokenCheck.providerToken()); User user = userTokenObj.user; String token = userTokenObj.token; String providerToken = userTokenObj.parameter; if (user == null) { throw new AspectMisconfigurationException( "User object is missing in method."); } TokenHolder holder = new TokenHolder(); ResponseEntity<String> authResult = checkAuthorization(token, AppTokenChecker.ID, holder, null); if (authResult != null) { return authResult; } IAppToken appToken = ((IAppToken)holder.tokenContents); String checkerId = identityProviderRegistry.getCheckerId(appToken.getProviderId(), appToken.getAuthorizationType()); if (checkerId == null) { logger.warn("Token references non existing identity provider."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The token you sent references an identity provider that is not registered with Giles."); return generateResponse(msgs, HttpStatus.UNAUTHORIZED); } TokenHolder apiTokenHolder = new TokenHolder(); ResponseEntity<String> apiTokenAuthResult = checkAuthorization(providerToken, checkerId, apiTokenHolder, appToken.getAppId()); if (apiTokenAuthResult != null) { return apiTokenAuthResult; } IApiTokenContents tokenContents = (IApiTokenContents) apiTokenHolder.tokenContents; User userInToken = userManager.findUserByProviderUserId(tokenContents.getUsername(), appToken.getProviderId()); if (userInToken == null) { logger.info("The user doesn't seem to have a Giles account."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user doesn't seem to have a Giles account."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } if (userInToken.getAccountStatus() != AccountStatus.APPROVED) { logger.info("The user account you are using has not been approved. Please contact a Giles administrator."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user account you are using has not been approved. Please contact a Giles administrator."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } fillUser(userInToken, user); return joinPoint.proceed(); }  @PostConstruct void init(); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkAppTokenOnlyAccess(ProceedingJoinPoint joinPoint,
            AppTokenOnlyCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkAppTokenAccess(ProceedingJoinPoint joinPoint,
            AppTokenCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkGilesTokenAccess(ProceedingJoinPoint joinPoint,
            TokenCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkDocument(ProceedingJoinPoint joinPoint, DocumentAccessCheck check); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkImageAccess(ProceedingJoinPoint joinPoint, ImageAccessCheck check ); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkFileGitHubAccess(ProceedingJoinPoint joinPoint, FileTokenAccessCheck check); }
RestSecurityAspect { @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") public Object checkAppTokenAccess(ProceedingJoinPoint joinPoint, AppTokenCheck tokenCheck) throws Throwable { logger.debug("Checking App access token for REST endpoint."); UserTokenObject userTokenObj = extractUserTokenInfo(joinPoint, tokenCheck.value(), tokenCheck.providerToken()); User user = userTokenObj.user; String token = userTokenObj.token; String providerToken = userTokenObj.parameter; if (user == null) { throw new AspectMisconfigurationException( "User object is missing in method."); } TokenHolder holder = new TokenHolder(); ResponseEntity<String> authResult = checkAuthorization(token, AppTokenChecker.ID, holder, null); if (authResult != null) { return authResult; } IAppToken appToken = ((IAppToken)holder.tokenContents); String checkerId = identityProviderRegistry.getCheckerId(appToken.getProviderId(), appToken.getAuthorizationType()); if (checkerId == null) { logger.warn("Token references non existing identity provider."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The token you sent references an identity provider that is not registered with Giles."); return generateResponse(msgs, HttpStatus.UNAUTHORIZED); } TokenHolder apiTokenHolder = new TokenHolder(); ResponseEntity<String> apiTokenAuthResult = checkAuthorization(providerToken, checkerId, apiTokenHolder, appToken.getAppId()); if (apiTokenAuthResult != null) { return apiTokenAuthResult; } IApiTokenContents tokenContents = (IApiTokenContents) apiTokenHolder.tokenContents; User userInToken = userManager.findUserByProviderUserId(tokenContents.getUsername(), appToken.getProviderId()); if (userInToken == null) { logger.info("The user doesn't seem to have a Giles account."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user doesn't seem to have a Giles account."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } if (userInToken.getAccountStatus() != AccountStatus.APPROVED) { logger.info("The user account you are using has not been approved. Please contact a Giles administrator."); Map<String, String> msgs = new HashMap<String, String>(); msgs.put("errorMsg", "The user account you are using has not been approved. Please contact a Giles administrator."); return generateResponse(msgs, HttpStatus.FORBIDDEN); } fillUser(userInToken, user); return joinPoint.proceed(); }  @PostConstruct void init(); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkAppTokenOnlyAccess(ProceedingJoinPoint joinPoint,
            AppTokenOnlyCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkAppTokenAccess(ProceedingJoinPoint joinPoint,
            AppTokenCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(tokenCheck)") Object checkGilesTokenAccess(ProceedingJoinPoint joinPoint,
            TokenCheck tokenCheck); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkDocument(ProceedingJoinPoint joinPoint, DocumentAccessCheck check); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkImageAccess(ProceedingJoinPoint joinPoint, ImageAccessCheck check ); @Around("within(edu.asu.diging.gilesecosystem.web.rest..*) && @annotation(check)") Object checkFileGitHubAccess(ProceedingJoinPoint joinPoint, FileTokenAccessCheck check);  }