>From 5b217c7e00f167ca4cc5c808d0b28a78dad9133e Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Thu, 6 Dec 2012 21:57:14 -0500
Subject: [PATCH] Ticket 214 - Proper error message when adding a duplicate
 user

---
 base/common/src/UserMessages.properties                            |    1 +
 base/common/src/com/netscape/cms/servlet/admin/UserService.java    |    2 +-
 .../src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java     |    3 ++-
 base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java       |    4 ++++
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/base/common/src/UserMessages.properties b/base/common/src/UserMessages.properties
index 694c31d6513b0ada39bd96227fbc00f9c472a68f..01d5fbc0f19eb8b3d9d6d182e89fde5694254c93 100644
--- a/base/common/src/UserMessages.properties
+++ b/base/common/src/UserMessages.properties
@@ -554,6 +554,7 @@ CMS_USRGRP_SRVLT_CERT_NOT_YET_VALID=Certificate not yet valid
 CMS_USRGRP_SRVLT_CERT_O_ERROR=Certificate related error
 CMS_USRGRP_USER_ADD_FAILED=Failed to add user
 CMS_USRGRP_USER_ADD_FAILED_1=Failed to add user. Missing \"{0}\"
+CMS_USRGRP_USER_ADD_FAILED_2=An user already exits with the user id \"{0}\".
 CMS_USRGRP_USER_MOD_FAILED=Failed to modify user.
 CMS_USRGRP_USER_MOD_FAILED_1=Failed to modify user. Missing \"{0}\"
 CMS_USRGRP_SRVLT_USER_CERT_EXISTS=Failed to add cert: The certificate you tried to add already exists
diff --git a/base/common/src/com/netscape/cms/servlet/admin/UserService.java b/base/common/src/com/netscape/cms/servlet/admin/UserService.java
index 4813d10bec12036682f3eef178f326328a59b112..9a54802ef88dc4a24a13403402bcbbc7b6f813b9 100644
--- a/base/common/src/com/netscape/cms/servlet/admin/UserService.java
+++ b/base/common/src/com/netscape/cms/servlet/admin/UserService.java
@@ -298,7 +298,7 @@ public class UserService extends PKIService implements UserResource {
                 if (user.getUserID() == null) {
                     throw new BadRequestDataException(getUserMessage("CMS_USRGRP_USER_ADD_FAILED_1", "uid"));
                 } else {
-                    throw new PKIException(getUserMessage("CMS_USRGRP_USER_ADD_FAILED"));
+                    throw new PKIException(e.getMessage());
                 }
 
             } catch (LDAPException e) {
diff --git a/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java b/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java
index 2cd337123a7b4b71c079fdba157a11449e4a18e6..506d608cd988870e3f7de797d23ac044c8d09b66 100644
--- a/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java
+++ b/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java
@@ -897,7 +897,8 @@ public class UsrGrpAdminServlet extends AdminServlet {
                             CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED_1", "uid"), null, resp);
                 } else {
                     sendResponse(ERROR,
-                            CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED"), null, resp);
+                            CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED_2", user.getUserID()), null,
+                            resp);
                 }
                 return;
             } catch (LDAPException e) {
diff --git a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
index 034357b6efb727f4d793ac14b8f7545bc28f6aa1..6314c226f3621880d03ef0b9ea7defa6c15bbbd5 100644
--- a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
@@ -646,6 +646,10 @@ public final class UGSubsystem implements IUGSubsystem {
             throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_ADD_USER_FAIL_NO_UID"));
         }
 
+        if (getUser(id.getUserID()) != null) {
+            throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_USER_ADD_FAILED_2", id.getUserID()));
+        }
+
         LDAPAttributeSet attrs = new LDAPAttributeSet();
         String oc[] = { "top", "person", "organizationalPerson",
                 "inetOrgPerson", "cmsuser" };
-- 
1.7.10.2

