>From dbbc2c9a56865afd4f25e1c36900a950661ee940 Mon Sep 17 00:00:00 2001
From: Christina Fu <cfu@redhat.com>
Date: Mon, 7 Jul 2014 13:48:47 -0700
Subject: [PATCH] TPSRewrite credential match fix

---
 .../src/org/dogtagpki/tps/msg/ExtendedLoginResponseMsg.java |  8 ++++++++
 base/common/src/org/dogtagpki/tps/msg/TPSMessage.java       |  4 ++++
 base/tps-tomcat/shared/conf/CS.cfg.in                       |  4 ++--
 .../org/dogtagpki/server/tps/processor/TPSProcessor.java    | 13 +++++++++++--
 base/tps/tools/raclient/RA_Conn.cpp                         |  6 ++++--
 5 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponseMsg.java b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponseMsg.java
index 173a775f48a2635ef04d7f8a8a55549665986ee2..7a04b8d4ced6b32b5ef9d65f7ea59c05c28e8cb5 100644
--- a/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponseMsg.java
+++ b/base/common/src/org/dogtagpki/tps/msg/ExtendedLoginResponseMsg.java
@@ -42,6 +42,14 @@ public class ExtendedLoginResponseMsg extends TPSMessage {
 
     }
 
+    public ExtendedLoginResponseMsg(OpType theOp, Map<String, String> theExtensions) {
+
+        put(OPERATION_TYPE_NAME, opTypeToInt(theOp));
+        put(MSG_TYPE_NAME, msgTypeToInt(MsgType.MSG_EXTENDED_LOGIN_RESPONSE));
+        authParams = theExtensions;
+
+    }
+
     public static void main(String[] args) {
 
     }
diff --git a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
index 16fec1dd8b709376ccf30ae65ccabe9cbf6fc070..a6e6096278bdf63a455e751dbda59989a1654f51 100644
--- a/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
+++ b/base/common/src/org/dogtagpki/tps/msg/TPSMessage.java
@@ -454,10 +454,14 @@ public class TPSMessage {
             break;
         case MSG_EXTENDED_LOGIN_RESPONSE:
             result =
+/*
                 new ExtendedLoginResponseMsg(op_val,
                     get(SCREEN_NAME_NAME),
                     get(PASSWORD_NAME),
                     extsMap);
+*/
+                new ExtendedLoginResponseMsg(op_val,
+                    extsMap);
             break;
         case MSG_LOGIN_REQUEST:
             break;
diff --git a/base/tps-tomcat/shared/conf/CS.cfg.in b/base/tps-tomcat/shared/conf/CS.cfg.in
index 57a7866a5b3ba0a5bfb5e4d4e69bbb22a854bf09..9f5b9124944218572fa3bda1250ed7f71e0be265 100644
--- a/base/tps-tomcat/shared/conf/CS.cfg.in
+++ b/base/tps-tomcat/shared/conf/CS.cfg.in
@@ -41,11 +41,11 @@ auths.instance.ldap1.ui.description.en=This authenticates user against the LDAP
 auths.instance.ldap1.ui.id.UID.description.en=LDAP User ID
 auths.instance.ldap1.ui.id.UID.name.en=LDAP User ID
 auths.instance.ldap1.ui.id.UID.credMap.authCred=uid
-auths.instance.ldap1.ui.id.UID.credMap.msgCred=screen_name
+auths.instance.ldap1.ui.id.UID.credMap.msgCred=UID
 auths.instance.ldap1.ui.id.PASSWORD.description.en=LDAP Password
 auths.instance.ldap1.ui.id.PASSWORD.name.en=LDAP Password
 auths.instance.ldap1.ui.id.PASSWORD.credMap.authCred=pwd
-auths.instance.ldap1.ui.id.PASSWORD.credMap.msgCred=password
+auths.instance.ldap1.ui.id.PASSWORD.credMap.msgCred=PASSWORD
 auths.instance.ldap1.dnpattern=
 auths.instance.ldap1.ldapByteAttributes=
 auths.instance.ldap1.ldapStringAttributes=mail,cn,uid
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
index 98e4d4885cb157c4738ba3c46082bb697b8c2c3e..e2f49adba3988fa391893152e33a7d7f5bc5e302 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/processor/TPSProcessor.java
@@ -737,8 +737,14 @@ public class TPSProcessor {
 
         String[] requiredCreds = auth.getAuthManager().getRequiredCreds();
         for (String cred : requiredCreds) {
+            CMS.debug("TPSProcessor.mapCredFromMsgResponse: mapping required auth cred:"+ cred);
             String name = auth.getCredMap(cred);
-            login.set(cred, response.get(name));
+            if (name != null) {
+                CMS.debug("TPSProcessor.mapCredFromMsgResponse: mapped to:"+ name);
+                login.set(cred, response.get(name));
+            } else {
+                CMS.debug("TPSProcessor.mapCredFromMsgResponse: not mapped");
+            }
         }
 
         return login;
@@ -816,7 +822,10 @@ public class TPSProcessor {
             throw e;
         }
 
-        IAuthCredentials login = mapCredFromMsgResponse(loginResp, auth);
+        IAuthCredentials login = 
+                new com.netscape.certsrv.authentication.AuthCredentials();
+        login.set("uid", loginResp.get(TPSMessage.SCREEN_NAME_NAME));
+        login.set("pwd", loginResp.get(TPSMessage.PASSWORD_NAME));
         return login;
     }
 
diff --git a/base/tps/tools/raclient/RA_Conn.cpp b/base/tps/tools/raclient/RA_Conn.cpp
index 8e7f30e5155c0f7b04351286e42b0f1928dc25ca..d9502abfe561dde2a99d4bceea75defdab77500d 100644
--- a/base/tps/tools/raclient/RA_Conn.cpp
+++ b/base/tps/tools/raclient/RA_Conn.cpp
@@ -82,6 +82,8 @@
 #define PARAM_INVALID_PW              "invalid_pw"
 #define PARAM_BLOCKED                 "blocked"
 #define PARAM_SCREEN_NAME             "screen_name"
+#define PARAM_E_UID                   "UID"
+#define PARAM_E_PASSWORD              "PASSWORD"
 #define PARAM_PASSWORD                "password"
 #define PARAM_PIN_REQUIRED            "pin_required"
 #define PARAM_NEXT_VALUE              "next_value"
@@ -315,8 +317,8 @@ RA_Conn::SendMsg (RA_Msg * msg)
       AuthParams *auth = resp->GetAuthParams ();
       sprintf (msgbuf, "%s=%d&%s=%s&%s=%s",
 	       PARAM_MSG_TYPE, MSG_EXTENDED_LOGIN_RESPONSE,
-	       PARAM_SCREEN_NAME, auth->GetUID (),
-	       PARAM_PASSWORD, auth->GetPassword ());
+	       PARAM_E_UID, auth->GetUID (),
+	       PARAM_E_PASSWORD, auth->GetPassword ());
       CreateChunkEntity (msgbuf, chunk, 4096);
     }
   else if (msg->GetType () == MSG_STATUS_UPDATE_RESPONSE)
-- 
1.8.4.2

