KerberosAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication; JaasSubjectHolder subjectHolder = kerberosClient.login(auth.getName(), auth.getCredentials().toString()); UserDetails userDetails = this.userDetailsService.loadUserByUsername(subjectHolder.getUsername()); KerberosUsernamePasswordAuthenticationToken output = new KerberosUsernamePasswordAuthenticationToken( userDetails, auth.getCredentials(), userDetails.getAuthorities(), subjectHolder); output.setDetails(authentication.getDetails()); return output; }  @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<? extends Object> authentication); void setKerberosClient(KerberosClient kerberosClient); void setUserDetailsService(UserDetailsService detailsService);  }
@Test public void testLoginOk() throws Exception { when(userDetailsService.loadUserByUsername(TEST_USER)).thenReturn(USER_DETAILS); when(kerberosClient.login(TEST_USER, TEST_PASSWORD)).thenReturn(JAAS_SUBJECT_HOLDER); Authentication authenticate = provider.authenticate(INPUT_TOKEN); verify(kerberosClient).login(TEST_USER, TEST_PASSWORD); assertNotNull(authenticate); assertEquals(TEST_USER, authenticate.getName()); assertEquals(USER_DETAILS, authenticate.getPrincipal()); assertEquals(TEST_PASSWORD, authenticate.getCredentials()); assertEquals(AUTHORITY_LIST, authenticate.getAuthorities()); }