directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lucasthei...@apache.org
Subject svn commit: r1595515 - in /directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template: LdapConnectionOperations.java LdapConnectionTemplate.java
Date Sat, 17 May 2014 17:10:11 GMT
Author: lucastheisen
Date: Sat May 17 17:10:11 2014
New Revision: 1595515

URL: http://svn.apache.org/r1595515
Log:
added additional overload operations to LdapConnectionTemplate

Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java?rev=1595515&r1=1595514&r2=1595515&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionOperations.java
Sat May 17 17:10:11 2014
@@ -32,6 +32,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.api.ldap.model.message.ResultResponse;
 import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.ldap.client.template.exception.LdapRequestUnsuccessfulException;
 import org.apache.directory.ldap.client.template.exception.PasswordException;
@@ -80,6 +81,63 @@ public interface LdapConnectionOperation
 
 
     /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(String, String, SearchScope, EntryMapper)}
+     */
+    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope,
char[] password ) throws PasswordException;
+
+
+    /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(Dn, String, SearchScope, EntryMapper)}
+     */
+    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[]
password ) throws PasswordException;
+    
+    
+    /**
+     * Attempts to authenticate the supplied credentials against the first 
+     * entry found matching the search criteria.  If authentication fails, 
+     * a PasswordException is thrown.  If successful, the response is 
+     * checked for warnings, and if present, a PasswordWarning is returned.
+     * Otherwise, null is returned.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param password
+     * @return
+     * @throws PasswordException
+     * @see {@link #authenticate(Dn, char[])}
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public PasswordWarning authenticate( SearchRequest searchRequest, char[] password ) throws
PasswordException;
+
+
+    /**
      * Attempts to authenticate the supplied credentials.  If authentication
      * fails, a PasswordException is thrown.  If successful, the response is 
      * checked for warnings, and if present, a PasswordWarning is returned.
@@ -156,6 +214,33 @@ public interface LdapConnectionOperation
 
 
     /**
+     * Modifies the password for <code>userDn</code> to
+     * <code>newPassword</code> using the admin account.
+     *
+     * @param userDn
+     * @param newPassword
+     * @throws PasswordException
+     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
+     */
+    public void modifyPassword( Dn userDn, char[] newPassword ) 
+        throws PasswordException;
+
+
+    /**
+     * Modifies the password for <code>userDn</code> from 
+     * <code>oldPassword</code> to <code>newPassword</code>.
+     *
+     * @param userDn
+     * @param oldPassword
+     * @param newPassword
+     * @throws PasswordException
+     * @see {@link #modifyPassword(Dn, char[], char[], boolean)}
+     */
+    public void modifyPassword( Dn userDn, char[] oldPassword,
+        char[] newPassword ) throws PasswordException;
+
+
+    /**
      * Modifies the password for <code>userDn</code> from 
      * <code>oldPassword</code> to <code>newPassword</code>, optionally
using
      * an admin account.  If <code>asAdmin</code> is true, then the operation
@@ -206,27 +291,74 @@ public interface LdapConnectionOperation
      * @throws LdapRequestUnsuccessfulException If the response is not
      * {@link ResultCodeEnum#SUCCESS}
      */
-    public <T extends ResultResponse> T responseOrException( T response );
+    public abstract <T extends ResultResponse> T responseOrException( T response );
 
 
     /**
-     * Searches for the first entry matching the supplied 
-     * <code>searchRequest</code>, feeding the result into the 
-     * <code>entryMapper</code>. This is basically the same as 
-     * {@link #search(SearchRequest, EntryMapper)}, but is optimized by
-     * modifying the <code>searchRequest</code> to set its size limit to 1.
-     * The <code>searchRequest</code> is returned to its original size limit
-     * before this method returns (or throws an exception).
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
      *
-     * @param searchRequest The search request
-     * @param entryMapper The mapper
-     * @return The mapped entry
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
      */
