>From c00eae560539a41e4bc2fc89bd465537c4d2c6a4 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Tue, 19 Jun 2012 11:15:56 -0400
Subject: [PATCH] Fixes for Review Comments for Patch 13

---
 .../com/netscape/cmscore/usrgrp/UGSubsystem.java   |   15 +++++----
 .../com/netscape/cmscore/request/RequestTest.java  |   34 +++-----------------
 base/kra/src/com/netscape/kra/RecoveryService.java |    4 +--
 3 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
index c7e83867dc9323a0b76935447925e106ce0f5121..20ad265242ae925fbf0dd061e971865e09f3e60c 100644
--- a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
@@ -418,7 +418,7 @@ public final class UGSubsystem implements IUGSubsystem {
     protected IUser lbuildUser(LDAPEntry entry) throws EUsrGrpException {
         LDAPAttribute uid = entry.getAttribute("uid");
         if (uid == null) {
-            throw new EUsrGrpException("No User with UID " + uid);
+            throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
         }
         IUser id = createUser(this, (String) uid.getStringValues().nextElement());
         LDAPAttribute cnAttr = entry.getAttribute("cn");
@@ -477,7 +477,7 @@ public final class UGSubsystem implements IUGSubsystem {
     protected IUser buildUser(LDAPEntry entry) throws EUsrGrpException {
         LDAPAttribute uid = entry.getAttribute("uid");
         if (uid == null) {
-            throw new EUsrGrpException("No User with UID " + uid + "for LDAP Entry " + entry.getDN());
+            throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN());
         }
         IUser id = createUser(this, (String) uid.getStringValues().nextElement());
         LDAPAttribute cnAttr = entry.getAttribute("cn");
@@ -1215,7 +1215,7 @@ public final class UGSubsystem implements IUGSubsystem {
      * @throws EUsrGrpException
      */
     protected IGroup buildGroup(LDAPEntry entry) throws EUsrGrpException {
-        LDAPAttribute cn=entry.getAttribute("cn");
+        LDAPAttribute cn = entry.getAttribute("cn");
         if (cn == null) {
             throw new EUsrGrpException("Cannot build group. No Attribute cn in LDAP Entry " + entry.getDN());
         }
@@ -1644,12 +1644,13 @@ public final class UGSubsystem implements IUGSubsystem {
     protected boolean isMatched(String dn1, String dn2) {
         String rdn1[] = LDAPDN.explodeDN(dn1, false);
         String rdn2[] = LDAPDN.explodeDN(dn2, false);
-        if ((rdn1 == null) ^ (rdn2 == null)) {
-            return false;
-        }
-        if ((rdn1 == null) && (rdn2 == null)) {
+        if (rdn1 == null && rdn2 == null) {
             return true;
         }
+        if (rdn1 == null || rdn2 == null) {
+            return false;
+        }
+
         if (rdn1.length == rdn2.length) {
             for (int j = 0; j < rdn1.length; j++) {
                 if (!rdn1[j].equalsIgnoreCase(rdn2[j])) {
diff --git a/base/common/test/com/netscape/cmscore/request/RequestTest.java b/base/common/test/com/netscape/cmscore/request/RequestTest.java
index a18b29f78d2d7759a61e082ba2922d363aa446d6..1de96a20350680dfb46b8835ac333c68a4c8435f 100644
--- a/base/common/test/com/netscape/cmscore/request/RequestTest.java
+++ b/base/common/test/com/netscape/cmscore/request/RequestTest.java
@@ -244,7 +244,7 @@ public class RequestTest extends CMSBaseTestCase {
         };
         assertTrue(request.setExtData("topkey1", data));
         Integer[] retval = request.getExtDataInIntegerArray("topkey1");
-        checkReturnValue(retval, "topkey1");
+        assertNotNull(retval);
         assertEquals(3, retval.length);
         assertEquals(data[0], retval[0]);
         assertEquals(data[1], retval[1]);
@@ -284,7 +284,7 @@ public class RequestTest extends CMSBaseTestCase {
         };
         assertTrue(request.setExtData("topkey1", data));
         BigInteger[] retval = request.getExtDataInBigIntegerArray("topkey1");
-        checkReturnValue(retval, "topkey1");
+        assertNotNull(retval);
         assertEquals(3, retval.length);
         assertEquals(data[0], retval[0]);
         assertEquals(data[1], retval[1]);
@@ -355,7 +355,7 @@ public class RequestTest extends CMSBaseTestCase {
 
         assertFalse(cmsStub.aToBCalled);
         X509CertImpl[] retval = request.getExtDataInCertArray("key");
-        checkReturnValue(retval, "key");
+        assertNotNull(retval);
         assertTrue(cmsStub.aToBCalled);
 
         assertEquals(2, retval.length);
@@ -382,7 +382,7 @@ public class RequestTest extends CMSBaseTestCase {
         assertEquals("orange", hashValue.get("3"));
 
         String[] retval = request.getExtDataInStringArray("key");
-        checkReturnValue(retval, "key");
+        assertNotNull(retval);
         assertEquals(4, retval.length);
         assertEquals("blue", retval[0]);
         assertEquals("green", retval[1]);
@@ -397,7 +397,7 @@ public class RequestTest extends CMSBaseTestCase {
         request.setExtData("kevin", hashValue);
 
         retval = request.getExtDataInStringArray("kevin");
-        checkReturnValue(retval, "kevin");
+        assertNotNull(retval);
         assertEquals(7, retval.length);
         assertEquals("square", retval[0]);
         assertNull(retval[1]);
@@ -555,7 +555,6 @@ public class RequestTest extends CMSBaseTestCase {
         assertTrue(request.mExtData.containsKey("key2"));
 
         retval = request.getExtDataInCertExts("key2");
-        checkReturnValue(retval, "key2");
         assertNotNull(retval);
         assertEquals(1, retval.size());
 
@@ -569,7 +568,6 @@ public class RequestTest extends CMSBaseTestCase {
         assertTrue(request.mExtData.containsKey("key"));
 
         CertificateSubjectName retval = request.getExtDataInCertSubjectName("key");
-        checkReturnValue(retval, "key");
         assertNotNull(retval);
         // the 'CN=' is uppercased at some point
         assertEquals("cn=kevin",
@@ -596,28 +594,6 @@ public class RequestTest extends CMSBaseTestCase {
         assertFalse(request.setExtData("key", (AuthToken) null));
     }
 
-    public void checkReturnValue(Object retVal, String key) throws Exception {
-        if (retVal == null) {
-            String type = "";
-            if (retVal instanceof String[]) {
-                type = "a String array";
-            } else if (retVal instanceof Integer[]) {
-                type = "an Integer array";
-            } else if (retVal instanceof BigInteger[]) {
-                type = "a BigInteger array";
-            } else if (retVal instanceof CertificateSubjectName) {
-                type = "a CertificateSubjectName";
-            } else if (retVal instanceof CertificateExtensions) {
-                type = "a CertificateExtensions";
-            } else if (retVal instanceof X509CertImpl[]) {
-                type = "a X509CertImpl array";
-            } else if (retVal instanceof IAuthToken) {
-                type = "an IAuthToken";
-            }
-            throw new Exception("Unable to get " + key + "as " + type + " object.");
-        }
-    }
-
     /**
      * CMSMemoryStub
      *
diff --git a/base/kra/src/com/netscape/kra/RecoveryService.java b/base/kra/src/com/netscape/kra/RecoveryService.java
index be1cedd8166fe534ae94275d1b4228c2c54f9b9e..1b5781ca0ada68a76bd9245dc07a2318f5c71102 100644
--- a/base/kra/src/com/netscape/kra/RecoveryService.java
+++ b/base/kra/src/com/netscape/kra/RecoveryService.java
@@ -451,7 +451,7 @@ public class RecoveryService implements IService {
             X509Certificate x509cert =
                     request.getExtDataInCert(ATTR_USER_CERT);
             if (x509cert == null) {
-                throw new EKRAException(CMS.getUserMessage("CMS_KRA_INVALID_KEYRECORD"));
+                throw new EKRAException(CMS.getUserMessage("CMS_KRA_PKCS12_FAILED_1","Missing Certificate"));
             }
             String pwd = (String) params.get(ATTR_TRANSPORT_PWD);
 
@@ -591,7 +591,7 @@ public class RecoveryService implements IService {
             X509Certificate x509cert =
                     request.getExtDataInCert(ATTR_USER_CERT);
             if (x509cert == null) {
-                throw new EKRAException(CMS.getUserMessage("CMS_KRA_INVALID_KEYRECORD"));
+                throw new EKRAException(CMS.getUserMessage("CMS_KRA_PKCS12_FAILED_1","Missing Certificate"));
             }
             String pwd = (String) params.get(ATTR_TRANSPORT_PWD);
 
-- 
1.7.10.2

