From c27b711db151b1957f017be4aa43f06eaf339b3d Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 25 Aug 2014 10:27:09 -0400 Subject: [PATCH] Fixed problem emptying a field in TPS UI. Previously emptying a field in TPS UI could not be saved because the change was not saved and sent to the server. The UI framework now has been fixed to save and send the empty field to the server such that the database can be updated properly. Additional parameters have been added to the tps-token-mod command to modify all editable fields. Ticket #1085 --- .../netscape/certsrv/tps/token/TokenClient.java | 4 +-- .../com/netscape/cmstools/tps/token/TokenCLI.java | 2 +- .../cmstools/tps/token/TokenModifyCLI.java | 25 ++++++++++++++--- .../src/com/netscape/cmscore/dbs/LDAPDatabase.java | 14 +++++++++- base/server/share/webapps/pki/js/pki-ui.js | 7 ++--- .../dogtagpki/server/tps/rest/TokenService.java | 31 ++++++++++++++++++---- 6 files changed, 66 insertions(+), 17 deletions(-) diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java index ba2ae3c0f605d1355b93c8891241fa5753a2454f..32a56b3d498b3c26e555fd2842e3ac35467c4781 100644 --- a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java @@ -55,8 +55,8 @@ public class TokenClient extends Client { return client.getEntity(response, TokenData.class); } - public TokenData updateToken(String tokenID, TokenData tokenData) { - Response response = resource.replaceToken(tokenID, tokenData); + public TokenData modifyToken(String tokenID, TokenData tokenData) { + Response response = resource.modifyToken(tokenID, tokenData); return client.getEntity(response, TokenData.class); } diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java index 40d1f944700b8c7dedeacf535aea0dd72f66e530..e7dd6a3081bdd89013d6d65d5b48797fb29dd55a 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java @@ -52,7 +52,7 @@ public class TokenCLI extends CLI { public static void printToken(TokenData token) { System.out.println(" Token ID: " + token.getID()); if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID()); - if (token.getType() != null) System.out.println(" Status: " + token.getType()); + if (token.getType() != null) System.out.println(" Type: " + token.getType()); if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java index 1c5602caa874ece17484d1e70f3ecd866bfdddb6..38e9fb00d4112e2f130bb2f1ac6f0fd5ee9c1664 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java @@ -42,13 +42,28 @@ public class TokenModifyCLI extends CLI { } public void printHelp() { - formatter.printHelp(getFullName() + " --user [OPTIONS...]", options); + formatter.printHelp(getFullName() + " [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); } @@ -84,8 +99,12 @@ public class TokenModifyCLI extends CLI { TokenData tokenData = new TokenData(); tokenData.setID(tokenID); tokenData.setUserID(cmd.getOptionValue("user")); + tokenData.setType(cmd.getOptionValue("type")); + tokenData.setAppletID(cmd.getOptionValue("applet")); + tokenData.setKeyInfo(cmd.getOptionValue("key-info")); + tokenData.setPolicy(cmd.getOptionValue("policy")); - tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData); + tokenData = tokenCLI.tokenClient.modifyToken(tokenID, tokenData); MainCLI.printMessage("Modified token \"" + tokenID + "\""); diff --git a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java index 650a65ea9a72bddbe50cbab734bad03b39873a19..cfe9588070c29857978817d65a6ffd52947c20d4 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java +++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java @@ -141,19 +141,31 @@ public abstract class LDAPDatabase extends Database { @Override public void updateRecord(String id, E record) throws Exception { + CMS.debug("LDAPDatabase: updateRecord(\"" + id + "\")"); + try (IDBSSession session = dbSubsystem.createSession()) { String dn = createDN(id); + CMS.debug("LDAPDatabase: dn: " + dn); + CMS.debug("LDAPDatabase: changetype: modify"); ModificationSet mods = new ModificationSet(); for (Enumeration names = record.getSerializableAttrNames(); names.hasMoreElements(); ) { String name = names.nextElement(); Object value = record.get(name); + CMS.debug("LDAPDatabase: replace: " + name); + CMS.debug("LDAPDatabase: " + name + ": " + value); + CMS.debug("LDAPDatabase: -"); mods.add(name, Modification.MOD_REPLACE, value); } - CMS.debug("LDAPDatabase: modifying " + dn); session.modify(dn, mods); + CMS.debug("LDAPDatabase: modification completed"); + + } catch (Exception e) { + CMS.debug("LDAPDatabase: modification failed"); + CMS.debug(e); + throw e; } } diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js index bf04d0121f9aeb8bace68e00f954a64ab38aaf25..7d8e6eef6c14ae1d913a191cc834d6a279e48333 100644 --- a/base/server/share/webapps/pki/js/pki-ui.js +++ b/base/server/share/webapps/pki/js/pki-ui.js @@ -1106,10 +1106,7 @@ var EntryPage = Page.extend({ var name = input.attr("name"); var value = input.val(); - if (value == "") { - delete self.entry[name]; - } else { - self.entry[name] = value; - } + // save all values including empty ones + self.entry[name] = value; } }); diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java index 898091d20b26451ed84db6405b5f4612dfe345e4..f12c39b1f6e81a43973ea4b8b296a0cabc786ed2 100644 --- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java @@ -367,36 +367,57 @@ public class TokenService extends PKIService implements TokenResource { try { TokenDatabase database = subsystem.getTokenDatabase(); + // get existing record tokenRecord = database.getRecord(tokenID); // update user ID if specified String userID = tokenData.getUserID(); if (userID != null) { - tokenRecord.setUserID(userID); + if (userID.equals("")) { // remove value if empty + tokenRecord.setUserID(null); + } else { // otherwise replace value + tokenRecord.setUserID(userID); + } } // update type if specified String type = tokenData.getType(); if (type != null) { - tokenRecord.setType(type); + if (type.equals("")) { // remove value if empty + tokenRecord.setType(null); + } else { // otherwise replace value + tokenRecord.setType(type); + } } // update applet ID if specified String appletID = tokenData.getAppletID(); if (appletID != null) { - tokenRecord.setAppletID(appletID); + if (appletID.equals("")) { // remove value if empty + tokenRecord.setAppletID(null); + } else { // otherwise replace value + tokenRecord.setAppletID(appletID); + } } // update key info if specified String keyInfo = tokenData.getKeyInfo(); if (keyInfo != null) { - tokenRecord.setKeyInfo(keyInfo); + if (keyInfo.equals("")) { // remove value if empty + tokenRecord.setKeyInfo(null); + } else { // otherwise replace value + tokenRecord.setKeyInfo(keyInfo); + } } // update policy if specified String policy = tokenData.getPolicy(); if (policy != null) { - tokenRecord.setPolicy(policy); + if (policy.equals("")) { // remove value if empty + tokenRecord.setPolicy(null); + } else { //otherwise replace value + tokenRecord.setPolicy(policy); + } } database.updateRecord(tokenID, tokenRecord); -- 1.8.4.2