summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-10-15 16:44:14 -0500
committerEndi Sukma Dewata <edewata@vm-117.idm.lab.bos.redhat.com>2012-10-17 19:26:18 -0400
commitce85954043c1890cd83bdb2ba79e8c92eb4405ae (patch)
treebdb2009828b0d202a10be4abbd4c31fc26e45ae0
parent2e2a1ed2401a9b0130eb2b5218508f5c1fd569b1 (diff)
downloadpki-ticket-309.zip
pki-ticket-309.tar.gz
pki-ticket-309.tar.xz
Refactored GetCookie servlet.ticket-309
The GetCookie servlet has been refactored to use the new SecurityDomainProcessor. Ticket #309
-rw-r--r--base/common/src/com/netscape/cms/servlet/csadmin/GetCookie.java132
1 files changed, 43 insertions, 89 deletions
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/GetCookie.java b/base/common/src/com/netscape/cms/servlet/csadmin/GetCookie.java
index 082c43b..6e26908 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/GetCookie.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/GetCookie.java
@@ -18,7 +18,6 @@
package com.netscape.cms.servlet.csadmin;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Locale;
@@ -35,8 +34,8 @@ import com.netscape.certsrv.authentication.IAuthToken;
import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.base.IArgBlock;
import com.netscape.certsrv.base.IConfigStore;
-import com.netscape.certsrv.base.ISecurityDomainSessionTable;
import com.netscape.certsrv.logging.ILogger;
+import com.netscape.certsrv.system.InstallToken;
import com.netscape.cms.servlet.base.CMSServlet;
import com.netscape.cms.servlet.base.UserInfo;
import com.netscape.cms.servlet.common.CMSRequest;
@@ -171,99 +170,54 @@ public class GetCookie extends CMSServlet {
return;
}
- String cookie = "";
- String auditMessage = "";
-
if (authToken != null) {
String uid = authToken.getInString("uid");
- String groupname = ConfigurationUtils.getGroupName(uid, subsystem);
-
- if (groupname != null) {
-
- auditMessage = CMS.getLogMessage(
- LOGGING_SIGNED_AUDIT_ROLE_ASSUME,
- uid,
- ILogger.SUCCESS,
- groupname);
- audit(auditMessage);
-
- // assign cookie
- long num = mRandom.nextLong();
- cookie = num + "";
- ISecurityDomainSessionTable ctable = CMS.getSecurityDomainSessionTable();
- String addr = "";
- try {
- addr = u.getHost();
- } catch (Exception e) {
- }
- String ip = "";
- try {
- ip = InetAddress.getByName(addr).toString();
- int index = ip.indexOf("/");
- if (index > 0)
- ip = ip.substring(index + 1);
- } catch (Exception e) {
- }
- String auditParams = "operation;;issue_token+token;;" + cookie + "+ip;;" + ip +
- "+uid;;" + uid + "+groupname;;" + groupname;
-
- int status = ctable.addEntry(cookie, ip, uid, groupname);
- if (status == ISecurityDomainSessionTable.SUCCESS) {
- auditMessage = CMS.getLogMessage(
- LOGGING_SIGNED_AUDIT_SECURITY_DOMAIN_UPDATE,
- uid,
- ILogger.SUCCESS,
- auditParams);
- audit(auditMessage);
- } else {
- auditMessage = CMS.getLogMessage(
- LOGGING_SIGNED_AUDIT_SECURITY_DOMAIN_UPDATE,
- uid,
- ILogger.FAILURE,
- auditParams);
- audit(auditMessage);
- }
+ String addr = "";
+ try {
+ addr = u.getHost();
+ } catch (Exception e) {
+ }
- try {
- if (!url.startsWith("$")) {
- try {
- form = getTemplate(mFormPath, httpReq, locale);
- } catch (IOException e) {
- CMS.debug("GetCookie process: cant locate the form");
- /*
- log(ILogger.LL_FAILURE,
- CMS.getLogMessage("CMSGW_ERR_GET_TEMPLATE", e.toString()));
- throw new ECMSGWException(
- CMS.getUserMessage("CMS_GW_DISPLAY_TEMPLATE_ERROR"));
- */
- }
-
- header.addStringValue("url", url);
- header.addStringValue("session_id", cookie);
-
- try {
- ServletOutputStream out = httpResp.getOutputStream();
-
- cmsReq.setStatus(CMSRequest.SUCCESS);
- httpResp.setContentType("text/html");
- form.renderOutput(out, argSet);
- } catch (IOException e) {
- log(ILogger.LL_FAILURE,
- CMS.getLogMessage("CMSGW_ERR_OUT_STREAM_TEMPLATE", e.toString()));
- throw new ECMSGWException(
- CMS.getUserMessage("CMS_GW_DISPLAY_TEMPLATE_ERROR"));
- }
+ try {
+ SecurityDomainProcessor processor = new SecurityDomainProcessor(getLocale(httpReq));
+
+ InstallToken installToken = processor.getInstallToken(uid, addr, subsystem);
+ String cookie = installToken.getToken();
+
+ if (!url.startsWith("$")) {
+ try {
+ form = getTemplate(mFormPath, httpReq, locale);
+ } catch (IOException e) {
+ CMS.debug("GetCookie process: cant locate the form");
+ /*
+ log(ILogger.LL_FAILURE,
+ CMS.getLogMessage("CMSGW_ERR_GET_TEMPLATE", e.toString()));
+ throw new ECMSGWException(
+ CMS.getUserMessage("CMS_GW_DISPLAY_TEMPLATE_ERROR"));
+ */
+ }
+
+ header.addStringValue("url", url);
+ header.addStringValue("session_id", cookie);
+
+ try {
+ ServletOutputStream out = httpResp.getOutputStream();
+
+ cmsReq.setStatus(CMSRequest.SUCCESS);
+ httpResp.setContentType("text/html");
+ form.renderOutput(out, argSet);
+
+ } catch (IOException e) {
+ log(ILogger.LL_FAILURE,
+ CMS.getLogMessage("CMSGW_ERR_OUT_STREAM_TEMPLATE", e.toString()));
+ throw new ECMSGWException(
+ CMS.getUserMessage("CMS_GW_DISPLAY_TEMPLATE_ERROR"));
}
- } catch (Exception e) {
}
- } else {
- auditMessage = CMS.getLogMessage(
- LOGGING_SIGNED_AUDIT_ROLE_ASSUME,
- uid,
- ILogger.FAILURE,
- "Enterprise " + subsystem + " Administrators");
- audit(auditMessage);
+
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
}