in redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java [214:270]
public User findUser( String username, boolean useCache )
throws UserNotFoundException, UserManagerException
{
if ( username == null )
{
throw new UserNotFoundException( "Unable to find user based on null username." );
}
if ( useCache )
{
// REDBACK-289/MRM-1488
// look for the user in the cache first
LdapUser ldapUser = ldapCacheService.getUser( username );
if ( ldapUser != null )
{
log.debug( "User {} found in cache.", username );
return ldapUser;
}
}
LdapConnection ldapConnection = null;
try
{
ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
User user = controller.getUser( username, context );
if ( user == null )
{
throw new UserNotFoundException( "user with name " + username + " not found " );
}
// REDBACK-289/MRM-1488
log.debug( "Adding user {} to cache..", username );
ldapCacheService.addUser( (LdapUser) user );
return user;
}
catch ( LdapControllerException e )
{
log.error( "Failed to find user: {}", username, e );
return null;
}
catch ( LdapException e )
{
throw new UserManagerException( e.getMessage(), e );
}
catch ( MappingException e )
{
log.error( "Failed to map user: {}", username, e );
return null;
}
finally
{
closeLdapConnection( ldapConnection );
}
}