@Test public void testLoadUserByUsername() { final PersonMapper personMapper = context.mock(PersonMapper.class); final PersistentLoginRepository loginRepo = context.mock(PersistentLoginRepository.class); context.checking(new Expectations() { { oneOf(personMapper).findByAccountId(with("username")); oneOf(loginRepo).getPersistentLogin(with("username")); } }); UserDetailsServiceImpl sut = new UserDetailsServiceImpl(personMapper, loginRepo, null, serviceActionController, createUserfromLdapAction); sut.setAuthenticationType(AuthenticationType.FORM); ExtendedUserDetails result = (ExtendedUserDetails) sut.loadUserByUsername("username"); assertNotNull("Should return UserDetailsObject", result); assertEquals(AuthenticationType.FORM, result.getAuthenticationType()); context.assertIsSatisfied(); }
@Override public UserDetails loadUserByUsername(final String username) { if (bypassUserName.equalsIgnoreCase(username)) { String errorMessage = "Configured to skip loading user details for " + username; log.debug(errorMessage); throw new UsernameNotFoundException(errorMessage); } Person person = null; PersistentLogin login = null; List<GrantedAuthority> authorities = null; try { person = personMapper.findByAccountId(username); login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username); authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0) : authorityProvider .loadAuthoritiesByUsername(username); if (person == null) { person = (Person) serviceActionController.execute(new ServiceActionContext(username, null), createUserfromLdapAction); } } catch (Exception e) { String errorMessage = "Error loading user details for: " + username; log.error(errorMessage + " " + e.getMessage()); throw new DataRetrievalFailureException(errorMessage, e); } if (person == null) { String errorMessage = "User not found: " + username; log.info(errorMessage); throw new UsernameNotFoundException(errorMessage); } return new ExtendedUserDetailsImpl(person, login, authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType); }
UserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(final String username) { if (bypassUserName.equalsIgnoreCase(username)) { String errorMessage = "Configured to skip loading user details for " + username; log.debug(errorMessage); throw new UsernameNotFoundException(errorMessage); } Person person = null; PersistentLogin login = null; List<GrantedAuthority> authorities = null; try { person = personMapper.findByAccountId(username); login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username); authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0) : authorityProvider .loadAuthoritiesByUsername(username); if (person == null) { person = (Person) serviceActionController.execute(new ServiceActionContext(username, null), createUserfromLdapAction); } } catch (Exception e) { String errorMessage = "Error loading user details for: " + username; log.error(errorMessage + " " + e.getMessage()); throw new DataRetrievalFailureException(errorMessage, e); } if (person == null) { String errorMessage = "User not found: " + username; log.info(errorMessage); throw new UsernameNotFoundException(errorMessage); } return new ExtendedUserDetailsImpl(person, login, authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType); } }
UserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(final String username) { if (bypassUserName.equalsIgnoreCase(username)) { String errorMessage = "Configured to skip loading user details for " + username; log.debug(errorMessage); throw new UsernameNotFoundException(errorMessage); } Person person = null; PersistentLogin login = null; List<GrantedAuthority> authorities = null; try { person = personMapper.findByAccountId(username); login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username); authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0) : authorityProvider .loadAuthoritiesByUsername(username); if (person == null) { person = (Person) serviceActionController.execute(new ServiceActionContext(username, null), createUserfromLdapAction); } } catch (Exception e) { String errorMessage = "Error loading user details for: " + username; log.error(errorMessage + " " + e.getMessage()); throw new DataRetrievalFailureException(errorMessage, e); } if (person == null) { String errorMessage = "User not found: " + username; log.info(errorMessage); throw new UsernameNotFoundException(errorMessage); } return new ExtendedUserDetailsImpl(person, login, authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType); } UserDetailsServiceImpl(final PersonMapper inPersonMapper,
            final PersistentLoginRepository inPersistentLoginRepository, final AuthorityProvider inAuthorityProvider,
            final ActionController inServiceActionController, final TaskHandlerServiceAction inCreateUserfromLdapAction); }
UserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(final String username) { if (bypassUserName.equalsIgnoreCase(username)) { String errorMessage = "Configured to skip loading user details for " + username; log.debug(errorMessage); throw new UsernameNotFoundException(errorMessage); } Person person = null; PersistentLogin login = null; List<GrantedAuthority> authorities = null; try { person = personMapper.findByAccountId(username); login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username); authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0) : authorityProvider .loadAuthoritiesByUsername(username); if (person == null) { person = (Person) serviceActionController.execute(new ServiceActionContext(username, null), createUserfromLdapAction); } } catch (Exception e) { String errorMessage = "Error loading user details for: " + username; log.error(errorMessage + " " + e.getMessage()); throw new DataRetrievalFailureException(errorMessage, e); } if (person == null) { String errorMessage = "User not found: " + username; log.info(errorMessage); throw new UsernameNotFoundException(errorMessage); } return new ExtendedUserDetailsImpl(person, login, authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType); } UserDetailsServiceImpl(final PersonMapper inPersonMapper,
            final PersistentLoginRepository inPersistentLoginRepository, final AuthorityProvider inAuthorityProvider,
            final ActionController inServiceActionController, final TaskHandlerServiceAction inCreateUserfromLdapAction); @Override UserDetails loadUserByUsername(final String username); void setAuthenticationType(final AuthenticationType inAuthenticationType); }
UserDetailsServiceImpl implements UserDetailsService { @Override public UserDetails loadUserByUsername(final String username) { if (bypassUserName.equalsIgnoreCase(username)) { String errorMessage = "Configured to skip loading user details for " + username; log.debug(errorMessage); throw new UsernameNotFoundException(errorMessage); } Person person = null; PersistentLogin login = null; List<GrantedAuthority> authorities = null; try { person = personMapper.findByAccountId(username); login = (loginRepository == null) ? null : loginRepository.getPersistentLogin(username); authorities = (authorityProvider == null) ? new ArrayList<GrantedAuthority>(0) : authorityProvider .loadAuthoritiesByUsername(username); if (person == null) { person = (Person) serviceActionController.execute(new ServiceActionContext(username, null), createUserfromLdapAction); } } catch (Exception e) { String errorMessage = "Error loading user details for: " + username; log.error(errorMessage + " " + e.getMessage()); throw new DataRetrievalFailureException(errorMessage, e); } if (person == null) { String errorMessage = "User not found: " + username; log.info(errorMessage); throw new UsernameNotFoundException(errorMessage); } return new ExtendedUserDetailsImpl(person, login, authorities.toArray(new GrantedAuthority[authorities.size()]), authenticationType); } UserDetailsServiceImpl(final PersonMapper inPersonMapper,
            final PersistentLoginRepository inPersistentLoginRepository, final AuthorityProvider inAuthorityProvider,
            final ActionController inServiceActionController, final TaskHandlerServiceAction inCreateUserfromLdapAction); @Override UserDetails loadUserByUsername(final String username); void setAuthenticationType(final AuthenticationType inAuthenticationType);  }