From 1e25c269bcfd4b4613e16664fa9ea045f19a6635 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 22 Aug 2013 01:48:23 -0400
Subject: [PATCH] Added subsystem group commands.

The group client and CLI has been added into each subsystem (e.g. ca-group-*)
while keeping the original command for backward compatibility.

Ticket #652
---
 base/common/src/com/netscape/certsrv/ca/CAClient.java         | 2 ++
 base/common/src/com/netscape/certsrv/kra/KRAClient.java       | 2 ++
 base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java     | 2 ++
 base/common/src/com/netscape/certsrv/tks/TKSClient.java       | 2 ++
 base/common/src/com/netscape/certsrv/tps/TPSClient.java       | 2 ++
 base/java-tools/src/com/netscape/cmstools/cli/CACLI.java      | 2 ++
 base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java     | 2 ++
 base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java    | 2 ++
 base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java     | 2 ++
 base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java     | 2 ++
 base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java | 7 ++++++-
 base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java | 5 ++---
 12 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/ca/CAClient.java b/base/common/src/com/netscape/certsrv/ca/CAClient.java
index 7fc6334bc30e10cb6a6ecae89e35d3d38255eaf7..a58d0236d6cab5823eed73d658e1326ba26ceab0 100644
--- a/base/common/src/com/netscape/certsrv/ca/CAClient.java
+++ b/base/common/src/com/netscape/certsrv/ca/CAClient.java
@@ -32,6 +32,7 @@ import com.netscape.certsrv.cert.CertSearchRequest;
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.client.SubsystemClient;
 import com.netscape.certsrv.dbs.certdb.CertId;
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.profile.ProfileData;
 import com.netscape.certsrv.profile.ProfileDataInfos;
 import com.netscape.certsrv.profile.ProfileResource;
