From dc68ed1a81dac876a4929b4b996942b1b4e4bfb2 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Tue, 6 Aug 2013 02:29:50 -0400
Subject: [PATCH] Reorganized CLI user commands.

New CLI modules have been added for each subsystem. The user commands
have been added to these subsystems while keeping the original command
for backward compatibility.

Ticket #701
---
 .../src/com/netscape/certsrv/ca/CAClient.java      |  4 ++
 .../src/com/netscape/certsrv/kra/KRAClient.java    |  4 ++
 .../src/com/netscape/certsrv/ocsp/OCSPClient.java  | 36 +++++++++++++++
 .../src/com/netscape/certsrv/tks/TKSClient.java    | 36 +++++++++++++++
 .../src/com/netscape/cmstools/cli/CACLI.java       | 54 ++++++++++++++++++++++
 .../src/com/netscape/cmstools/cli/KRACLI.java      | 54 ++++++++++++++++++++++
 .../src/com/netscape/cmstools/cli/MainCLI.java     |  4 ++
 .../src/com/netscape/cmstools/cli/OCSPCLI.java     | 54 ++++++++++++++++++++++
 .../src/com/netscape/cmstools/cli/TKSCLI.java      | 54 ++++++++++++++++++++++
 .../src/com/netscape/cmstools/user/UserCLI.java    |  7 ++-
 10 files changed, 306 insertions(+), 1 deletion(-)
 create mode 100644 base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
 create mode 100644 base/common/src/com/netscape/certsrv/tks/TKSClient.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/cli/CACLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java

diff --git a/base/common/src/com/netscape/certsrv/ca/CAClient.java b/base/common/src/com/netscape/certsrv/ca/CAClient.java
index abd54a63b4fa5899c3f9949340ed367cf99055e7..7fc6334bc30e10cb6a6ecae89e35d3d38255eaf7 100644
--- a/base/common/src/com/netscape/certsrv/ca/CAClient.java
+++ b/base/common/src/com/netscape/certsrv/ca/CAClient.java
@@ -36,6 +36,7 @@ import com.netscape.certsrv.profile.ProfileData;
 import com.netscape.certsrv.profile.ProfileDataInfos;
 import com.netscape.certsrv.profile.ProfileResource;
 import com.netscape.certsrv.request.RequestId;
