From ab21b3fdc71955285b9fb858e5cf1094c1bbf66c Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 1 Aug 2013 10:53:22 -0400
Subject: [PATCH] Refactored authentication managers.

The CertUserDBAuthentication and PasswdUserDBAuthentication are authentication
managers in cmscore package but they are needed by PKIRealm that is now in cms
package, so new interfaces have been refactored from these classes so they
can be used without causing dependency issue.
---
 .../authentication/ICertUserDBAuthentication.java  | 37 ++++++++++++++++++++++
 .../IPasswdJUserDBAuthentication.java              | 33 +++++++++++++++++++
 .../src/com/netscape/cms/realm/PKIRealm.java       | 12 +++----
 .../authentication/CertUserDBAuthentication.java   | 10 ++----
 .../authentication/PasswdUserDBAuthentication.java |  9 ++----
 5 files changed, 80 insertions(+), 21 deletions(-)
 create mode 100644 base/common/src/com/netscape/cms/authentication/ICertUserDBAuthentication.java
 create mode 100644 base/common/src/com/netscape/cms/authentication/IPasswdJUserDBAuthentication.java

diff --git a/base/common/src/com/netscape/cms/authentication/ICertUserDBAuthentication.java b/base/common/src/com/netscape/cms/authentication/ICertUserDBAuthentication.java
new file mode 100644
index 0000000000000000000000000000000000000000..7dc4aac9553c665b12f25e0fa0f58a676193ee40
--- /dev/null
+++ b/base/common/src/com/netscape/cms/authentication/ICertUserDBAuthentication.java
@@ -0,0 +1,37 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.cms.authentication;
+
+import com.netscape.certsrv.authentication.IAuthManager;
+
+/**
+ * @author lhsiao
+ * @author cfu
+ * @version $Revision$, $Date$
+ */
+public interface ICertUserDBAuthentication {
+
+    /* result auth token attributes */
+    public static final String TOKEN_USERDN = "user";
+    public static final String TOKEN_USER_DN = "userdn";
+    public static final String TOKEN_USERID = "userid";
+    public static final String TOKEN_UID = "uid";
+
+    /* required credentials */
+    public static final String CRED_CERT = IAuthManager.CRED_SSL_CLIENT_CERT;
+}
\ No newline at end of file
diff --git a/base/common/src/com/netscape/cms/authentication/IPasswdJUserDBAuthentication.java b/base/common/src/com/netscape/cms/authentication/IPasswdJUserDBAuthentication.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d38c34b544a9eb7b49986792e582b1219944e46
--- /dev/null
+++ b/base/common/src/com/netscape/cms/authentication/IPasswdJUserDBAuthentication.java
@@ -0,0 +1,33 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.cms.authentication;
+
+/**
+ * @author lhsiao, cfu
+ * @version $Revision$, $Date$
+ */
+public interface IPasswdJUserDBAuthentication {
+
+    /* required credentials. uid, pwd are strings */
+    public static final String CRED_UID = "uid";
+    public static final String CRED_PWD = "pwd";
+
+    /* attribute in returned token */
+    public static final String TOKEN_USERDN = "userdn";
+    public static final String TOKEN_USERID = "userid";
+}
\ No newline at end of file
diff --git a/base/common/src/com/netscape/cms/realm/PKIRealm.java b/base/common/src/com/netscape/cms/realm/PKIRealm.java
index f1523452764b55fcf3301b94b3f17e83b8a28de1..10fab9ad0ab4f4640e137da4fea0a977a896de8e 100644
--- a/base/common/src/com/netscape/cms/realm/PKIRealm.java
+++ b/base/common/src/com/netscape/cms/realm/PKIRealm.java
@@ -18,9 +18,9 @@ import com.netscape.certsrv.usrgrp.EUsrGrpException;
 import com.netscape.certsrv.usrgrp.IGroup;
 import com.netscape.certsrv.usrgrp.IUGSubsystem;
 import com.netscape.certsrv.usrgrp.IUser;
+import com.netscape.cms.authentication.ICertUserDBAuthentication;
+import com.netscape.cms.authentication.IPasswdJUserDBAuthentication;
 import com.netscape.cms.servlet.common.AuthCredentials;
