summaryrefslogtreecommitdiffstats
path: root/base/tps/src
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-10-20 00:54:47 +0200
committerEndi S. Dewata <edewata@redhat.com>2016-10-21 17:17:57 +0200
commitf979c3b436e9a12e8c71ba0abab5c892d375f945 (patch)
tree4b2698b5eae632e6469611033e12971de6bf5edf /base/tps/src
parent3e05e67da87c5ce4742c77b43f2a122a968e4cc9 (diff)
downloadpki-f979c3b436e9a12e8c71ba0abab5c892d375f945.tar.gz
pki-f979c3b436e9a12e8c71ba0abab5c892d375f945.tar.xz
pki-f979c3b436e9a12e8c71ba0abab5c892d375f945.zip
Fixed TPS UI system menu.
The TPS UI has been modified to adjust the system menu based on the list of accessible components obtained during login. The TPSApplication has been modified to use TPSAccountService which returns the list of accessible components based on the following properties in the CS.cfg: * admin: target.configure.list * agent: target.agent_approve.list The AccountInfo has been changed to extend the ResourceMessage such that it can be used to pass the list of accessible components as an attribute. https://fedorahosted.org/pki/ticket/2523
Diffstat (limited to 'base/tps/src')
-rw-r--r--base/tps/src/org/dogtagpki/server/tps/TPSAccountService.java80
-rw-r--r--base/tps/src/org/dogtagpki/server/tps/rest/TPSApplication.java4
2 files changed, 82 insertions, 2 deletions
diff --git a/base/tps/src/org/dogtagpki/server/tps/TPSAccountService.java b/base/tps/src/org/dogtagpki/server/tps/TPSAccountService.java
new file mode 100644
index 000000000..73f3c5e3f
--- /dev/null
+++ b/base/tps/src/org/dogtagpki/server/tps/TPSAccountService.java
@@ -0,0 +1,80 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2016 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package org.dogtagpki.server.tps;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.apache.commons.lang.StringUtils;
+import org.dogtagpki.server.rest.AccountService;
+
+import com.netscape.certsrv.account.AccountInfo;
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.base.IConfigStore;
+import com.netscape.certsrv.base.PKIException;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TPSAccountService extends AccountService {
+
+ IConfigStore configStore = CMS.getConfigStore();
+
+ @Override
+ public AccountInfo createAccountInfo() {
+
+ AccountInfo accountInfo = super.createAccountInfo();
+
+ try {
+ // determine accessible components based on roles
+ Collection<String> components = new HashSet<String>();
+
+ Collection<String> roles = accountInfo.getRoles();
+
+ if (roles.contains("Administrators")) {
+ String values = configStore.getString("target.configure.list", "");
+ if (!StringUtils.isEmpty(values)) {
+ components.addAll(Arrays.asList(values.split(",")));
+ }
+
+ // admin always has access to general configuration and audit logging
+ components.add("Generals");
+ components.add("Audit_Logging");
+
+ }
+
+ if (roles.contains("TPS Agents")) {
+ String values = configStore.getString("target.agent_approve.list", "");
+ if (!StringUtils.isEmpty(values)) {
+ components.addAll(Arrays.asList(values.split(",")));
+ }
+ }
+
+ accountInfo.setAttribute("components", StringUtils.join(components, ","));
+
+ } catch (EBaseException e) {
+ CMS.debug(e);
+ throw new PKIException(e);
+ }
+
+ return accountInfo;
+ }
+}
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TPSApplication.java b/base/tps/src/org/dogtagpki/server/tps/rest/TPSApplication.java
index b63af8344..09f5025f7 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TPSApplication.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TPSApplication.java
@@ -23,7 +23,6 @@ import java.util.Set;
import javax.ws.rs.core.Application;
import org.dogtagpki.server.rest.ACLInterceptor;
-import org.dogtagpki.server.rest.AccountService;
import org.dogtagpki.server.rest.AuditService;
import org.dogtagpki.server.rest.AuthMethodInterceptor;
import org.dogtagpki.server.rest.GroupService;
@@ -33,6 +32,7 @@ import org.dogtagpki.server.rest.SelfTestService;
import org.dogtagpki.server.rest.SessionContextInterceptor;
import org.dogtagpki.server.rest.SystemCertService;
import org.dogtagpki.server.rest.UserService;
+import org.dogtagpki.server.tps.TPSAccountService;
import org.dogtagpki.server.tps.config.ConfigService;
/**
@@ -46,7 +46,7 @@ public class TPSApplication extends Application {
public TPSApplication() {
// account
- classes.add(AccountService.class);
+ classes.add(TPSAccountService.class);
// audit
classes.add(AuditService.class);