From 9bd94a0a54793a0720b803846ce2291e5064c2ae Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 3 Feb 2016 19:20:31 +0100 Subject: Added resource bundle for token state labels. The labels for token states and the transitions are now stored in token-states.properties. The default file will be stored in the /usr/share/pki/tps/conf, but it can be overriden by copying and customizing the file into /tps/conf. When the UI retrieves the token data the labels for the current state and the valid transitions will be loaded from the file and returned to the UI. The UI will show the transition labels in the dropdown list for changing token status. https://fedorahosted.org/pki/ticket/1289 https://fedorahosted.org/pki/ticket/1291 --- .../com/netscape/certsrv/tps/token/TokenData.java | 23 ++++++++---- .../com/netscape/cmstools/tps/token/TokenCLI.java | 20 +++++++++- .../com/netscape/cms/servlet/base/PKIService.java | 41 +++++++++++++++++++++ base/server/share/webapps/pki/js/pki-ui.js | 22 +++++++++-- base/tps/shared/conf/token-states.properties | 21 +++++++++++ base/tps/shared/webapps/tps/js/token.js | 43 +++++++++++----------- base/tps/shared/webapps/tps/ui/token.html | 2 +- base/tps/shared/webapps/tps/ui/tokens.html | 2 +- .../dogtagpki/server/tps/rest/TokenService.java | 27 ++++++++++++-- 9 files changed, 162 insertions(+), 39 deletions(-) create mode 100644 base/tps/shared/conf/token-states.properties (limited to 'base') diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenData.java b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java index 9947bf658..a4bddcad8 100644 --- a/base/common/src/com/netscape/certsrv/tps/token/TokenData.java +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java @@ -51,13 +51,18 @@ public class TokenData { } } + public static class TokenStatusData { + public TokenStatus name; + public String label; + } + String id; String tokenID; String userID; String type; - TokenStatus status; - Collection nextStates; + TokenStatusData status; + Collection nextStates; String appletID; String keyInfo; @@ -104,20 +109,20 @@ public class TokenData { } @XmlElement(name="Status") - public TokenStatus getStatus() { + public TokenStatusData getStatus() { return status; } - public void setStatus(TokenStatus status) { + public void setStatus(TokenStatusData status) { this.status = status; } @XmlElement(name="NextStates") - public Collection getNextStates() { + public Collection getNextStates() { return nextStates; } - public void setNextStates(Collection nextStates) { + public void setNextStates(Collection nextStates) { this.nextStates = nextStates; } @@ -288,7 +293,11 @@ public class TokenData { before.setID("token1"); before.setUserID("user1"); before.setType("userKey"); - before.setStatus(TokenStatus.ACTIVE); + + TokenStatusData statusData = new TokenStatusData(); + statusData.name = TokenStatus.ACTIVE; + before.setStatus(statusData); + before.setAppletID("APPLET1234"); before.setKeyInfo("key info"); before.setPolicy("FORCE_FORMAT=YES"); 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 328490a49..77ca40bd1 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 @@ -18,11 +18,16 @@ package com.netscape.cmstools.tps.token; +import java.util.ArrayList; +import java.util.Collection; + import org.apache.commons.lang.StringUtils; import org.jboss.resteasy.plugins.providers.atom.Link; import com.netscape.certsrv.tps.token.TokenClient; import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.certsrv.tps.token.TokenData.TokenStatusData; +import com.netscape.certsrv.tps.token.TokenStatus; import com.netscape.cmstools.cli.CLI; /** @@ -54,8 +59,19 @@ public class TokenCLI extends CLI { 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(" Type: " + token.getType()); - if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); - if (token.getNextStates() != null) System.out.println(" Next States: " + StringUtils.join(token.getNextStates(), ", ")); + + TokenStatusData status = token.getStatus(); + if (status != null) System.out.println(" Status: " + status.name); + + Collection nextStates = token.getNextStates(); + if (nextStates != null) { + Collection names = new ArrayList(); + for (TokenStatusData nextState : nextStates) { + names.add(nextState.name); + } + System.out.println(" Next States: " + StringUtils.join(names, ", ")); + } + if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); if (token.getPolicy() != null) System.out.println(" Policy: " + token.getPolicy()); diff --git a/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java b/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java index fe77fd567..d2e55b5a3 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java +++ b/base/server/cms/src/com/netscape/cms/servlet/base/PKIService.java @@ -17,14 +17,19 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cms.servlet.base; +import java.io.File; import java.lang.reflect.Method; import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.ResourceBundle; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.FormParam; import javax.ws.rs.core.CacheControl; @@ -77,10 +82,46 @@ public class PKIService { @Context protected HttpServletRequest servletRequest; + @Context + protected ServletContext servletContext; public ILogger logger = CMS.getLogger(); public IAuditor auditor = CMS.getAuditor(); + public String getInstanceDir() { + return System.getProperty("catalina.base"); + } + + public String getSubsystemName() { + // get web application path: / + String path = servletContext.getContextPath(); + + // get subsystem name by removing the / prefix from the path + return path.startsWith("/") ? path.substring(1) : path; + } + + public String getSubsystemConfDir() { + return getInstanceDir() + File.separator + getSubsystemName() + File.separator + "conf"; + } + + public String getSharedSubsystemConfDir() { + return File.separator + "usr" + File.separator + "share" + File.separator + "pki" + + File.separator + getSubsystemName() + File.separator + "conf"; + } + + public ResourceBundle getResourceBundle(String name) throws Exception { + + // Look in //conf first, + // then fallback to /usr/share/pki//conf. + URL[] urls = { + new File(getSubsystemConfDir()).toURI().toURL(), + new File(getSharedSubsystemConfDir()).toURI().toURL() + }; + + ClassLoader loader = new URLClassLoader(urls); + return ResourceBundle.getBundle(name, servletRequest.getLocale(), loader); + } + public static MediaType resolveFormat(MediaType format) { if (format == null) return null; diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js index c6e326a0c..0729895aa 100644 --- a/base/server/share/webapps/pki/js/pki-ui.js +++ b/base/server/share/webapps/pki/js/pki-ui.js @@ -456,8 +456,24 @@ var TableItem = Backbone.View.extend({ break; } - var name = RegExp.$1; - var value = self.get(name); + // get attribute name + var fullName = RegExp.$1; + + // split attribute names + var names = fullName.split("."); + + // get the value from the leaf object + var value; + for (var i=0; i', { - text: TokenStatus[status], - value: status, + text: status.label, + value: status.name, selected: true }).appendTo(select); - var nextStates = self.entry["nextStates"]; + var nextStates = self.entry.nextStates; _.each(nextStates, function(nextState) { $('