correctly inform users what happened with failing ldap
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1419566 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7181023737
commit
e0dc1a1966
|
@ -25,6 +25,7 @@ import org.apache.archiva.redback.common.ldap.UserMapper;
|
||||||
import org.apache.archiva.redback.users.AbstractUserManager;
|
import org.apache.archiva.redback.users.AbstractUserManager;
|
||||||
import org.apache.archiva.redback.users.User;
|
import org.apache.archiva.redback.users.User;
|
||||||
import org.apache.archiva.redback.users.UserManager;
|
import org.apache.archiva.redback.users.UserManager;
|
||||||
|
import org.apache.archiva.redback.users.UserManagerException;
|
||||||
import org.apache.archiva.redback.users.UserNotFoundException;
|
import org.apache.archiva.redback.users.UserNotFoundException;
|
||||||
import org.apache.archiva.redback.common.ldap.MappingException;
|
import org.apache.archiva.redback.common.ldap.MappingException;
|
||||||
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
|
||||||
|
@ -45,22 +46,21 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="jesse@codehaus.org"> jesse
|
* @author <a href="jesse@codehaus.org"> jesse
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Service( "userManager#ldap" )
|
@Service("userManager#ldap")
|
||||||
public class LdapUserManager
|
public class LdapUserManager
|
||||||
extends AbstractUserManager
|
extends AbstractUserManager
|
||||||
implements UserManager
|
implements UserManager
|
||||||
{
|
{
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "ldapConnectionFactory#configurable" )
|
@Named(value = "ldapConnectionFactory#configurable")
|
||||||
private LdapConnectionFactory connectionFactory;
|
private LdapConnectionFactory connectionFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private LdapController controller;
|
private LdapController controller;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "userMapper#ldap" )
|
@Named(value = "userMapper#ldap")
|
||||||
private UserMapper mapper;
|
private UserMapper mapper;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -75,15 +75,30 @@ public class LdapUserManager
|
||||||
|
|
||||||
public User addUser( User user )
|
public User addUser( User user )
|
||||||
{
|
{
|
||||||
return addUser( user, true );
|
try
|
||||||
|
{
|
||||||
|
return addUser( user, true );
|
||||||
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUserUnchecked( User user )
|
public void addUserUnchecked( User user )
|
||||||
{
|
{
|
||||||
addUser( user, false );
|
try
|
||||||
|
{
|
||||||
|
addUser( user, false );
|
||||||
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private User addUser( User user, boolean checked )
|
private User addUser( User user, boolean checked )
|
||||||
|
throws LdapException
|
||||||
{
|
{
|
||||||
if ( user == null )
|
if ( user == null )
|
||||||
{
|
{
|
||||||
|
@ -135,10 +150,10 @@ public class LdapUserManager
|
||||||
{
|
{
|
||||||
clearFromCache( username );
|
clearFromCache( username );
|
||||||
}
|
}
|
||||||
|
LdapConnection ldapConnection = null;
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
controller.removeUser( username, context );
|
controller.removeUser( username, context );
|
||||||
}
|
}
|
||||||
|
@ -146,6 +161,10 @@ public class LdapUserManager
|
||||||
{
|
{
|
||||||
log.error( "Failed to delete user: " + username, e );
|
log.error( "Failed to delete user: " + username, e );
|
||||||
}
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
closeLdapConnection( ldapConnection );
|
closeLdapConnection( ldapConnection );
|
||||||
|
@ -179,9 +198,11 @@ public class LdapUserManager
|
||||||
return ldapUser;
|
return ldapUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
LdapConnection ldapConnection = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
User user = controller.getUser( username, context );
|
User user = controller.getUser( username, context );
|
||||||
if ( user == null )
|
if ( user == null )
|
||||||
|
@ -201,6 +222,10 @@ public class LdapUserManager
|
||||||
log.error( "Failed to find user: {}", username, e );
|
log.error( "Failed to find user: {}", username, e );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
catch ( MappingException e )
|
catch ( MappingException e )
|
||||||
{
|
{
|
||||||
log.error( "Failed to map user: {}", username, e );
|
log.error( "Failed to map user: {}", username, e );
|
||||||
|
@ -247,9 +272,11 @@ public class LdapUserManager
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
LdapConnection ldapConnection = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
return controller.getUsersByQuery( (LdapUserQuery) query, context );
|
return controller.getUsersByQuery( (LdapUserQuery) query, context );
|
||||||
}
|
}
|
||||||
|
@ -263,6 +290,10 @@ public class LdapUserManager
|
||||||
log.error( "Failed to map user", e );
|
log.error( "Failed to map user", e );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
closeLdapConnection( ldapConnection );
|
closeLdapConnection( ldapConnection );
|
||||||
|
@ -291,9 +322,11 @@ public class LdapUserManager
|
||||||
*/
|
*/
|
||||||
public List<User> getUsers()
|
public List<User> getUsers()
|
||||||
{
|
{
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
LdapConnection ldapConnection = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
List<User> users = new ArrayList<User>( controller.getUsers( context ) );
|
List<User> users = new ArrayList<User>( controller.getUsers( context ) );
|
||||||
//We add the guest user because it isn't in LDAP
|
//We add the guest user because it isn't in LDAP
|
||||||
|
@ -311,6 +344,10 @@ public class LdapUserManager
|
||||||
}
|
}
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
/*catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}*/
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
log.error( e.getMessage(), e );
|
log.error( e.getMessage(), e );
|
||||||
|
@ -341,9 +378,11 @@ public class LdapUserManager
|
||||||
clearFromCache( user.getUsername() );
|
clearFromCache( user.getUsername() );
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
LdapConnection ldapConnection = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
controller.updateUser( user, context );
|
controller.updateUser( user, context );
|
||||||
}
|
}
|
||||||
|
@ -355,6 +394,10 @@ public class LdapUserManager
|
||||||
{
|
{
|
||||||
log.error( "Failed to update user: " + user.getUsername(), e );
|
log.error( "Failed to update user: " + user.getUsername(), e );
|
||||||
}
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
closeLdapConnection( ldapConnection );
|
closeLdapConnection( ldapConnection );
|
||||||
|
@ -378,9 +421,11 @@ public class LdapUserManager
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapConnection ldapConnection = getLdapConnection();
|
LdapConnection ldapConnection = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
ldapConnection = getLdapConnection();
|
||||||
DirContext context = ldapConnection.getDirContext();
|
DirContext context = ldapConnection.getDirContext();
|
||||||
return controller.userExists( principal, context );
|
return controller.userExists( principal, context );
|
||||||
}
|
}
|
||||||
|
@ -389,6 +434,10 @@ public class LdapUserManager
|
||||||
log.warn( "Failed to search for user: " + principal, e );
|
log.warn( "Failed to search for user: " + principal, e );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
catch ( LdapException e )
|
||||||
|
{
|
||||||
|
throw new UserManagerException( e.getMessage(), e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
closeLdapConnection( ldapConnection );
|
closeLdapConnection( ldapConnection );
|
||||||
|
@ -396,6 +445,7 @@ public class LdapUserManager
|
||||||
}
|
}
|
||||||
|
|
||||||
private LdapConnection getLdapConnection()
|
private LdapConnection getLdapConnection()
|
||||||
|
throws LdapException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -404,7 +454,7 @@ public class LdapUserManager
|
||||||
catch ( LdapException e )
|
catch ( LdapException e )
|
||||||
{
|
{
|
||||||
log.warn( "failed to get a ldap connection " + e.getMessage(), e );
|
log.warn( "failed to get a ldap connection " + e.getMessage(), e );
|
||||||
throw new RuntimeException( "failed to get a ldap connection " + e.getMessage(), e );
|
throw new LdapException( "failed to get a ldap connection " + e.getMessage(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue