You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2014/11/05 18:33:17 UTC

[10/20] git commit: Added the read, modify and delete method that take a Dn as a parameter, instead of a String.

Added the read, modify and delete method that take a Dn as a parameter,
instead of a String.

Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/056ce2bb
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/056ce2bb
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/056ce2bb

Branch: refs/heads/master
Commit: 056ce2bb5f6cd8166c4251f66438ea897d76fbe4
Parents: 13ac7c8
Author: Emmanuel Lécharny <el...@symas.com>
Authored: Sun Nov 2 17:02:27 2014 +0100
Committer: Emmanuel Lécharny <el...@symas.com>
Committed: Sun Nov 2 17:02:27 2014 +0100

----------------------------------------------------------------------
 .../core/ldap/ApacheDsDataProvider.java         | 80 +++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/056ce2bb/src/main/java/org/apache/directory/fortress/core/ldap/ApacheDsDataProvider.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/ApacheDsDataProvider.java b/src/main/java/org/apache/directory/fortress/core/ldap/ApacheDsDataProvider.java
index 15cf330..6d03635 100644
--- a/src/main/java/org/apache/directory/fortress/core/ldap/ApacheDsDataProvider.java
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/ApacheDsDataProvider.java
@@ -339,6 +339,23 @@ public abstract class ApacheDsDataProvider
 
 
     /**
+     * Read the ldap record from specified location.
+     *
+     * @param connection handle to ldap connection.
+     * @param dn         contains ldap distinguished name.
+     * @param attrs      array contains array names to pull back.
+     * @return ldap entry.
+     * @throws LdapException in the event system error occurs.
+     */
+    protected Entry read( LdapConnection connection, Dn dn, String[] attrs ) throws LdapException
+    {
+        counters.incrementRead();
+
+        return connection.lookup( dn, attrs );
+    }
+
+
+    /**
      * Read the ldap record from specified location with user assertion.
      *
      * @param connection handle to ldap connection.
@@ -385,7 +402,7 @@ public abstract class ApacheDsDataProvider
     {
         counters.incrementAdd();
 
-        if ( GlobalIds.IS_AUDIT && entity != null && entity.getAdminSession() != null )
+        if ( GlobalIds.IS_AUDIT && ( entity != null ) && ( entity.getAdminSession() != null ) )
         {
             if ( VUtil.isNotNullOrEmpty( entity.getAdminSession().getInternalUserId() ) )
             {
@@ -423,6 +440,21 @@ public abstract class ApacheDsDataProvider
 
 
     /**
+     * Update exiting ldap entry to the directory.  Do not add audit context.
+     *
+     * @param connection handle to ldap connection.
+     * @param dn         contains distinguished node of entry.
+     * @param mods       contains data to modify.
+     * @throws LdapException in the event system error occurs.
+     */
+    protected void modify( LdapConnection connection, Dn dn, List<Modification> mods ) throws LdapException
+    {
+        counters.incrementMod();
+        connection.modify( dn, mods.toArray( new Modification[]{} ) );
+    }
+
+
+    /**
      * Update exiting ldap entry to the directory.  Add audit context.
      *
      * @param connection handle to ldap connection.
@@ -441,6 +473,24 @@ public abstract class ApacheDsDataProvider
 
 
     /**
+     * Update exiting ldap entry to the directory.  Add audit context.
+     *
+     * @param connection handle to ldap connection.
+     * @param dn         contains distinguished node of entry.
+     * @param mods       contains data to modify.
+     * @param entity     contains audit context.
+     * @throws LdapException in the event system error occurs.
+     */
+    protected void modify( LdapConnection connection, Dn dn, List<Modification> mods,
+        FortEntity entity ) throws LdapException
+    {
+        counters.incrementMod();
+        audit( mods, entity );
+        connection.modify( dn, mods.toArray( new Modification[]{} ) );
+    }
+
+
+    /**
      * Delete exiting ldap entry from the directory.  Do not add audit context.
      *
      * @param connection handle to ldap connection.
@@ -480,6 +530,31 @@ public abstract class ApacheDsDataProvider
 
 
     /**
+     * Delete exiting ldap entry from the directory.  Add audit context.  This method will call modify prior to
+     * delete which will
+     * force corresponding audit record to be written to slapd access log.
+     *
+     * @param connection handle to ldap connection.
+     * @param dn         contains distinguished node of entry targeted for removal..
+     * @param entity     contains audit context.
+     * @throws LdapException in the event system error occurs.
+     */
+    protected void delete( LdapConnection connection, Dn dn, FortEntity entity ) throws LdapException
+    {
+        counters.incrementDelete();
+        List<Modification> mods = new ArrayList<Modification>();
+        audit( mods, entity );
+
+        if ( mods.size() > 0 )
+        {
+            modify( connection, dn, mods );
+        }
+
+        connection.delete( dn );
+    }
+
+
+    /**
      * Delete exiting ldap entry and all descendants from the directory.  Do not add audit context.
      *
      * @param connection handle to ldap connection.
@@ -1260,16 +1335,19 @@ public abstract class ApacheDsDataProvider
         if ( VUtil.isNotNullOrEmpty( value ) )
         {
             int length = value.length();
+            
             if ( length > validLen )
             {
                 String error = "encodeSafeText value [" + value + "] invalid length [" + length + "]";
                 throw new LdapException( error );
             }
+            
             if ( GlobalIds.LDAP_FILTER_SIZE_FOUND )
             {
                 value = VUtil.escapeLDAPSearchFilter( value );
             }
         }
+        
         return value;
     }