DrishtiAuthenticationProvider implements AuthenticationProvider { public DrishtiUser getDrishtiUser(Authentication authentication) { DrishtiUser user; try { user = allDrishtiUsers.findByUsername((String) authentication.getPrincipal()); } catch (Exception e) { logger.error(format("{0}. Exception: {1}", INTERNAL_ERROR, e)); throw new BadCredentialsException(INTERNAL_ERROR); } return user; } @Autowired  DrishtiAuthenticationProvider(AllDrishtiUsers allDrishtiUsers, @Qualifier("shaPasswordEncoder") PasswordEncoder passwordEncoder); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); DrishtiUser getDrishtiUser(Authentication authentication); DrishtiUser getDrishtiUser(String username); static final String USER_NOT_FOUND; static final String USER_NOT_ACTIVATED; static final String INTERNAL_ERROR; }
@Test public void shouldFetchDrishtiUserByUsername() throws Exception { authenticationProvider.getDrishtiUser("user 1"); verify(allDrishtiUsers).findByUsername("user 1"); }