*/
public interface AuthenticationDataSource
{
- String getPrincipal();
+ String getUsername();
boolean isEnforcePasswordChange();
}
return password;
}
- public String getPrincipal()
+ public String getUsername()
{
return principal;
}
{
}
- public String getPrincipal()
+ public String getUsername()
{
return principal;
}
!config.getBoolean( UserConfigurationKeys.LDAP_BIND_AUTHENTICATOR_ALLOW_EMPTY_PASSWORDS, false )
&& StringUtils.isEmpty( source.getPassword() ) ) )
{
- return new AuthenticationResult( false, source.getPrincipal(), null );
+ return new AuthenticationResult( false, source.getUsername(), null );
}
SearchControls ctls = new SearchControls();
String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" + ( mapper.getUserFilter() != null
? mapper.getUserFilter()
- : "" ) + "(" + mapper.getUserIdAttribute() + "=" + source.getPrincipal() + "))";
+ : "" ) + "(" + mapper.getUserIdAttribute() + "=" + source.getUsername() + "))";
log.debug( "Searching for users with filter: '{}' from base dn: {}", filter, mapper.getUserBaseDn() );
{
ldapConnection = getLdapConnection();
// check the cache for user's userDn in the ldap server
- String userDn = ldapCacheService.getLdapUserDn( source.getPrincipal() );
+ String userDn = ldapCacheService.getLdapUserDn( source.getUsername() );
if ( userDn == null )
{
log.debug( "userDn for user {} not found in cache. Retrieving from ldap server..",
- source.getPrincipal() );
+ source.getUsername() );
DirContext context = ldapConnection.getDirContext();
results = context.search( mapper.getUserBaseDn(), filter, ctls );
- log.debug( "Found user '{}': {}", source.getPrincipal(), results.hasMoreElements() );
+ log.debug( "Found user '{}': {}", source.getUsername(), results.hasMoreElements() );
if ( results.hasMoreElements() )
{
userDn = result.getNameInNamespace();
- log.debug( "Adding userDn {} for user {} to the cache..", userDn, source.getPrincipal() );
+ log.debug( "Adding userDn {} for user {} to the cache..", userDn, source.getUsername() );
// REDBACK-289/MRM-1488 cache the ldap user's userDn to lessen calls to ldap server
- ldapCacheService.addLdapUserDn( source.getPrincipal(), userDn );
+ ldapCacheService.addLdapUserDn( source.getUsername(), userDn );
}
else
{
- return new AuthenticationResult( false, source.getPrincipal(), null );
+ return new AuthenticationResult( false, source.getUsername(), null );
}
}
authLdapConnection = connectionFactory.getConnection( userDn, source.getPassword() );
- log.info( "user '{}' authenticated", source.getPrincipal() );
+ log.info( "user '{}' authenticated", source.getUsername() );
- return new AuthenticationResult( true, source.getPrincipal(), null );
+ return new AuthenticationResult( true, source.getUsername(), null );
}
catch ( LdapException e )
{
- return new AuthenticationResult( false, source.getPrincipal(), e );
+ return new AuthenticationResult( false, source.getUsername(), e );
}
catch ( NamingException e )
{
- return new AuthenticationResult( false, source.getPrincipal(), e );
+ return new AuthenticationResult( false, source.getUsername(), e );
}
finally
{
{
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
- login = source.getPrincipal();
+ login = source.getUsername();
password = source.getPassword();
if ( source.getPassword().equals( password ) )
throws AccountLockedException, AuthenticationException
{
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
- return new AuthenticationResult( true, source.getPrincipal(), null );
+ return new AuthenticationResult( true, source.getUsername(), null );
}
public String getId()
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* {@link Authenticator} implementation that uses a wrapped {@link UserManager} to authenticate.
try
{
log.debug( "Authenticate: {}", source );
- User user = userManager.findUser( source.getPrincipal() );
+ User user = userManager.findUser( source.getUsername() );
username = user.getUsername();
if ( user.isLocked() )
{
- throw new AccountLockedException( "Account " + source.getPrincipal() + " is locked.", user );
+ throw new AccountLockedException( "Account " + source.getUsername() + " is locked.", user );
}
if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() )
boolean isPasswordValid = encoder.isPasswordValid( user.getEncodedPassword(), source.getPassword() );
if ( isPasswordValid )
{
- log.debug( "User {} provided a valid password", source.getPrincipal() );
+ log.debug( "User {} provided a valid password", source.getUsername() );
try
{
userManager.updateUser( user );
}
- return new AuthenticationResult( true, source.getPrincipal(), null );
+ return new AuthenticationResult( true, source.getUsername(), null );
}
else
{
- log.warn( "Password is Invalid for user {}.", source.getPrincipal() );
+ log.warn( "Password is Invalid for user {}.", source.getUsername() );
authenticationFailureCauses.add(
new AuthenticationFailureCause( AuthenticationConstants.AUTHN_NO_SUCH_USER,
- "Password is Invalid for user " + source.getPrincipal() + "." ) );
+ "Password is Invalid for user " + source.getUsername() + "." ) );
try
{
userManager.updateUser( user );
}
- return new AuthenticationResult( false, source.getPrincipal(), null, authenticationFailureCauses );
+ return new AuthenticationResult( false, source.getUsername(), null, authenticationFailureCauses );
}
}
catch ( UserNotFoundException e )
{
- log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
+ log.warn( "Login for user {} failed. user not found.", source.getUsername() );
resultException = e;
authenticationFailureCauses.add( new AuthenticationFailureCause( AuthenticationConstants.AUTHN_NO_SUCH_USER,
- "Login for user " + source.getPrincipal()
+ "Login for user " + source.getUsername()
+ " failed. user not found." ) );
}
catch ( UserManagerException e )
{
- log.warn( "Login for user {} failed, message: {}", source.getPrincipal(), e.getMessage() );
+ log.warn( "Login for user {} failed, message: {}", source.getUsername(), e.getMessage() );
resultException = e;
authenticationFailureCauses.add(
new AuthenticationFailureCause( AuthenticationConstants.AUTHN_RUNTIME_EXCEPTION,
- "Login for user " + source.getPrincipal() + " failed, message: "
+ "Login for user " + source.getUsername() + " failed, message: "
+ e.getMessage() ) );
}
// if we find a key (exception was probably thrown if not) then we should be authentic
if ( authKey != null )
{
- User user = userManager.findUser( dataSource.getPrincipal() );
+ User user = userManager.findUser( dataSource.getUsername() );
if ( user.isLocked() )
{
- throw new AccountLockedException( "Account " + source.getPrincipal() + " is locked.", user );
+ throw new AccountLockedException( "Account " + source.getUsername() + " is locked.", user );
}
if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() )
throw new MustChangePasswordException( "Password expired.", user );
}
- return new AuthenticationResult( true, dataSource.getPrincipal(), null );
+ return new AuthenticationResult( true, dataSource.getUsername(), null );
}
else
{
- return new AuthenticationResult( false, dataSource.getPrincipal(),
+ return new AuthenticationResult( false, dataSource.getUsername(),
new AuthenticationException( "unable to find key" ) );
}
}
}
catch ( UserNotFoundException e )
{
- log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
+ log.warn( "Login for user {} failed. user not found.", source.getUsername() );
return new AuthenticationResult( false, null, e );
}
catch ( UserManagerException e )
{
- log.warn( "Login fail for user {} failed. message: {}", source.getPrincipal(), e.getMessage() );
+ log.warn( "Login fail for user {} failed. message: {}", source.getUsername(), e.getMessage() );
return new AuthenticationResult( false, null, e );
}
}