-    public abstract <T> T searchFirst( SearchRequest searchRequest,
+    public abstract <T> List<T> search( String baseDn, String filter, SearchScope
scope,
         EntryMapper<T> entryMapper );
 
 
     /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope
scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested

+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( String baseDn, String filter, SearchScope
scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the entries matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested

+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #search(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> List<T> search( Dn baseDn, String filter, SearchScope
scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
      * Searches for the entries matching the supplied 
      * <code>searchRequest</code>, feeding the result into the 
      * <code>entryMapper</code>.
@@ -237,5 +369,86 @@ public interface LdapConnectionOperation
      */
     public abstract <T> List<T> search( SearchRequest searchRequest,
         EntryMapper<T> entryMapper );
+    
+    
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested

+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+
+
+    /**
+     * Searches for the first entry matching the supplied criteria, feeding the 
+     * result into the <code>entryMapper</code>, querying only the requested

+     * attributes.
+     *
+     * @param baseDn
+     * @param filter
+     * @param scope
+     * @param attributes
+     * @param entryMapper
+     * @return The mapped entries
+     * @see {@link #searchFirst(SearchRequest, EntryMapper)}
+     */
+    public abstract <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper );
+    
+
+    /**
+     * Searches for the first entry matching the supplied 
+     * <code>searchRequest</code>, feeding the result into the 
+     * <code>entryMapper</code>. This is basically the same as 
+     * {@link #search(SearchRequest, EntryMapper)}, but is optimized by
+     * modifying the <code>searchRequest</code> to set its size limit to 1.
+     * The <code>searchRequest</code> is returned to its original size limit
+     * before this method returns (or throws an exception).
+     *
+     * @param searchRequest The search request
+     * @param entryMapper The mapper
+     * @return The mapped entry
+     */
+    public abstract <T> T searchFirst( SearchRequest searchRequest,
+        EntryMapper<T> entryMapper );
 
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java?rev=1595515&r1=1595514&r2=1595515&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/template/LdapConnectionTemplate.java
Sat May 17 17:10:11 2014
@@ -64,6 +64,13 @@ import org.slf4j.LoggerFactory;
 public class LdapConnectionTemplate implements LdapConnectionOperations, ModelFactory
 {
     private static Logger logger = LoggerFactory.getLogger( LdapConnectionTemplate.class
);
+    private static final EntryMapper<Dn> dnEntryMapper = new EntryMapper<Dn>()
{
+        @Override
+        public Dn map( Entry entry ) throws LdapException
+        {
+            return entry.getDn();
+        }
+    };
 
     private LdapConnectionPool connectionPool;
     private final PasswordPolicyDecorator passwordPolicyRequestControl;
@@ -139,6 +146,32 @@ public class LdapConnectionTemplate impl
 
 
     @Override
+    public PasswordWarning authenticate( String baseDn, String filter, SearchScope scope,
char[] password ) throws PasswordException
+    {
+        return authenticate( newSearchRequest( baseDn, filter, scope ), password );
+    }
+
+
+    @Override
+    public PasswordWarning authenticate( Dn baseDn, String filter, SearchScope scope, char[]
password ) throws PasswordException
+    {
+        return authenticate( newSearchRequest( baseDn, filter, scope ), password );
+    }
+    
+    
+    @Override
+    public PasswordWarning authenticate( SearchRequest searchRequest, char[] password ) throws
PasswordException
+    {
+        Dn userDn = searchFirst( searchRequest, dnEntryMapper );
+        if ( userDn == null ) {
+            throw new PasswordException().setResultCode( ResultCodeEnum.INVALID_CREDENTIALS
);
+        }
+        
+        return authenticate( userDn, password );
+    }
+    
+    
+    @Override
     public PasswordWarning authenticate( Dn userDn, char[] password ) throws PasswordException
     {
         LdapConnection connection = null;
@@ -313,6 +346,19 @@ public class LdapConnectionTemplate impl
 
     }
 
+    @Override
+    public void modifyPassword( Dn userDn, char[] newPassword ) 
+        throws PasswordException
+    {
+        modifyPassword( userDn, null, newPassword, true );
+    }
+
+    @Override
+    public void modifyPassword( Dn userDn, char[] oldPassword,
+        char[] newPassword ) throws PasswordException
+    {
+        modifyPassword( userDn, oldPassword, newPassword, false );
+    }
 
     @Override
     public void modifyPassword( Dn userDn, char[] oldPassword,
@@ -530,6 +576,46 @@ public class LdapConnectionTemplate impl
 
 
     @Override
+    public <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper )
+    {
+        return searchFirst( 
+            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper )
+    {
+        return searchFirst( 
+            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> T searchFirst( String baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper )
+    {
+        return searchFirst(
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> T searchFirst( Dn baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper )
+    {
+        return searchFirst(
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            entryMapper );
+    }
+    
+    
+    @Override
     public <T> T searchFirst( SearchRequest searchRequest,
         EntryMapper<T> entryMapper )
     {
@@ -550,6 +636,46 @@ public class LdapConnectionTemplate impl
 
 
     @Override
+    public <T> List<T> search( String baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper )
+    {
+        return search( 
+            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
+        EntryMapper<T> entryMapper )
+    {
+        return search( 
+            modelFactory.newSearchRequest( baseDn, filter, scope ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> List<T> search( String baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper )
+    {
+        return search(
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            entryMapper );
+    }
+
+
+    @Override
+    public <T> List<T> search( Dn baseDn, String filter, SearchScope scope,
+        String[] attributes, EntryMapper<T> entryMapper )
+    {
+        return search(
+            modelFactory.newSearchRequest( baseDn, filter, scope, attributes ), 
+            entryMapper );
+    }
+
+
+    @Override
     public <T> List<T> search( SearchRequest searchRequest,
         EntryMapper<T> entryMapper )
     {



Mime
View raw message