public Authentication authenticate(Authentication authentication) throws AuthenticationException { ((TestingAuthenticationToken) authentication).setDetails(resultDetails); return authentication; }
@Test public void detailsAreSetOnAuthenticationTokenIfNotAlreadySetByProvider() throws Exception { Object details = new Object(); ProviderManager authMgr = makeProviderManager(); TestingAuthenticationToken request = createAuthenticationToken(); request.setDetails(details); Authentication result = authMgr.authenticate(request); assertThat(result.getCredentials()).isNotNull(); assertThat(result.getDetails()).isSameAs(details); }
@Test public void detailsAreNotSetOnAuthenticationTokenIfAlreadySetByProvider() throws Exception { Object requestDetails = "(Request Details)"; final Object resultDetails = "(Result Details)"; // A provider which sets the details object AuthenticationProvider provider = new AuthenticationProvider() { public Authentication authenticate(Authentication authentication) throws AuthenticationException { ((TestingAuthenticationToken) authentication).setDetails(resultDetails); return authentication; } public boolean supports(Class<?> authentication) { return true; } }; ProviderManager authMgr = new ProviderManager(Arrays.asList(provider)); TestingAuthenticationToken request = createAuthenticationToken(); request.setDetails(requestDetails); Authentication result = authMgr.authenticate(request); assertThat(result.getDetails()).isEqualTo(resultDetails); }
/** * Provide the mock user information to be used * * @param withMockOAuth2Token * @return */ private Authentication getAuthentication(WithMockOAuth2Token withMockOAuth2Token) { List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(withMockOAuth2Token.authorities()); User userPrincipal = new User(withMockOAuth2Token.userName(), withMockOAuth2Token.password(), true, true, true, true, authorities); HashMap<String, String> details = new HashMap<String, String>(); details.put("user_name", withMockOAuth2Token.userName()); details.put("email", "anilallewar@yahoo.co.in"); details.put("name", "Anil Allewar"); TestingAuthenticationToken token = new TestingAuthenticationToken(userPrincipal, null, authorities); token.setAuthenticated(true); token.setDetails(details); return token; }
@Override public Authentication getAuthentication() { final String[] authorities; if (annotation.allSpPermissions()) { authorities = getAllAuthorities(annotation.authorities(), annotation.removeFromAllPermission()); } else { authorities = annotation.authorities(); } final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken( new UserPrincipal(annotation.principal(), annotation.principal(), annotation.principal(), annotation.principal(), null, annotation.tenantId()), annotation.credentials(), authorities); testingAuthenticationToken.setDetails( new TenantAwareAuthenticationDetails(annotation.tenantId(), annotation.controller())); return testingAuthenticationToken; }
@Override public Authentication getAuthentication() { final String[] authorities; if (annotation.allSpPermissions()) { authorities = getAllAuthorities(annotation.authorities(), annotation.removeFromAllPermission()); } else { authorities = annotation.authorities(); } final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken( new UserPrincipal(annotation.principal(), annotation.principal(), annotation.principal(), annotation.principal(), null, annotation.tenantId()), annotation.credentials(), authorities); testingAuthenticationToken.setDetails( new TenantAwareAuthenticationDetails(annotation.tenantId(), annotation.controller())); return testingAuthenticationToken; }