use getUsername rather than getPrincipal

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1433465 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-01-15 15:43:29 +00:00
parent 17f4210d6c
commit 30bc1f3ad8
8 changed files with 34 additions and 36 deletions

View File

@ -30,7 +30,7 @@ package org.apache.archiva.redback.authentication;
*/
public interface AuthenticationDataSource
{
String getPrincipal();
String getUsername();
boolean isEnforcePasswordChange();
}

View File

@ -56,7 +56,7 @@ public class PasswordBasedAuthenticationDataSource
return password;
}
public String getPrincipal()
public String getUsername()
{
return principal;
}

View File

@ -50,7 +50,7 @@ public class TokenBasedAuthenticationDataSource
{
}
public String getPrincipal()
public String getUsername()
{
return principal;
}

View File

@ -87,7 +87,7 @@ public class LdapBindAuthenticator
!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();
@ -99,7 +99,7 @@ public class LdapBindAuthenticator
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() );
@ -110,18 +110,18 @@ public class LdapBindAuthenticator
{
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() )
{
@ -129,14 +129,14 @@ public class LdapBindAuthenticator
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 );
}
}
@ -144,17 +144,17 @@ public class LdapBindAuthenticator
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
{

View File

@ -51,7 +51,7 @@ public class MemoryAuthenticator
{
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
login = source.getPrincipal();
login = source.getUsername();
password = source.getPassword();
if ( source.getPassword().equals( password ) )

View File

@ -44,7 +44,7 @@ public class OpenAuthenticator
throws AccountLockedException, AuthenticationException
{
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
return new AuthenticationResult( true, source.getPrincipal(), null );
return new AuthenticationResult( true, source.getUsername(), null );
}
public String getId()

View File

@ -43,9 +43,7 @@ import org.springframework.stereotype.Service;
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.
@ -92,12 +90,12 @@ public class UserManagerAuthenticator
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() )
@ -111,7 +109,7 @@ public class UserManagerAuthenticator
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
{
@ -132,14 +130,14 @@ public class UserManagerAuthenticator
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
{
@ -150,24 +148,24 @@ public class UserManagerAuthenticator
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() ) );
}

View File

@ -77,11 +77,11 @@ public class KeyStoreAuthenticator
// 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() )
@ -89,11 +89,11 @@ public class KeyStoreAuthenticator
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" ) );
}
}
@ -107,12 +107,12 @@ public class KeyStoreAuthenticator
}
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 );
}
}