summaryrefslogtreecommitdiffstats
path: root/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2015-10-20 21:07:33 +0200
committerMatthew Harmsen <mharmsen@redhat.com>2015-10-23 09:31:49 -0600
commite35499a0d72b47e1418cfb6526c301b442c87155 (patch)
tree1e53b2bef8f51d84da9fa8d5050f5aebdfa3687a /base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
parenta156c64a8af6e32e6f356b4660769a808a361521 (diff)
downloadpki-e35499a0d72b47e1418cfb6526c301b442c87155.tar.gz
pki-e35499a0d72b47e1418cfb6526c301b442c87155.tar.xz
pki-e35499a0d72b47e1418cfb6526c301b442c87155.zip
Replaced legacy HttpClient.
The ConfigurationUtils and CertUtil have been modified to use PKIConnection which uses Apache HttpClient instead of the legacy custom HttpClient. The POST request content is now created using MultivaluedMap. The PKIConnection has been modified to provide a get() method to send an HTTP GET request. The post() method was modified to accept a path parameter. https://fedorahosted.org/pki/ticket/342 (cherry picked from commit aaacd71a2f125501645885d3da1de18459782572)
Diffstat (limited to 'base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java')
-rw-r--r--base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java38
1 files changed, 11 insertions, 27 deletions
diff --git a/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java b/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
index 5eeddecb3..ebda0b620 100644
--- a/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
+++ b/base/server/cms/src/com/netscape/cms/authentication/TokenAuthentication.java
@@ -18,11 +18,13 @@
package com.netscape.cms.authentication;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Vector;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.authentication.AuthToken;
import com.netscape.certsrv.authentication.EInvalidCredentials;
@@ -38,10 +40,7 @@ import com.netscape.certsrv.profile.IProfile;
import com.netscape.certsrv.profile.IProfileAuthenticator;
import com.netscape.certsrv.property.IDescriptor;
import com.netscape.certsrv.request.IRequest;
-import com.netscape.cmsutil.http.HttpClient;
-import com.netscape.cmsutil.http.HttpRequest;
-import com.netscape.cmsutil.http.HttpResponse;
-import com.netscape.cmsutil.http.JssSSLSocketFactory;
+import com.netscape.cms.servlet.csadmin.ConfigurationUtils;
import com.netscape.cmsutil.xml.XMLObject;
/**
@@ -138,7 +137,9 @@ public class TokenAuthentication implements IAuthManager,
int authEEPort = sconfig.getInteger("securitydomain.httpseeport");
String authURL = "/ca/admin/ca/tokenAuthenticate";
- String content = CRED_SESSION_ID + "=" + sessionId + "&hostname=" + givenHost;
+ MultivaluedMap<String, String> content = new MultivaluedHashMap<String, String>();
+ content.putSingle(CRED_SESSION_ID, sessionId);
+ content.putSingle("hostname", givenHost);
CMS.debug("TokenAuthentication: content=" + content);
String c = null;
@@ -158,7 +159,7 @@ public class TokenAuthentication implements IAuthManager,
authURL = "/ca/ee/ca/tokenAuthenticate";
try {
c = sendAuthRequest(authHost, authEEPort, authURL, content);
- } catch (IOException e1) {
+ } catch (Exception e1) {
CMS.debug("TokenAuthenticate: failed to contact EE host:port "
+ authHost + ":" + authAdminPort + " " + e1);
throw new EBaseException(e1.getMessage());
@@ -208,27 +209,10 @@ public class TokenAuthentication implements IAuthManager,
return authToken;
}
- private String sendAuthRequest(String authHost, int authPort, String authUrl, String content)
- throws IOException {
- HttpClient httpclient = new HttpClient();
- String c = null;
+ private String sendAuthRequest(String authHost, int authPort, String authUrl, MultivaluedMap<String, String> content)
+ throws Exception {
- JssSSLSocketFactory factory = new JssSSLSocketFactory();
- httpclient = new HttpClient(factory);
- httpclient.connect(authHost, authPort);
- HttpRequest httprequest = new HttpRequest();
- httprequest.setMethod(HttpRequest.POST);
- httprequest.setURI(authUrl);
- httprequest.setHeader("user-agent", "HTTPTool/1.0");
- httprequest.setHeader("content-length", "" + content.length());
- httprequest.setHeader("content-type",
- "application/x-www-form-urlencoded");
- httprequest.setContent(content);
-
- HttpResponse httpresponse = httpclient.send(httprequest);
- c = httpresponse.getContent();
-
- return c;
+ return ConfigurationUtils.post(authHost, authPort, true, authUrl, content, null, null);
}
/**