import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.User;
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.common.ldap.MappingException;
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
/**
* @author <a href="jesse@codehaus.org"> jesse
- *
*/
-@Service( "userManager#ldap" )
+@Service("userManager#ldap")
public class LdapUserManager
extends AbstractUserManager
implements UserManager
{
@Inject
- @Named( value = "ldapConnectionFactory#configurable" )
+ @Named(value = "ldapConnectionFactory#configurable")
private LdapConnectionFactory connectionFactory;
@Inject
private LdapController controller;
@Inject
- @Named( value = "userMapper#ldap" )
+ @Named(value = "userMapper#ldap")
private UserMapper mapper;
@Inject
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 )
{
- addUser( user, false );
+ try
+ {
+ addUser( user, false );
+ }
+ catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }
}
private User addUser( User user, boolean checked )
+ throws LdapException
{
if ( user == null )
{
{
clearFromCache( username );
}
-
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
controller.removeUser( username, context );
}
{
log.error( "Failed to delete user: " + username, e );
}
+ catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }
finally
{
closeLdapConnection( ldapConnection );
return ldapUser;
}
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
+
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
User user = controller.getUser( username, context );
if ( user == null )
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 Collections.emptyList();
}
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
+
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
return controller.getUsersByQuery( (LdapUserQuery) query, context );
}
log.error( "Failed to map user", e );
return null;
}
+ catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }
finally
{
closeLdapConnection( ldapConnection );
*/
public List<User> getUsers()
{
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
+
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
List<User> users = new ArrayList<User>( controller.getUsers( context ) );
//We add the guest user because it isn't in LDAP
}
return users;
}
+ /*catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }*/
catch ( Exception e )
{
log.error( e.getMessage(), e );
clearFromCache( user.getUsername() );
}
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
+
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
controller.updateUser( user, context );
}
{
log.error( "Failed to update user: " + user.getUsername(), e );
}
+ catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }
finally
{
closeLdapConnection( ldapConnection );
return true;
}
- LdapConnection ldapConnection = getLdapConnection();
+ LdapConnection ldapConnection = null;
+
try
{
+ ldapConnection = getLdapConnection();
DirContext context = ldapConnection.getDirContext();
return controller.userExists( principal, context );
}
log.warn( "Failed to search for user: " + principal, e );
return false;
}
+ catch ( LdapException e )
+ {
+ throw new UserManagerException( e.getMessage(), e );
+ }
finally
{
closeLdapConnection( ldapConnection );
}
private LdapConnection getLdapConnection()
+ throws LdapException
{
try
{
catch ( LdapException 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 );
}
}