{
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 user not found in DB, try to create from LDAP
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 user still not found, give up.
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);
}