/**
* @author <a href="jesse@codehaus.org"> jesse
- *
*/
@Service
public class DefaultLdapController
private Logger log = LoggerFactory.getLogger( getClass() );
@Inject
- @Named(value = "userMapper#ldap")
+ @Named( value = "userMapper#ldap" )
private UserMapper mapper;
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#removeUser(java.lang.Object, javax.naming.directory.DirContext)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#removeUser(java.lang.Object, javax.naming.directory.DirContext)
+ */
public void removeUser( Object principal, DirContext context )
throws LdapControllerException
{
}
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#updateUser(org.apache.archiva.redback.users.User, javax.naming.directory.DirContext)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#updateUser(org.apache.archiva.redback.users.User, javax.naming.directory.DirContext)
+ */
public void updateUser( User user, DirContext context )
throws LdapControllerException, MappingException
{
}
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#userExists(java.lang.Object, javax.naming.directory.DirContext)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#userExists(java.lang.Object, javax.naming.directory.DirContext)
+ */
public boolean userExists( Object key, DirContext context )
throws LdapControllerException
{
finally
{
if ( results != null )
+ {
try
{
results.close();
{
log.warn( "Error closing search results", e );
}
+ }
}
}
return searchUsers( context, returnAttributes, null );
}
- protected NamingEnumeration<SearchResult> searchUsers( DirContext context, String[] returnAttributes, LdapUserQuery query )
+ protected NamingEnumeration<SearchResult> searchUsers( DirContext context, String[] returnAttributes,
+ LdapUserQuery query )
throws NamingException
{
if ( query == null )
ctls.setReturningAttributes( mapper.getReturningAttributes() );
ctls.setCountLimit( ( (LdapUserMapper) mapper ).getMaxResultCount() );
- String finalFilter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" +
- ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + query.getLdapFilter(mapper) + ")";
+ String finalFilter = new StringBuilder( "(&(objectClass=" + mapper.getUserObjectClass() + ")" ).append(
+ ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) ).append(
+ query.getLdapFilter( mapper ) + ")" ).toString();
- log.debug( "Searching for users with filter: '{}'" + " from base dn: {}",finalFilter, mapper.getUserBaseDn() );
+ log.debug( "Searching for users with filter: '{}' from base dn: {}", finalFilter, mapper.getUserBaseDn() );
return context.search( mapper.getUserBaseDn(), finalFilter, ctls );
}
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUsers(javax.naming.directory.DirContext)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUsers(javax.naming.directory.DirContext)
+ */
public Collection<User> getUsers( DirContext context )
throws LdapControllerException, MappingException
{
finally
{
if ( results != null )
+ {
try
{
results.close();
{
log.warn( "failed to close search results", e );
}
+ }
}
}
-
- /**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUsersByQuery(org.apache.archiva.redback.users.ldap.LdapUserQuery, javax.naming.directory.DirContext)
- */
- public List<User> getUsersByQuery( LdapUserQuery query, DirContext context )
- throws LdapControllerException, MappingException
- {
- NamingEnumeration<SearchResult> results = null;
- try
- {
- results = searchUsers( context, null, query );
- List<User> users = new LinkedList<User>();
-
- while ( results.hasMoreElements() )
- {
- SearchResult result = results.nextElement();
-
- users.add( mapper.getUser( result.getAttributes() ) );
- }
-
- return users;
- }
- catch ( NamingException e )
- {
- String message = "Failed to retrieve ldap information for users.";
-
- throw new LdapControllerException( message, e );
- }
- finally
+
+ /**
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUsersByQuery(org.apache.archiva.redback.users.ldap.LdapUserQuery, javax.naming.directory.DirContext)
+ */
+ public List<User> getUsersByQuery( LdapUserQuery query, DirContext context )
+ throws LdapControllerException, MappingException
+ {
+ NamingEnumeration<SearchResult> results = null;
+ try
+ {
+ results = searchUsers( context, null, query );
+ List<User> users = new LinkedList<User>();
+
+ while ( results.hasMoreElements() )
+ {
+ SearchResult result = results.nextElement();
+
+ users.add( mapper.getUser( result.getAttributes() ) );
+ }
+
+ return users;
+ }
+ catch ( NamingException e )
+ {
+ String message = "Failed to retrieve ldap information for users.";
+
+ throw new LdapControllerException( message, e );
+ }
+ finally
{
if ( results != null )
+ {
try
{
results.close();
{
log.warn( "failed to close search results", e );
}
+ }
}
- }
+ }
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#createUser(org.apache.archiva.redback.users.User, javax.naming.directory.DirContext, boolean)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#createUser(org.apache.archiva.redback.users.User, javax.naming.directory.DirContext, boolean)
+ */
public void createUser( User user, DirContext context, boolean encodePasswordIfChanged )
throws LdapControllerException, MappingException
{
}
/**
- * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUser(java.lang.Object, javax.naming.directory.DirContext)
- */
+ * @see org.apache.archiva.redback.users.ldap.ctl.LdapController#getUser(java.lang.Object, javax.naming.directory.DirContext)
+ */
public LdapUser getUser( Object key, DirContext context )
throws LdapControllerException, MappingException
{
finally
{
if ( result != null )
+ {
try
{
result.close();
{
log.warn( "failed to close search results", e );
}
+ }
}
}