@@ -51,6 +52,7 @@ public class CAClient extends SubsystemClient {
 
     public void init() throws URISyntaxException {
 
+        addClient(new GroupClient(client, name));
         addClient(new UserClient(client, name));
 
         certRequestClient = createProxy(CertRequestResource.class);
diff --git a/base/common/src/com/netscape/certsrv/kra/KRAClient.java b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
index 40919f23ad4b31e372f12ef11228403e1491f4e6..3bebb150e1991afd09c0aae9396c1accf0e50213 100644
--- a/base/common/src/com/netscape/certsrv/kra/KRAClient.java
+++ b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
@@ -10,6 +10,7 @@ import com.netscape.certsrv.cert.CertData;
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.client.SubsystemClient;
 import com.netscape.certsrv.dbs.keydb.KeyId;
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.key.KeyArchivalRequest;
 import com.netscape.certsrv.key.KeyData;
 import com.netscape.certsrv.key.KeyDataInfo;
@@ -37,6 +38,7 @@ public class KRAClient extends SubsystemClient {
 
     public void init() throws URISyntaxException {
 
+        addClient(new GroupClient(client, name));
         addClient(new UserClient(client, name));
 
         systemCertClient = createProxy(SystemCertResource.class);
diff --git a/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
index fc751f8ec07b79a4207c8deff0e771607822740e..ed65e8b001c4c70a4d0d4cc06b031c3b9a28bc34 100644
--- a/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
+++ b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.user.UserClient;
 
 public class OCSPClient extends SubsystemClient {
@@ -31,6 +32,7 @@ public class OCSPClient extends SubsystemClient {
     }
 
     public void init() throws URISyntaxException {
+        addClient(new GroupClient(client, name));
         addClient(new UserClient(client, name));
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tks/TKSClient.java b/base/common/src/com/netscape/certsrv/tks/TKSClient.java
index ff926cb28bed69bc43c9417f7f18d1b85f620334..baecf8ddbae1cda183d49e8d7a6ca2db5208e131 100644
--- a/base/common/src/com/netscape/certsrv/tks/TKSClient.java
+++ b/base/common/src/com/netscape/certsrv/tks/TKSClient.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.user.UserClient;
 
 public class TKSClient extends SubsystemClient {
@@ -31,6 +32,7 @@ public class TKSClient extends SubsystemClient {
     }
 
     public void init() throws URISyntaxException {
+        addClient(new GroupClient(client, name));
         addClient(new UserClient(client, name));
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 263b92b3ad907303648f5af90d408d5eeb092edb..0726eb192d27e26143b88604358977bd4728b2c2 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.group.GroupClient;
 import com.netscape.certsrv.logging.ActivityClient;
 import com.netscape.certsrv.token.TokenClient;
 import com.netscape.certsrv.user.UserClient;
@@ -37,6 +38,7 @@ public class TPSClient extends SubsystemClient {
 
     public void init() throws URISyntaxException {
         addClient(new ActivityClient(client, name));
+        addClient(new GroupClient(client, name));
         addClient(new TokenClient(client, name));
         addClient(new UserClient(client, name));
     }
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java
index c97dbd7ba24a582f74321a7c556873b307a15f23..ce253d884c597d1f56835a1e537cf485cc7becd4 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
 
 import com.netscape.certsrv.ca.CAClient;
 import com.netscape.certsrv.client.Client;
+import com.netscape.cmstools.group.GroupCLI;
 import com.netscape.cmstools.user.UserCLI;
 
 /**
@@ -32,6 +33,7 @@ public class CACLI extends SubsystemCLI {
     public CACLI(CLI parent) {
         super("ca", "CA management commands", parent);
 
+        addModule(new GroupCLI(this));
         addModule(new UserCLI(this));
     }
 
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
index 0249d876aa4e5bb5ba2cbc67cefd0af6caf556b7..ecc72688a21cacdeb71ee50f2a123c8b0adcf73e 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
 
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.kra.KRAClient;
+import com.netscape.cmstools.group.GroupCLI;
 import com.netscape.cmstools.user.UserCLI;
 
 /**
@@ -32,6 +33,7 @@ public class KRACLI extends SubsystemCLI {
     public KRACLI(CLI parent) {
         super("kra", "KRA management commands", parent);
 
+        addModule(new GroupCLI(this));
         addModule(new UserCLI(this));
     }
 
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java
index 7a0be1c3f5c352518cf247c1d2c155536aac3acc..e28b97cdb16afc501e492b74246b37efd1dd3d66 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
 
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.ocsp.OCSPClient;
+import com.netscape.cmstools.group.GroupCLI;
 import com.netscape.cmstools.user.UserCLI;
 
 /**
@@ -32,6 +33,7 @@ public class OCSPCLI extends SubsystemCLI {
     public OCSPCLI(CLI parent) {
         super("ocsp", "OCSP management commands", parent);
 
+        addModule(new GroupCLI(this));
         addModule(new UserCLI(this));
     }
 
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java
index 0117432fe97937551ec96f2500734a2edf7f46d8..df7050189b541574954f0e797cdd451db956fecc 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
 
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.tks.TKSClient;
+import com.netscape.cmstools.group.GroupCLI;
 import com.netscape.cmstools.user.UserCLI;
 
 /**
@@ -32,6 +33,7 @@ public class TKSCLI extends SubsystemCLI {
     public TKSCLI(CLI parent) {
         super("tks", "TKS management commands", parent);
 
+        addModule(new GroupCLI(this));
         addModule(new UserCLI(this));
     }
 
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
index 6cd417312ad730153e97bc54fae3fd4dd0dca103..00f0131cb0652235170ca7c2c29573bf27cbd485 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
 
 import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.tps.TPSClient;
+import com.netscape.cmstools.group.GroupCLI;
 import com.netscape.cmstools.logging.ActivityCLI;
 import com.netscape.cmstools.token.TokenCLI;
 import com.netscape.cmstools.user.UserCLI;
@@ -35,6 +36,7 @@ public class TPSCLI extends SubsystemCLI {
         super("tps", "TPS management commands", mainCLI);
 
         addModule(new ActivityCLI(this));
+        addModule(new GroupCLI(this));
         addModule(new TokenCLI(this));
         addModule(new UserCLI(this));
     }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
index d691c432b569de11c03470dde9e816633b90f435..f14d30ebc10d8365c9b0c779de0bad6f972eeb93 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java
@@ -63,7 +63,12 @@ public class GroupCLI extends CLI {
     public void execute(String[] args) throws Exception {
 
         client = parent.getClient();
-        groupClient = new GroupClient(client);
+        groupClient = (GroupClient)parent.getClient("group");
+
+        if (groupClient == null) {
+            // if parent doesn't have group client then create a new one
+            groupClient = new GroupClient(client);
+        }
 
         if (args.length == 0) {
             printHelp();
diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java
index 4584a5ef7d99d201780319566498569d41a77c0f..14e54af3d42c553deaa4d2526451c7ccdb36087c 100644
--- a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java
@@ -25,7 +25,6 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
 import com.netscape.certsrv.token.TokenClient;
 import com.netscape.certsrv.token.TokenData;
 import com.netscape.cmstools.cli.CLI;
-import com.netscape.cmstools.cli.SubsystemCLI;
 
 /**
  * @author Endi S. Dewata
@@ -34,8 +33,8 @@ public class TokenCLI extends CLI {
 
     public TokenClient tokenClient;
 
-    public TokenCLI(SubsystemCLI subsystemCLI) {
-        super("token", "Token management commands", subsystemCLI);
+    public TokenCLI(CLI parent) {
+        super("token", "Token management commands", parent);
 
         addModule(new TokenAddCLI(this));
         addModule(new TokenFindCLI(this));
-- 
1.8.1.4