+import com.netscape.certsrv.user.UserClient;
 
 public class CAClient extends SubsystemClient {
 
@@ -49,6 +50,9 @@ public class CAClient extends SubsystemClient {
     }
 
     public void init() throws URISyntaxException {
+
+        addClient(new UserClient(client, name));
+
         certRequestClient = createProxy(CertRequestResource.class);
         certClient = createProxy(CertResource.class);
         profileClient = createProxy(ProfileResource.class);
diff --git a/base/common/src/com/netscape/certsrv/kra/KRAClient.java b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
index ae91d18537dec8d3e5be7bb12992acf6f3f0fb10..40919f23ad4b31e372f12ef11228403e1491f4e6 100644
--- a/base/common/src/com/netscape/certsrv/kra/KRAClient.java
+++ b/base/common/src/com/netscape/certsrv/kra/KRAClient.java
@@ -21,6 +21,7 @@ import com.netscape.certsrv.key.KeyRequestResource;
 import com.netscape.certsrv.key.KeyResource;
 import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.system.SystemCertResource;
+import com.netscape.certsrv.user.UserClient;
 import com.netscape.cmsutil.util.Utils;
 
 public class KRAClient extends SubsystemClient {
@@ -35,6 +36,9 @@ public class KRAClient extends SubsystemClient {
     }
 
     public void init() throws URISyntaxException {
+
+        addClient(new UserClient(client, name));
+
         systemCertClient = createProxy(SystemCertResource.class);
         keyRequestClient = createProxy(KeyRequestResource.class);
         keyClient = createProxy(KeyResource.class);
diff --git a/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..fc751f8ec07b79a4207c8deff0e771607822740e
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java
@@ -0,0 +1,36 @@
+//--- 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) 2013 Red Hat, Inc.
+//All rights reserved.
+//--- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.ocsp;
+
+import java.net.URISyntaxException;
+
+import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.user.UserClient;
+
+public class OCSPClient extends SubsystemClient {
+
+    public OCSPClient(PKIClient client) throws URISyntaxException {
+        super(client, "ocsp");
+        init();
+    }
+
+    public void init() throws URISyntaxException {
+        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
new file mode 100644
index 0000000000000000000000000000000000000000..ff926cb28bed69bc43c9417f7f18d1b85f620334
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tks/TKSClient.java
@@ -0,0 +1,36 @@
+//--- 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) 2013 Red Hat, Inc.
+//All rights reserved.
+//--- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.tks;
+
+import java.net.URISyntaxException;
+
+import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.user.UserClient;
+
+public class TKSClient extends SubsystemClient {
+
+    public TKSClient(PKIClient client) throws URISyntaxException {
+        super(client, "tks");
+        init();
+    }
+
+    public void init() throws URISyntaxException {
+        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
new file mode 100644
index 0000000000000000000000000000000000000000..c97dbd7ba24a582f74321a7c556873b307a15f23
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java
@@ -0,0 +1,54 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.cli;
+
+import com.netscape.certsrv.ca.CAClient;
+import com.netscape.certsrv.client.Client;
+import com.netscape.cmstools.user.UserCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class CACLI extends SubsystemCLI {
+
+    public CAClient caClient;
+
+    public CACLI(CLI parent) {
+        super("ca", "CA management commands", parent);
+
+        addModule(new UserCLI(this));
+    }
+
+    public void init() throws Exception {
+        client = parent.getClient();
+        caClient = new CAClient(client);
+    }
+
+    public void login() {
+        caClient.login();
+    }
+
+    public void logout() {
+        caClient.logout();
+    }
+
+    public Client getClient(String name) {
+        return caClient.getClient(name);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..0249d876aa4e5bb5ba2cbc67cefd0af6caf556b7
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java
@@ -0,0 +1,54 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.cli;
+
+import com.netscape.certsrv.client.Client;
+import com.netscape.certsrv.kra.KRAClient;
+import com.netscape.cmstools.user.UserCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class KRACLI extends SubsystemCLI {
+
+    public KRAClient kraClient;
+
+    public KRACLI(CLI parent) {
+        super("kra", "KRA management commands", parent);
+
+        addModule(new UserCLI(this));
+    }
+
+    public void init() throws Exception {
+        client = parent.getClient();
+        kraClient = new KRAClient(client);
+    }
+
+    public void login() {
+        kraClient.login();
+    }
+
+    public void logout() {
+        kraClient.logout();
+    }
+
+    public Client getClient(String name) {
+        return kraClient.getClient(name);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
index 7625e2f47b34b2114a5537f46bdfbc96fe227a39..fcdb03ef48e896b441124a532108cdbf31e25e38 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
@@ -67,13 +67,17 @@ public class MainCLI extends CLI {
     public MainCLI() throws Exception {
         super("pki", "PKI command-line interface");
 
+        addModule(new CACLI(this));
         addModule(new CertCLI(this));
         addModule(new ClientCLI(this));
         addModule(new GroupCLI(this));
         addModule(new KeyCLI(this));
+        addModule(new KRACLI(this));
         addModule(new KRAConnectorCLI(this));
+        addModule(new OCSPCLI(this));
         addModule(new ProfileCLI(this));
         addModule(new SecurityDomainCLI(this));
+        addModule(new TKSCLI(this));
         addModule(new TPSCLI(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
new file mode 100644
index 0000000000000000000000000000000000000000..7a0be1c3f5c352518cf247c1d2c155536aac3acc
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java
@@ -0,0 +1,54 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.cli;
+
+import com.netscape.certsrv.client.Client;
+import com.netscape.certsrv.ocsp.OCSPClient;
+import com.netscape.cmstools.user.UserCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class OCSPCLI extends SubsystemCLI {
+
+    public OCSPClient ocspClient;
+
+    public OCSPCLI(CLI parent) {
+        super("ocsp", "OCSP management commands", parent);
+
+        addModule(new UserCLI(this));
+    }
+
+    public void init() throws Exception {
+        client = parent.getClient();
+        ocspClient = new OCSPClient(client);
+    }
+
+    public void login() {
+        ocspClient.login();
+    }
+
+    public void logout() {
+        ocspClient.logout();
+    }
+
+    public Client getClient(String name) {
+        return ocspClient.getClient(name);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..0117432fe97937551ec96f2500734a2edf7f46d8
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java
@@ -0,0 +1,54 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.cli;
+
+import com.netscape.certsrv.client.Client;
+import com.netscape.certsrv.tks.TKSClient;
+import com.netscape.cmstools.user.UserCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TKSCLI extends SubsystemCLI {
+
+    public TKSClient tksClient;
+
+    public TKSCLI(CLI parent) {
+        super("tks", "TKS management commands", parent);
+
+        addModule(new UserCLI(this));
+    }
+
+    public void init() throws Exception {
+        client = parent.getClient();
+        tksClient = new TKSClient(client);
+    }
+
+    public void login() {
+        tksClient.login();
+    }
+
+    public void logout() {
+        tksClient.logout();
+    }
+
+    public Client getClient(String name) {
+        return tksClient.getClient(name);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
index 4f6d11ac3a5be7ae88050322754986508b63a66d..6cf0a4d5289511a1cc99e75212cd12667c39913e 100644
--- a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
@@ -69,7 +69,12 @@ public class UserCLI extends CLI {
     public void execute(String[] args) throws Exception {
 
         client = parent.getClient();
-        userClient = new UserClient(client);
+        userClient = (UserClient)parent.getClient("user");
+
+        if (userClient == null) {
+            // if parent doesn't have user client then create a new one
+            userClient = new UserClient(client);
+        }
 
         if (args.length == 0) {
             printHelp();
-- 
1.8.1.4

