diff options
author | Endi S. Dewata <edewata@redhat.com> | 2014-08-25 10:27:09 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2014-08-26 11:04:02 -0400 |
commit | 8e464b6ba5d83d7915978db5841967f20672dfd0 (patch) | |
tree | 36662b6cec8b52bbcab68abc8612574924161514 | |
parent | 20b9d956aab21a5a2a61162e6c88fbee5828a9e9 (diff) | |
download | pki-8e464b6ba5d83d7915978db5841967f20672dfd0.tar.gz pki-8e464b6ba5d83d7915978db5841967f20672dfd0.tar.xz pki-8e464b6ba5d83d7915978db5841967f20672dfd0.zip |
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
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 ba2ae3c0f..32a56b3d4 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 40d1f9447..e7dd6a308 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 1c5602caa..38e9fb00d 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() + " <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); } @@ -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 650a65ea9..cfe958807 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<E extends IDBObj> extends Database<E> { @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<String> 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 bf04d0121..7d8e6eef6 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 898091d20..f12c39b1f 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); |