summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-10-15 16:44:14 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-10-18 10:07:03 -0500
commit8973480558c6b87c4aa6e1fdcd48b6d98c05a042 (patch)
treebdb2009828b0d202a10be4abbd4c31fc26e45ae0 /base
parent168d95446c3a7ae8643128a51fa86dd326e3a6a8 (diff)
downloadpki-8973480558c6b87c4aa6e1fdcd48b6d98c05a042.tar.gz
pki-8973480558c6b87c4aa6e1fdcd48b6d98c05a042.tar.xz
pki-8973480558c6b87c4aa6e1fdcd48b6d98c05a042.zip
Refactored GetCookie servlet.
The GetCookie servlet has been refactored to use the new SecurityDomainProcessor. Ticket #309
Diffstat (limited to 'base')
-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 082c43b42..6e269089e 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();
}
}
}