directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject directory-fortress-core git commit: FC-215 - User Add entry already exists exception
Date Sun, 25 Jun 2017 18:08:18 GMT
Repository: directory-fortress-core
Updated Branches:
  refs/heads/master dc8a7cac5 -> 49b76cee6


FC-215 - User Add entry already exists exception


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/49b76cee
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/49b76cee
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/49b76cee

Branch: refs/heads/master
Commit: 49b76cee698ae537dd221258a5ff83fd6cabb167
Parents: dc8a7ca
Author: Shawn McKinney <smckinney@apache.org>
Authored: Sun Jun 25 13:08:11 2017 -0500
Committer: Shawn McKinney <smckinney@apache.org>
Committed: Sun Jun 25 13:08:11 2017 -0500

----------------------------------------------------------------------
 .../directory/fortress/core/GlobalErrIds.java   |  5 +++++
 .../directory/fortress/core/impl/UserDAO.java   |  6 ++++++
 .../core/samples/LoadTestUserSample.java        | 22 +++++++++++++++-----
 3 files changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/49b76cee/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
index eae0b26..711e51e 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
@@ -382,6 +382,11 @@ public final class GlobalErrIds
     public static final int USER_BIND_FAILED = 1037;
 
     /**
+     * The User node could not be added to ldap.
+     */
+    public static final int USER_ADD_FAILED_ALREADY_EXISTS = 1038;
+
+    /**
      * 2000's User-Role assignments
      */
 

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/49b76cee/src/main/java/org/apache/directory/fortress/core/impl/UserDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/UserDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/UserDAO.java
index 1c9a589..c4211bf 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/UserDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/UserDAO.java
@@ -43,6 +43,7 @@ import org.apache.directory.api.ldap.model.entry.Modification;
 import org.apache.directory.api.ldap.model.entry.ModificationOperation;
 import org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException;
 import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
+import org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException;
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.api.ldap.model.exception.LdapNoPermissionException;
@@ -312,6 +313,11 @@ final class UserDAO extends LdapDataProvider
             add( ld, myEntry, entity );
             entity.setDn( dn );
         }
+        catch ( LdapEntryAlreadyExistsException e )
+        {
+            String error = "create userId [" + entity.getUserId() + "] failed, already exists
in directory";
+            throw new CreateException( GlobalErrIds.USER_ADD_FAILED_ALREADY_EXISTS, error,
e );
+        }
         catch ( LdapException e )
         {
             String error = "create userId [" + entity.getUserId() + "] caught LDAPException="
+ e.getMessage();

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/49b76cee/src/test/java/org/apache/directory/fortress/core/samples/LoadTestUserSample.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/samples/LoadTestUserSample.java
b/src/test/java/org/apache/directory/fortress/core/samples/LoadTestUserSample.java
index 8066a7a..8538a7c 100644
--- a/src/test/java/org/apache/directory/fortress/core/samples/LoadTestUserSample.java
+++ b/src/test/java/org/apache/directory/fortress/core/samples/LoadTestUserSample.java
@@ -33,6 +33,7 @@ import junit.framework.TestSuite;
 import org.apache.directory.fortress.core.model.UserRole;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import sun.rmi.runtime.Log;
 
 /**
  * LoadTestUserSample JUnit Test.  These samples create many users and assign them to roles.
@@ -158,9 +159,6 @@ public class LoadTestUserSample extends TestCase
              *   {@link User#setRole(String)}="sampleRole1"
              *   {@link User#ou}="sampleUserOU1"
              */
-            //User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE,
CreateUserOrgSample.TEST_USER_OU_NM);
-            //User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE,
CreateUserOrgSample.TEST_USER_OU_NM);
-
             for( int i = 1; i <= NUMBER_TEST_USERS; i++)
             {
                 User inUser = new User(TEST_USERID + i, TEST_PASSWORD);
@@ -168,14 +166,28 @@ public class LoadTestUserSample extends TestCase
                 // Now call the add API.  The API will return User entity with associated
LDAP dn if creation was successful.
                 User outUser = adminMgr.addUser(inUser);
                 assertNotNull(outUser);
+
+                if( i % 1000 == 0)
+                {
+                    System.out.println( ".");
+                }
             }
 
             LOG.info(szLocation + " users create success");
         }
         catch (SecurityException ex)
         {
-            LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ",
msg=" + ex.getMessage(), ex);
-            fail(ex.getMessage());
+            // org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException:
+
+            if(ex.getErrorId() == GlobalErrIds.USER_ADD_FAILED_ALREADY_EXISTS)
+            {
+                // ignore
+            }
+            else
+            {
+                LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId()
+ ", msg=" + ex.getMessage(), ex);
+                fail(ex.getMessage());
+            }
         }
     }
 


Mime
View raw message