@Test public void testAuthenticate() { final JaasAuthenticationProvider provider = context.mock(JaasAuthenticationProvider.class); final JaasAuthenticationToken token = context.mock(JaasAuthenticationToken.class); final UsernamePasswordAuthenticationToken auth = context.mock(UsernamePasswordAuthenticationToken.class); final UserDetailsService uds = context.mock(UserDetailsService.class); final UserDetails ud = context.mock(UserDetails.class); context.checking(new Expectations() { { oneOf(provider).authenticate(auth); will(returnValue(token)); exactly(2).of(token).getName(); will(returnValue("homers")); oneOf(uds).loadUserByUsername("homers"); will(returnValue(ud)); oneOf(ud).isAccountNonLocked(); will(returnValue(true)); oneOf(ud).isEnabled(); will(returnValue(true)); oneOf(ud).isAccountNonExpired(); will(returnValue(true)); oneOf(ud).isCredentialsNonExpired(); will(returnValue(true)); oneOf(token).getCredentials(); will(returnValue(null)); oneOf(token).getAuthorities(); will(returnValue(new GrantedAuthority[0])); } }); JaasAuthenticationProviderWrapper sut = new JaasAuthenticationProviderWrapper(provider, uds); assertEquals("Authentication.getPrincipal() doesn't return expected userDetailsObject ", ud, sut.authenticate(auth).getPrincipal()); context.assertIsSatisfied(); }
public Authentication authenticate(final Authentication authentication) { Authentication parentAuthResult = authProvider.authenticate(authentication); if (parentAuthResult == null) { log.debug("Parent authentication provider returned null Authentication object."); return null; } log.debug("loading userDetails for user: " + parentAuthResult.getName()); UserDetails details = userDetailsService .loadUserByUsername((String) parentAuthResult.getName()); detailsChecker.check(details); return new UsernamePasswordAuthenticationToken(details, parentAuthResult.getCredentials(), parentAuthResult.getAuthorities()); }
JaasAuthenticationProviderWrapper implements
        AuthenticationProvider { public Authentication authenticate(final Authentication authentication) { Authentication parentAuthResult = authProvider.authenticate(authentication); if (parentAuthResult == null) { log.debug("Parent authentication provider returned null Authentication object."); return null; } log.debug("loading userDetails for user: " + parentAuthResult.getName()); UserDetails details = userDetailsService .loadUserByUsername((String) parentAuthResult.getName()); detailsChecker.check(details); return new UsernamePasswordAuthenticationToken(details, parentAuthResult.getCredentials(), parentAuthResult.getAuthorities()); } }
JaasAuthenticationProviderWrapper implements
        AuthenticationProvider { public Authentication authenticate(final Authentication authentication) { Authentication parentAuthResult = authProvider.authenticate(authentication); if (parentAuthResult == null) { log.debug("Parent authentication provider returned null Authentication object."); return null; } log.debug("loading userDetails for user: " + parentAuthResult.getName()); UserDetails details = userDetailsService .loadUserByUsername((String) parentAuthResult.getName()); detailsChecker.check(details); return new UsernamePasswordAuthenticationToken(details, parentAuthResult.getCredentials(), parentAuthResult.getAuthorities()); } JaasAuthenticationProviderWrapper(final JaasAuthenticationProvider inAuthProvider,
            final UserDetailsService inUserDetailsService); }
JaasAuthenticationProviderWrapper implements
        AuthenticationProvider { public Authentication authenticate(final Authentication authentication) { Authentication parentAuthResult = authProvider.authenticate(authentication); if (parentAuthResult == null) { log.debug("Parent authentication provider returned null Authentication object."); return null; } log.debug("loading userDetails for user: " + parentAuthResult.getName()); UserDetails details = userDetailsService .loadUserByUsername((String) parentAuthResult.getName()); detailsChecker.check(details); return new UsernamePasswordAuthenticationToken(details, parentAuthResult.getCredentials(), parentAuthResult.getAuthorities()); } JaasAuthenticationProviderWrapper(final JaasAuthenticationProvider inAuthProvider,
            final UserDetailsService inUserDetailsService); Authentication authenticate(final Authentication authentication); @SuppressWarnings("unchecked") boolean supports(final Class authentication); }
JaasAuthenticationProviderWrapper implements
        AuthenticationProvider { public Authentication authenticate(final Authentication authentication) { Authentication parentAuthResult = authProvider.authenticate(authentication); if (parentAuthResult == null) { log.debug("Parent authentication provider returned null Authentication object."); return null; } log.debug("loading userDetails for user: " + parentAuthResult.getName()); UserDetails details = userDetailsService .loadUserByUsername((String) parentAuthResult.getName()); detailsChecker.check(details); return new UsernamePasswordAuthenticationToken(details, parentAuthResult.getCredentials(), parentAuthResult.getAuthorities()); } JaasAuthenticationProviderWrapper(final JaasAuthenticationProvider inAuthProvider,
            final UserDetailsService inUserDetailsService); Authentication authenticate(final Authentication authentication); @SuppressWarnings("unchecked") boolean supports(final Class authentication);  }