[Pki-devel] [PATCH] 677 Fixed token add operation.
Endi Sukma Dewata
edewata at redhat.com
Thu Feb 4 04:38:53 UTC 2016
The TokenService has been fixed to allow adding a new token with
empty attributes via the UI or CLI. The TPS UI has been modified
to hide the status, create timestamp, and modify timestamp fields
when adding a new token. The CLI has been modified to provide the
parameters to specify the attribute values.
https://fedorahosted.org/pki/ticket/1646
--
Endi S. Dewata
-------------- next part --------------
From 3fad7b7220d4f7c37b3df596815fc500ce1de279 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata at redhat.com>
Date: Wed, 3 Feb 2016 23:54:56 +0100
Subject: [PATCH] Fixed token add operation.
The TokenService has been fixed to allow adding a new token with
empty attributes via the UI or CLI. The TPS UI has been modified
to hide the status, create timestamp, and modify timestamp fields
when adding a new token. The CLI has been modified to provide the
parameters to specify the attribute values.
https://fedorahosted.org/pki/ticket/1646
---
.../netscape/cmstools/tps/token/TokenAddCLI.java | 35 ++++++++++++++--
base/tps/shared/webapps/tps/js/token.js | 13 ++++++
base/tps/shared/webapps/tps/ui/token.html | 8 ++--
base/tps/shared/webapps/tps/ui/tokens.html | 6 +--
.../dogtagpki/server/tps/rest/TokenService.java | 49 +++++++++++++++-------
5 files changed, 85 insertions(+), 26 deletions(-)
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
index a63df2e8005ad9161a2c90c7c88953abc6a85be4..9252dceacafcdec3fd9709803b92766c932559ca 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
@@ -42,13 +42,28 @@ public class TokenAddCLI extends CLI {
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <Token ID> --user <User ID> [OPTIONS...]", options);
+ formatter.printHelp(getFullName() + " <Token ID> [OPTIONS...]", options);
}
public void createOptions() {
Option option = new Option(null, "user", true, "User ID");
option.setArgName("User ID");
- option.setRequired(true);
+ options.addOption(option);
+
+ option = new Option(null, "type", true, "Type");
+ option.setArgName("Type");
+ options.addOption(option);
+
+ option = new Option(null, "applet", true, "Applet ID");
+ option.setArgName("Applet ID");
+ options.addOption(option);
+
+ option = new Option(null, "key-info", true, "Key info");
+ option.setArgName("Key info");
+ options.addOption(option);
+
+ option = new Option(null, "policy", true, "Policy");
+ option.setArgName("Policy");
options.addOption(option);
}
@@ -83,7 +98,21 @@ public class TokenAddCLI extends CLI {
TokenData tokenData = new TokenData();
tokenData.setTokenID(tokenID);
- tokenData.setUserID(cmd.getOptionValue("user"));
+
+ String userID = cmd.getOptionValue("user");
+ tokenData.setUserID(userID);
+
+ String type = cmd.getOptionValue("type");
+ tokenData.setType(type);
+
+ String appletID = cmd.getOptionValue("applet");
+ tokenData.setAppletID(appletID);
+
+ String keyInfo = cmd.getOptionValue("key-info");
+ tokenData.setKeyInfo(keyInfo);
+
+ String policy = cmd.getOptionValue("policy");
+ tokenData.setPolicy(policy);
tokenData = tokenCLI.tokenClient.addToken(tokenData);
diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js
index a2d25fd6eaf39161fd6fb0e611929789ef87851d..e21cb3176544e7cb934f965a123c8396c919cb5e 100644
--- a/base/tps/shared/webapps/tps/js/token.js
+++ b/base/tps/shared/webapps/tps/js/token.js
@@ -195,8 +195,21 @@ var TokenPage = EntryPage.extend({
if (self.mode == "add") {
self.changeStatusAction.hide();
+ self.$("label[name='createTimestamp']").hide();
+ self.$("input[name='createTimestamp']").hide();
+ self.$("label[name='modifyTimestamp']").hide();
+ self.$("input[name='modifyTimestamp']").hide();
+ self.$("label[name='status']").hide();
+ self.$("input[name='statusLabel']").hide();
+
} else {
self.changeStatusAction.show();
+ self.$("label[name='createTimestamp']").show();
+ self.$("input[name='createTimestamp']").show();
+ self.$("label[name='modifyTimestamp']").show();
+ self.$("input[name='modifyTimestamp']").show();
+ self.$("label[name='status']").show();
+ self.$("input[name='statusLabel']").show();
}
}
});
diff --git a/base/tps/shared/webapps/tps/ui/token.html b/base/tps/shared/webapps/tps/ui/token.html
index 90b9c72a585f5723e47d7830b4a70805088a2fd4..16e92f444654d4cf48871f40f1d714eb96debb9b 100644
--- a/base/tps/shared/webapps/tps/ui/token.html
+++ b/base/tps/shared/webapps/tps/ui/token.html
@@ -49,18 +49,18 @@
<input name="userID" readonly="readonly"><br>
<label>Type</label>
<input name="type" readonly="readonly"><br>
- <label>Status</label>
- <input name="statusLabel" readonly="readonly"><br>
<label>Applet ID</label>
<input name="appletID" readonly="readonly"><br>
<label>Key Info</label>
<input name="keyInfo" readonly="readonly"><br>
<label>Policy</label>
<input name="policy" readonly="readonly"><br>
- <label>Created</label>
+ <label name="createTimestamp">Created</label>
<input name="createTimestamp" readonly="readonly"><br>
- <label>Modified</label>
+ <label name="modifyTimestamp">Modified</label>
<input name="modifyTimestamp" readonly="readonly"><br>
+ <label name="status">Status</label>
+ <input name="statusLabel" readonly="readonly"><br>
</fieldset>
</div>
diff --git a/base/tps/shared/webapps/tps/ui/tokens.html b/base/tps/shared/webapps/tps/ui/tokens.html
index 42a93cd93ff45c920e7dc22e88004a2e3a439665..ec89de958a17bba09b181e8bbe3d15b6c8287cad 100644
--- a/base/tps/shared/webapps/tps/ui/tokens.html
+++ b/base/tps/shared/webapps/tps/ui/tokens.html
@@ -105,9 +105,6 @@
<input name="userID" readonly="readonly"><br>
<label>Type</label>
<input name="type" readonly="readonly"><br>
- <label>Status</label>
- <select name="status">
- </select><br>
<label>Applet ID</label>
<input name="appletID" readonly="readonly"><br>
<label>Key Info</label>
@@ -118,6 +115,9 @@
<input name="createTimestamp" readonly="readonly"><br>
<label>Modified</label>
<input name="modifyTimestamp" readonly="readonly"><br>
+ <label>Status</label>
+ <select name="status">
+ </select><br>
</fieldset>
</div>
<div class="modal-footer">
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
index 1a3a4e96a94350356fa8ccb2ff7e9c5f0b85ff8a..6cd0c6c5787da459dd3835b7ae1ca3687998b243 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java
@@ -34,6 +34,7 @@ import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.StringUtils;
import org.dogtagpki.server.tps.TPSSubsystem;
import org.dogtagpki.server.tps.dbs.ActivityDatabase;
import org.dogtagpki.server.tps.dbs.TokenDatabase;
@@ -223,18 +224,39 @@ public class TokenService extends PKIService implements TokenResource {
return tokenData;
}
- public TokenRecord createTokenRecord(TokenData tokenData, String ipAddress, String remoteUser) throws Exception {
+ public TokenRecord createTokenRecord(TokenData tokenData) throws Exception {
TokenRecord tokenRecord = new TokenRecord();
- tokenRecord.setId(tokenData.getID());
- tokenRecord.setUserID(tokenData.getUserID());
- tokenRecord.setType(tokenData.getType());
- setTokenStatus(tokenRecord, tokenData.getStatus(), ipAddress, remoteUser);
- tokenRecord.setAppletID(tokenData.getAppletID());
- tokenRecord.setKeyInfo(tokenData.getKeyInfo());
- tokenRecord.setPolicy(tokenData.getPolicy());
- tokenRecord.setCreateTimestamp(tokenData.getCreateTimestamp());
- tokenRecord.setModifyTimestamp(tokenData.getModifyTimestamp());
+ tokenRecord.setId(tokenData.getTokenID());
+
+ String userID = tokenData.getUserID();
+ if (StringUtils.isNotEmpty(userID)) {
+ tokenRecord.setUserID(userID);
+ }
+
+ String type = tokenData.getType();
+ if (StringUtils.isNotEmpty(type)) {
+ tokenRecord.setType(type);
+ }
+
+ String appletID = tokenData.getAppletID();
+ if (StringUtils.isNotEmpty(appletID)) {
+ tokenRecord.setAppletID(appletID);
+ }
+
+ String keyInfo = tokenData.getKeyInfo();
+ if (StringUtils.isNotEmpty(keyInfo)) {
+ tokenRecord.setKeyInfo(keyInfo);
+ }
+
+ String policy = tokenData.getPolicy();
+ if (StringUtils.isNotEmpty(policy)) {
+ tokenRecord.setPolicy(policy);
+ }
+
+ // new tokens are uninitialized when created
+ tokenRecord.setStatus("uninitialized");
+ tokenRecord.setReason(null);
return tokenRecord;
}
@@ -346,12 +368,7 @@ public class TokenService extends PKIService implements TokenResource {
try {
TokenDatabase database = subsystem.getTokenDatabase();
-
- // new tokens are uninitialized when created
- tokenData.setStatus(TokenStatus.UNINITIALIZED);
-
- tokenRecord = createTokenRecord(tokenData, ipAddress, remoteUser);
- tokenRecord.setId(tokenID);
+ tokenRecord = createTokenRecord(tokenData);
database.addRecord(tokenID, tokenRecord);
subsystem.tdb.tdbActivity(ActivityDatabase.OP_ADD, tokenRecord,
ipAddress, msg, "success", remoteUser);
--
2.4.3
More information about the Pki-devel
mailing list