KerberosServiceAuthenticationProvider implements
		AuthenticationProvider, InitializingBean { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { KerberosServiceRequestToken auth = (KerberosServiceRequestToken) authentication; byte[] token = auth.getToken(); LOG.debug("Try to validate Kerberos Token"); KerberosTicketValidation ticketValidation = this.ticketValidator.validateTicket(token); LOG.debug("Successfully validated " + ticketValidation.username()); UserDetails userDetails = this.userDetailsService.loadUserByUsername(ticketValidation.username()); userDetailsChecker.check(userDetails); additionalAuthenticationChecks(userDetails, auth); KerberosServiceRequestToken responseAuth = new KerberosServiceRequestToken( userDetails, ticketValidation, userDetails.getAuthorities(), token); responseAuth.setDetails(authentication.getDetails()); return responseAuth; }  @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<? extends Object> auth); @Override void afterPropertiesSet(); void setUserDetailsService(UserDetailsService userDetailsService); void setTicketValidator(KerberosTicketValidator ticketValidator);  }
@Test(expected=UsernameNotFoundException.class) public void testUsernameNotFound() throws Exception { when(ticketValidator.validateTicket(TEST_TOKEN)).thenReturn(TICKET_VALIDATION); when(userDetailsService.loadUserByUsername(TEST_USER)).thenThrow(new UsernameNotFoundException("")); provider.authenticate(INPUT_TOKEN); }
@Test(expected=BadCredentialsException.class) public void testTicketValidationWrong() throws Exception { when(ticketValidator.validateTicket(TEST_TOKEN)).thenThrow(new BadCredentialsException("")); provider.authenticate(INPUT_TOKEN); }