-import com.netscape.cmscore.authentication.CertUserDBAuthentication;
-import com.netscape.cmscore.authentication.PasswdUserDBAuthentication;
 import com.netscape.cmscore.realm.PKIPrincipal;
 
 /**
@@ -47,8 +47,8 @@ public class PKIRealm extends RealmBase {
             IAuthManager authMgr = authSub.getAuthManager(IAuthSubsystem.PASSWDUSERDB_AUTHMGR_ID);
 
             AuthCredentials creds = new AuthCredentials();
-            creds.set(PasswdUserDBAuthentication.CRED_UID, username);
-            creds.set(PasswdUserDBAuthentication.CRED_PWD, password);
+            creds.set(IPasswdJUserDBAuthentication.CRED_UID, username);
+            creds.set(IPasswdJUserDBAuthentication.CRED_PWD, password);
 
             IAuthToken authToken = authMgr.authenticate(creds); // throws exception if authentication fails
 
@@ -79,11 +79,11 @@ public class PKIRealm extends RealmBase {
             IAuthManager authMgr = authSub.getAuthManager(IAuthSubsystem.CERTUSERDB_AUTHMGR_ID);
 
             AuthCredentials creds = new AuthCredentials();
-            creds.set(CertUserDBAuthentication.CRED_CERT, certImpls);
+            creds.set(ICertUserDBAuthentication.CRED_CERT, certImpls);
 
             IAuthToken authToken = authMgr.authenticate(creds); // throws exception if authentication fails
 
-            String username = authToken.getInString(CertUserDBAuthentication.TOKEN_USERID);
+            String username = authToken.getInString(ICertUserDBAuthentication.TOKEN_USERID);
             logDebug("User ID: "+username);
 
             return getPrincipal(username, authToken);
diff --git a/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java b/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java
index fab9c18129573f05012c7cc1757bca359d2f6b63..f259071d03a64ba7b7da1d837689fe03451df01f 100644
--- a/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java
+++ b/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java
@@ -34,6 +34,7 @@ import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.usrgrp.Certificates;
 import com.netscape.certsrv.usrgrp.EUsrGrpException;
 import com.netscape.certsrv.usrgrp.ICertUserLocator;
+import com.netscape.cms.authentication.ICertUserDBAuthentication;
 import com.netscape.cmscore.usrgrp.ExactMatchCertUserLocator;
 import com.netscape.cmscore.usrgrp.User;
 
@@ -47,16 +48,9 @@ import com.netscape.cmscore.usrgrp.User;
  * @author cfu
  * @version $Revision$, $Date$
  */
-public class CertUserDBAuthentication implements IAuthManager {
-
-    /* result auth token attributes */
-    public static final String TOKEN_USERDN = "user";
-    public static final String TOKEN_USER_DN = "userdn";
-    public static final String TOKEN_USERID = "userid";
-    public static final String TOKEN_UID = "uid";
+public class CertUserDBAuthentication implements IAuthManager, ICertUserDBAuthentication {
 
     /* required credentials */
-    public static final String CRED_CERT = IAuthManager.CRED_SSL_CLIENT_CERT;
     protected String[] mRequiredCreds = { CRED_CERT };
 
     /* config parameters to pass to console (none) */
diff --git a/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java b/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java
index 449a196d443f27fb7e947f157776b55586e6bcaa..c6bb04e1d6b8409367197f839d087a8d5ea20f18 100644
--- a/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java
+++ b/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java
@@ -35,6 +35,7 @@ import com.netscape.certsrv.base.IConfigStore;
 import com.netscape.certsrv.ldap.ELdapException;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.usrgrp.IUser;
+import com.netscape.cms.authentication.IPasswdJUserDBAuthentication;
 import com.netscape.cmscore.dbs.DBSubsystem;
 import com.netscape.cmscore.ldapconn.LdapAnonConnFactory;
 import com.netscape.cmscore.ldapconn.LdapBoundConnFactory;
@@ -52,17 +53,11 @@ import com.netscape.cmscore.util.Debug;
  * @author lhsiao, cfu
  * @version $Revision$, $Date$
  */
-public class PasswdUserDBAuthentication implements IAuthManager {
+public class PasswdUserDBAuthentication implements IAuthManager, IPasswdJUserDBAuthentication {
 
     /* required credentials. uid, pwd are strings */
-    public static final String CRED_UID = "uid";
-    public static final String CRED_PWD = "pwd";
     protected static String[] mRequiredCred = { CRED_UID, CRED_PWD };
 
-    /* attribute in returned token */
-    public static final String TOKEN_USERDN = "userdn";
-    public static final String TOKEN_USERID = "userid";
-
     /* configuration params to pass to console (none) */
     protected static String[] mConfigParams = null;
 
-- 
1.8.1.4

