[Pki-devel] [PATCH] 677 Fixed token add operation.
Endi Sukma Dewata
edewata at redhat.com
Thu Feb 4 20:50:30 UTC 2016
On 2/3/2016 10:38 PM, Endi Sukma Dewata wrote:
> 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
New patch attached. Now the add operation will only accept token ID,
user ID, and policy attributes to match the edit operation (ticket #1687).
--
Endi S. Dewata
-------------- next part --------------
>From cada3602a953e690330a0707b73ca12f941f9542 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 TPS UI and CLI have been modified to accept only token ID,
and optionally user ID and policy attributes when adding a token.
https://fedorahosted.org/pki/ticket/1477
https://fedorahosted.org/pki/ticket/1687
---
.../netscape/cmstools/tps/token/TokenAddCLI.java | 14 +++++++--
base/tps/shared/webapps/tps/js/token.js | 25 +++++++++++++++
base/tps/shared/webapps/tps/ui/token.html | 22 ++++++-------
base/tps/shared/webapps/tps/ui/tokens.html | 6 ++--
.../dogtagpki/server/tps/rest/TokenService.java | 36 ++++++++++------------
5 files changed, 66 insertions(+), 37 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..1615846d6b6ae91c74cb87dda2e48667c24ff811 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,16 @@ 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, "policy", true, "Policy");
+ option.setArgName("Policy");
options.addOption(option);
}
@@ -83,7 +86,12 @@ 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 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 1a4267f72de1c378522dc16ec18f3c90414f1dd7..b4d5a717beb7e7c49e2641044881abaaa7c49b32 100644
--- a/base/tps/shared/webapps/tps/js/token.js
+++ b/base/tps/shared/webapps/tps/js/token.js
@@ -201,8 +201,33 @@ var TokenPage = EntryPage.extend({
if (self.mode == "add") {
self.changeStatusAction.hide();
+ self.$("label[name='type']").hide();
+ self.$("input[name='type']").hide();
+ self.$("label[name='appletID']").hide();
+ self.$("input[name='appletID']").hide();
+ self.$("label[name='keyInfo']").hide();
+ self.$("input[name='keyInfo']").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='type']").show();
+ self.$("input[name='type']").show();
+ self.$("label[name='appletID']").show();
+ self.$("input[name='appletID']").show();
+ self.$("label[name='keyInfo']").show();
+ self.$("input[name='keyInfo']").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..aaf18141424d972eb3312eec5819a8bc06e8420c 100644
--- a/base/tps/shared/webapps/tps/ui/token.html
+++ b/base/tps/shared/webapps/tps/ui/token.html
@@ -43,24 +43,24 @@
<div name="token" class="pki-fields">
<fieldset>
- <label>Token ID</label>
+ <label name="tokenID">Token ID</label>
<input name="tokenID" readonly="readonly"><br>
- <label>User ID</label>
+ <label name="userID">User ID</label>
<input name="userID" readonly="readonly"><br>
- <label>Type</label>
+ <label name="policy">Policy</label>
+ <input name="policy" readonly="readonly"><br>
+ <label name="type">Type</label>
<input name="type" readonly="readonly"><br>
- <label>Status</label>
- <input name="statusLabel" readonly="readonly"><br>
- <label>Applet ID</label>
+ <label name="appletID">Applet ID</label>
<input name="appletID" readonly="readonly"><br>
- <label>Key Info</label>
+ <label name="keyInfo">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..247aa911c809454891ae3f8a6dc358a965b96008 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,22 +224,6 @@ public class TokenService extends PKIService implements TokenResource {
return tokenData;
}
- public TokenRecord createTokenRecord(TokenData tokenData, String ipAddress, String remoteUser) 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());
-
- return tokenRecord;
- }
-
@Override
public Response findTokens(String filter, Integer start, Integer size) {
@@ -347,11 +332,22 @@ 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 = new TokenRecord();
tokenRecord.setId(tokenID);
+
+ String userID = tokenData.getUserID();
+ if (StringUtils.isNotEmpty(userID)) {
+ tokenRecord.setUserID(userID);
+ }
+
+ String policy = tokenData.getPolicy();
+ if (StringUtils.isNotEmpty(policy)) {
+ tokenRecord.setPolicy(policy);
+ }
+
+ // new tokens are uninitialized when created
+ tokenRecord.setStatus("uninitialized");
+
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