From 5c2ef06ac5d848059063cacb4b4dea7844215ece 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  | 36 ++++++++++++++++++++++
 .../IPasswdUserDBAuthentication.java               | 33 ++++++++++++++++++++
 .../src/com/netscape/cms/realm/PKIRealm.java       | 12 ++++----
 .../authentication/CertUserDBAuthentication.java   | 10 ++----
 .../authentication/PasswdUserDBAuthentication.java |  9 ++----
 5 files changed, 79 insertions(+), 21 deletions(-)
 create mode 100644 base/common/src/com/netscape/certsrv/authentication/ICertUserDBAuthentication.java
 create mode 100644 base/common/src/com/netscape/certsrv/authentication/IPasswdUserDBAuthentication.java

diff --git a/base/common/src/com/netscape/certsrv/authentication/ICertUserDBAuthentication.java b/base/common/src/com/netscape/certsrv/authentication/ICertUserDBAuthentication.java
new file mode 100644
index 0000000000000000000000000000000000000000..5b905061c8ccadb11127928c540a9ff93ed976a5
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/authentication/ICertUserDBAuthentication.java
@@ -0,0 +1,36 @@
+// --- 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.certsrv.authentication;
+
+
+/**
+ * @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/certsrv/authentication/IPasswdUserDBAuthentication.java b/base/common/src/com/netscape/certsrv/authentication/IPasswdUserDBAuthentication.java
new file mode 100644
index 0000000000000000000000000000000000000000..2921b677803882601ae7a2d57c7dac75d8b3e028
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/authentication/IPasswdUserDBAuthentication.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.certsrv.authentication;
+
+/**
+ * @author lhsiao, cfu
+ * @version $Revision$, $Date$
+ */
+public interface IPasswdUserDBAuthentication {
+
+    /* 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..d6ac100f5f023523d182733d6d82136615883690 100644
--- a/base/common/src/com/netscape/cms/realm/PKIRealm.java
+++ b/base/common/src/com/netscape/cms/realm/PKIRealm.java
@@ -14,13 +14,13 @@ import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.authentication.IAuthManager;
 import com.netscape.certsrv.authentication.IAuthSubsystem;
 import com.netscape.certsrv.authentication.IAuthToken;
+import com.netscape.certsrv.authentication.ICertUserDBAuthentication;
+import com.netscape.certsrv.authentication.IPasswdUserDBAuthentication;
 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.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(IPasswdUserDBAuthentication.CRED_UID, username);
+            creds.set(IPasswdUserDBAuthentication.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..573b736d4b5c97293cf61865cf00d25d9c88c1bb 100644
--- a/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java
+++ b/base/common/src/com/netscape/cmscore/authentication/CertUserDBAuthentication.java
@@ -28,6 +28,7 @@ import com.netscape.certsrv.authentication.EMissingCredential;
 import com.netscape.certsrv.authentication.IAuthCredentials;
 import com.netscape.certsrv.authentication.IAuthManager;
 import com.netscape.certsrv.authentication.IAuthToken;
+import com.netscape.certsrv.authentication.ICertUserDBAuthentication;
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.base.IConfigStore;
 import com.netscape.certsrv.logging.ILogger;
@@ -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..2905f3c758c1d96873347434bb12a5efd063c957 100644
--- a/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java
+++ b/base/common/src/com/netscape/cmscore/authentication/PasswdUserDBAuthentication.java
@@ -30,6 +30,7 @@ import com.netscape.certsrv.authentication.EMissingCredential;
 import com.netscape.certsrv.authentication.IAuthCredentials;
 import com.netscape.certsrv.authentication.IAuthManager;
 import com.netscape.certsrv.authentication.IAuthToken;
+import com.netscape.certsrv.authentication.IPasswdUserDBAuthentication;
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.base.IConfigStore;
 import com.netscape.certsrv.ldap.ELdapException;
@@ -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, IPasswdUserDBAuthentication {
 
     /* 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

