Skip to content

Commit

Permalink
Added generic CMC servlet.
Browse files Browse the repository at this point in the history
The caProfileSubmitCMCFull servlet has been modified to accept
the profile ID specified in the URL query parameter, which will
override the default profile ID specified in the web.xml.

The HttpClient was previously using StringTokenizer with '=' as
delimiter to parse the configuration file, which caused a problem
when parsing URL query parameters. The code has been modified to
use the Properties class to parse the configuration file properly.

https://pagure.io/dogtagpki/issue/2815

Change-Id: I99c63bcef7c9e6975c5e8652693c6467c5424ae6
  • Loading branch information
edewata committed Sep 22, 2017
1 parent d7fc489 commit 9e33fcc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
62 changes: 19 additions & 43 deletions base/java-tools/src/com/netscape/cmstools/HttpClient.java
Expand Up @@ -30,7 +30,7 @@
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.util.StringTokenizer;
import java.util.Properties;

import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.crypto.CryptoToken;
Expand Down Expand Up @@ -286,17 +286,14 @@ static void printUsage() {
System.out.println("#This parameter will be ignored if clientmode=false");
System.out.println("nickname=");
System.out.println("");
System.out.println("#servlet: servlet name");
System.out.println("servlet=/ca/profileSubmitCMCFull");
System.out.println("#servlet: target URL");
System.out.println("#This parameter may include query parameters");
System.out.println("servlet=/ca/ee/ca/profileSubmitCMCFull?profileId=caFullCMCUserCert");
System.out.println("");
System.exit(0);
}

public static void main(String args[]) {
String host = null, portstr = null, secure = null, tokenName = null, dbdir = null, nickname = null;
String password = null, ofilename = null, ifilename = null;
String servlet = null;
String clientmode = null;

System.out.println("");

Expand All @@ -322,48 +319,27 @@ public static void main(String args[]) {
return;
}

Properties config = new Properties();
try {
String str = "";
while ((str = reader.readLine()) != null) {
str = str.trim();
if (!str.startsWith("#") && str.length() > 0) {
StringTokenizer tokenizer = new StringTokenizer(str, "=");
if (tokenizer.hasMoreTokens()) {
String name = tokenizer.nextToken();
String val = null;
if (tokenizer.countTokens() > 0)
val = tokenizer.nextToken();
if (name.equals("host")) {
host = val;
} else if (name.equals("port")) {
portstr = val;
} else if (name.equals("secure")) {
secure = val;
} else if (name.equals("tokenname")) {
tokenName = val;
} else if (name.equals("dbdir")) {
dbdir = val;
} else if (name.equals("nickname")) {
nickname = val;
} else if (name.equals("password")) {
password = val;
} else if (name.equals("output")) {
ofilename = val;
} else if (name.equals("input")) {
ifilename = val;
} else if (name.equals("clientmode")) {
clientmode = val;
} else if (name.equals("servlet")) {
servlet = val;
}
}
}
}
config.load(reader);

} catch (Exception e) {
e.printStackTrace();
printUsage();
}

String host = config.getProperty("host");
String portstr = config.getProperty("port");
String secure = config.getProperty("secure");
String tokenName = config.getProperty("tokenname");
String dbdir = config.getProperty("dbdir");
String nickname = config.getProperty("nickname");
String password = config.getProperty("password");
String ofilename = config.getProperty("output");
String ifilename = config.getProperty("input");
String clientmode = config.getProperty("clientmode");
String servlet = config.getProperty("servlet");

if (host == null) {
System.out.println("Missing host name.");
printUsage();
Expand Down
Expand Up @@ -353,13 +353,10 @@ public void process(CMSRequest cmsReq) throws EBaseException {
return;
}

// if we did not configure profileId in xml file,
// then accept the user-provided one
String profileId = null;
// use user-provided profile ID
String profileId = request.getParameter("profileId");

if (mProfileId == null) {
profileId = request.getParameter("profileId");
} else {
if (profileId == null) { // otherwise use the default one
profileId = mProfileId;
}

Expand Down

0 comments on commit 9e33fcc

Please sign in to comment.