From 116632dbda6d15ae29e5b729d132668094f1beb7 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 1 Aug 2013 04:17:07 -0400
Subject: [PATCH] Refactored client framework.

A new Client class was added as a base for all client classes. The
SubsystemClient was added as a base for all subsystem clients. It also
provides methods to authenticate against the subsystem.

Ticket #701
---
 .../netscape/certsrv/account/AccountClient.java    | 25 ++++-----
 .../src/com/netscape/certsrv/ca/CAClient.java      |  6 +--
 .../src/com/netscape/certsrv/cert/CertClient.java  |  6 +--
 .../SystemConfigClient.java => client/Client.java} | 35 ++++--------
 .../src/com/netscape/certsrv/client/PKIClient.java | 35 +++++++++++-
 .../com/netscape/certsrv/client/PKIConnection.java |  3 +-
 .../netscape/certsrv/client/SubsystemClient.java   | 62 ++++++++++++++++++++++
 .../com/netscape/certsrv/group/GroupClient.java    |  6 +--
 .../src/com/netscape/certsrv/key/KeyClient.java    |  6 +--
 .../src/com/netscape/certsrv/kra/DRMClient.java    |  6 +--
 .../netscape/certsrv/profile/ProfileClient.java    |  7 +--
 .../certsrv/system/KRAConnectorClient.java         |  6 +--
 .../certsrv/system/SecurityDomainClient.java       |  6 +--
 .../certsrv/system/SystemConfigClient.java         |  6 +--
 .../com/netscape/certsrv/token/TokenClient.java    | 15 +++---
 .../src/com/netscape/certsrv/tps/TPSClient.java    | 16 ++----
 .../src/com/netscape/certsrv/user/UserClient.java  |  6 +--
 17 files changed, 162 insertions(+), 90 deletions(-)
 copy base/common/src/com/netscape/certsrv/{system/SystemConfigClient.java => client/Client.java} (50%)
 create mode 100644 base/common/src/com/netscape/certsrv/client/SubsystemClient.java

diff --git a/base/common/src/com/netscape/certsrv/account/AccountClient.java b/base/common/src/com/netscape/certsrv/account/AccountClient.java
index 36adcf57a1aa0c6cb2234384e74b3a46850df26a..5fb3df9e21250ace25671511abd117fbf1d00cd9 100644
--- a/base/common/src/com/netscape/certsrv/account/AccountClient.java
+++ b/base/common/src/com/netscape/certsrv/account/AccountClient.java
@@ -19,35 +19,36 @@ package com.netscape.certsrv.account;
 
 import java.net.URISyntaxException;
 
-import com.netscape.certsrv.client.ClientConfig;
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.PKIClient;
 
 /**
  * @author Endi S. Dewata
  */
-public class AccountClient {
+public class AccountClient extends Client {
 
-    public PKIClient client;
     public AccountResource resource;
-
-    public AccountClient(ClientConfig config) throws URISyntaxException {
-        this(new PKIClient(config));
-    }
+    public boolean loggedIn;
 
     public AccountClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
-        init();
+        this(client, null);
     }
 
-    public void init() throws URISyntaxException {
-        resource = client.createProxy(AccountResource.class);
+    public AccountClient(PKIClient client, String subsystem) throws URISyntaxException {
+        super(client, "account");
+
+        resource = client.createProxy(subsystem, AccountResource.class);
     }
 
     public void login() {
         resource.login();
+        loggedIn = true;
     }
 
     public void logout() {
-        resource.logout();
+        if (loggedIn) {
+            resource.logout();
+            loggedIn = false;
+        }
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/ca/CAClient.java b/base/common/src/com/netscape/certsrv/ca/CAClient.java
index 906caada79d4c4f96387619e57185204a47ec9bd..655b13ab1c7779fefe11abb381eebe58bab01bff 100644
--- a/base/common/src/com/netscape/certsrv/ca/CAClient.java
+++ b/base/common/src/com/netscape/certsrv/ca/CAClient.java
@@ -31,15 +31,15 @@ import com.netscape.certsrv.cert.CertReviewResponse;
 import com.netscape.certsrv.cert.CertSearchRequest;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.SubsystemClient;
 import com.netscape.certsrv.dbs.certdb.CertId;
 import com.netscape.certsrv.profile.ProfileData;
 import com.netscape.certsrv.profile.ProfileDataInfos;
 import com.netscape.certsrv.profile.ProfileResource;
 import com.netscape.certsrv.request.RequestId;
 
-public class CAClient {
+public class CAClient extends SubsystemClient {
 
-    private PKIClient client;
     private CertResource certClient;
     private CertRequestResource certRequestClient;
     private ProfileResource profileClient;
@@ -49,7 +49,7 @@ public class CAClient {
     }
 
     public CAClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "ca");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/cert/CertClient.java b/base/common/src/com/netscape/certsrv/cert/CertClient.java
index 42c78eb2c09400ec3edad8a41b1ab3037741219c..891bf28b172ea4847dafce31684ab23d68130d29 100644
--- a/base/common/src/com/netscape/certsrv/cert/CertClient.java
+++ b/base/common/src/com/netscape/certsrv/cert/CertClient.java
@@ -19,6 +19,7 @@ package com.netscape.certsrv.cert;
 
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.dbs.certdb.CertId;
@@ -27,9 +28,8 @@ import com.netscape.certsrv.request.RequestId;
 /**
  * @author Endi S. Dewata
  */
-public class CertClient {
+public class CertClient extends Client {
 
-    public PKIClient client;
     public CertResource certClient;
     public CertRequestResource certRequestResource;
 
@@ -38,7 +38,7 @@ public class CertClient {
     }
 
     public CertClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "cert");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java b/base/common/src/com/netscape/certsrv/client/Client.java
similarity index 50%
copy from base/common/src/com/netscape/certsrv/system/SystemConfigClient.java
copy to base/common/src/com/netscape/certsrv/client/Client.java
index aa4e6842e53a3a96e845354a8b799a10175d9f0a..0fec0c5962af969eade1c28f2cadcfc4f0da45fb 100644
--- a/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java
+++ b/base/common/src/com/netscape/certsrv/client/Client.java
@@ -12,40 +12,25 @@
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 //
-// (C) 2012 Red Hat, Inc.
+// (C) 2013 Red Hat, Inc.
 // All rights reserved.
 // --- END COPYRIGHT BLOCK ---
-package com.netscape.certsrv.system;
-
-import java.net.URISyntaxException;
-
-import com.netscape.certsrv.client.ClientConfig;
-import com.netscape.certsrv.client.PKIClient;
-
+package com.netscape.certsrv.client;
 
 /**
- * @author alee
- *
+ * @author Endi S. Dewata
  */
-public class SystemConfigClient {
+public class Client {
 
-    private PKIClient client;
-    private SystemConfigResource configClient;
+    public PKIClient client;
+    public String name;
 
-    public SystemConfigClient(ClientConfig config) throws URISyntaxException {
-        this(new PKIClient(config));
-    }
-
-    public SystemConfigClient(PKIClient client) throws URISyntaxException {
+    public Client(PKIClient client, String name) {
         this.client = client;
-        init();
+        this.name = name;
     }
 
-    public void init() throws URISyntaxException {
-        configClient = client.createProxy(SystemConfigResource.class);
-    }
-
-    public ConfigurationResponse configure(ConfigurationRequest data) {
-        return configClient.configure(data);
+    public String getName() {
+        return name;
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/client/PKIClient.java b/base/common/src/com/netscape/certsrv/client/PKIClient.java
index 3b316ceb3355cd6d653143b29ef78f4d16d1f6ef..cc441fd1a5136328cf312b4fed4fbe91c8721f5a 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIClient.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIClient.java
@@ -2,6 +2,7 @@ package com.netscape.certsrv.client;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.cert.CertificateEncodingException;
@@ -27,6 +28,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
+import com.netscape.certsrv.base.PKIException;
 import com.netscape.cmsutil.util.Utils;
 
 
@@ -35,7 +37,7 @@ public class PKIClient {
     public ClientConfig config;
     public PKIConnection connection;
 
-    File certDatabase;
+    public File certDatabase;
 
     public boolean verbose;
 
@@ -46,7 +48,36 @@ public class PKIClient {
     }
 
     public <T> T createProxy(Class<T> clazz) throws URISyntaxException {
-        return connection.createProxy(clazz);
+        return createProxy(null, clazz);
+    }
+
+    public <T> T createProxy(String subsystem, Class<T> clazz) throws URISyntaxException {
+
+        URI serverURI = config.getServerURI();
+
+        String path;
+        if (subsystem != null) {
+            // overwrite the path with the specified subsystem
+            path = "/" + subsystem;
+
+        } else if (serverURI.getPath().length() > 2) {
+            // use the subsystem specified in server URI
+            path = serverURI.getPath();
+
+        } else {
+            throw new PKIException("Missing subsystem name.");
+        }
+
+        URI resourceURI = new URI(
+            serverURI.getScheme(),
+            serverURI.getUserInfo(),
+            serverURI.getHost(),
+            serverURI.getPort(),
+            path + "/rest",
+            serverURI.getQuery(),
+            serverURI.getFragment());
+
+        return connection.createProxy(resourceURI, clazz);
     }
 
     public <T> T getEntity(ClientResponse<T> response) {
diff --git a/base/common/src/com/netscape/certsrv/client/PKIConnection.java b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
index 397e7ca91f288a3ad01edb97d532da9b2c597739..d057deba0c674e98de0a99b12addf64eaf117f74 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIConnection.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
@@ -509,8 +509,7 @@ public class PKIConnection {
 
     }
 
-    public <T> T createProxy(Class<T> clazz) throws URISyntaxException {
-        URI uri = new URI(config.getServerURI()+"/rest");
+    public <T> T createProxy(URI uri, Class<T> clazz) throws URISyntaxException {
         return ProxyFactory.create(clazz, uri, executor, providerFactory);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/client/SubsystemClient.java b/base/common/src/com/netscape/certsrv/client/SubsystemClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..4adb661a8c76ad4c5a5b8202bbe228aea5aec0b9
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/client/SubsystemClient.java
@@ -0,0 +1,62 @@
+// --- 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.client;
+
+import java.net.URISyntaxException;
+import java.util.LinkedHashMap;
+
+import com.netscape.certsrv.account.AccountClient;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+public class SubsystemClient extends Client {
+
+    public AccountClient accountClient;
+
+    public LinkedHashMap<String, Client> clients = new LinkedHashMap<String, Client>();
+
+    public SubsystemClient(PKIClient client, String name) throws URISyntaxException {
+        super(client, name);
+
+        accountClient = new AccountClient(client, name);
+    }
+
+    public void addClient(Client client) {
+        clients.put(client.getName(), client);
+    }
+
+    public Client getClient(String name) {
+        return clients.get(name);
+    }
+
+    /**
+     * Log in to the subsystem.
+     */
+    public void login() {
+        accountClient.login();
+    }
+
+    /**
+     * Log out from the subsystem.
+     */
+    public void logout() {
+        accountClient.logout();
+    }
+}
diff --git a/base/common/src/com/netscape/certsrv/group/GroupClient.java b/base/common/src/com/netscape/certsrv/group/GroupClient.java
index ac666fae693e6d75bd73f39bcc4dbcc8b563f290..5ca687adea5c56cf829a30723cebaa89c038a658 100644
--- a/base/common/src/com/netscape/certsrv/group/GroupClient.java
+++ b/base/common/src/com/netscape/certsrv/group/GroupClient.java
@@ -21,15 +21,15 @@ import java.net.URISyntaxException;
 
 import org.jboss.resteasy.client.ClientResponse;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
 /**
  * @author Endi S. Dewata
  */
-public class GroupClient {
+public class GroupClient extends Client {
 
-    public PKIClient client;
     public GroupResource groupClient;
     public GroupMemberResource groupMemberClient;
 
@@ -38,7 +38,7 @@ public class GroupClient {
     }
 
     public GroupClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "group");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/key/KeyClient.java b/base/common/src/com/netscape/certsrv/key/KeyClient.java
index 7deef0472eee728618f036cbf008924fce8f7604..e31d3c96ae90591eb229b4d0db0df5abf93bf3c7 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyClient.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyClient.java
@@ -19,6 +19,7 @@ package com.netscape.certsrv.key;
 
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.request.RequestId;
@@ -26,9 +27,8 @@ import com.netscape.certsrv.request.RequestId;
 /**
  * @author Endi S. Dewata
  */
-public class KeyClient {
+public class KeyClient extends Client {
 
-    public PKIClient client;
     public KeyResource keyClient;
     public KeyRequestResource keyRequestClient;
 
@@ -37,7 +37,7 @@ public class KeyClient {
     }
 
     public KeyClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "key");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/kra/DRMClient.java b/base/common/src/com/netscape/certsrv/kra/DRMClient.java
index 75e85a2aee57cbed9f5db548b9136cafc177cc4a..9e8e20deeef31d2656396ab0778c9e3461f9c20a 100644
--- a/base/common/src/com/netscape/certsrv/kra/DRMClient.java
+++ b/base/common/src/com/netscape/certsrv/kra/DRMClient.java
@@ -9,6 +9,7 @@ import org.jboss.resteasy.client.ClientResponse;
 import com.netscape.certsrv.cert.CertData;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.SubsystemClient;
 import com.netscape.certsrv.dbs.keydb.KeyId;
 import com.netscape.certsrv.key.KeyArchivalRequest;
 import com.netscape.certsrv.key.KeyData;
@@ -23,9 +24,8 @@ import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.system.SystemCertResource;
 import com.netscape.cmsutil.util.Utils;
 
-public class DRMClient {
+public class DRMClient extends SubsystemClient {
 
-    private PKIClient client;
     private KeyResource keyClient;
     private KeyRequestResource keyRequestClient;
     private SystemCertResource systemCertClient;
@@ -35,7 +35,7 @@ public class DRMClient {
     }
 
     public DRMClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "kra");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java
index 12b54cc60a1954ed8d88cf1b5399dd8e16a56e57..c1e5e42bae91f1974a4f2b7cbf5466dd9020ef32 100644
--- a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java
+++ b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java
@@ -19,14 +19,15 @@ package com.netscape.certsrv.profile;
 
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
 /**
  * @author Ade Lee
  */
-public class ProfileClient {
-    public PKIClient client;
+public class ProfileClient extends Client {
+
     public ProfileResource profileClient;
 
     public ProfileClient(ClientConfig config) throws URISyntaxException {
@@ -34,7 +35,7 @@ public class ProfileClient {
     }
 
     public ProfileClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "profile");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/system/KRAConnectorClient.java b/base/common/src/com/netscape/certsrv/system/KRAConnectorClient.java
index ea71cf645010e1449c26f4f57913ea6bf763a825..72eb40dc8ce15254fd1c63292bb3b72d68f50e20 100644
--- a/base/common/src/com/netscape/certsrv/system/KRAConnectorClient.java
+++ b/base/common/src/com/netscape/certsrv/system/KRAConnectorClient.java
@@ -19,15 +19,15 @@
 package com.netscape.certsrv.system;
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
 /**
  * @author Ade Lee
  */
-public class KRAConnectorClient {
+public class KRAConnectorClient extends Client {
 
-    public PKIClient client;
     public KRAConnectorResource kraConnectorClient;
 
     public KRAConnectorClient(ClientConfig config) throws URISyntaxException {
@@ -35,7 +35,7 @@ public class KRAConnectorClient {
     }
 
     public KRAConnectorClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "kraconnector");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/system/SecurityDomainClient.java b/base/common/src/com/netscape/certsrv/system/SecurityDomainClient.java
index 490f837dabe2dc6fdf3c6a57c01955aabd33c002..7c1c4208f03349656486bbf409ad7c846bdc73f1 100644
--- a/base/common/src/com/netscape/certsrv/system/SecurityDomainClient.java
+++ b/base/common/src/com/netscape/certsrv/system/SecurityDomainClient.java
@@ -19,6 +19,7 @@ package com.netscape.certsrv.system;
 
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
@@ -26,9 +27,8 @@ import com.netscape.certsrv.client.PKIClient;
 /**
  * @author alee
  */
-public class SecurityDomainClient {
+public class SecurityDomainClient extends Client {
 
-    private PKIClient client;
     private SecurityDomainResource securityDomainClient;
 
     public SecurityDomainClient(ClientConfig config) throws URISyntaxException {
@@ -36,7 +36,7 @@ public class SecurityDomainClient {
     }
 
     public SecurityDomainClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "securitydomain");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java b/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java
index aa4e6842e53a3a96e845354a8b799a10175d9f0a..b7e95d0cb7d80b785e100183a208b8f921182d8d 100644
--- a/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java
+++ b/base/common/src/com/netscape/certsrv/system/SystemConfigClient.java
@@ -19,6 +19,7 @@ package com.netscape.certsrv.system;
 
 import java.net.URISyntaxException;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
@@ -27,9 +28,8 @@ import com.netscape.certsrv.client.PKIClient;
  * @author alee
  *
  */
-public class SystemConfigClient {
+public class SystemConfigClient extends Client {
 
-    private PKIClient client;
     private SystemConfigResource configClient;
 
     public SystemConfigClient(ClientConfig config) throws URISyntaxException {
@@ -37,7 +37,7 @@ public class SystemConfigClient {
     }
 
     public SystemConfigClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "systemconfig");
         init();
     }
 
diff --git a/base/common/src/com/netscape/certsrv/token/TokenClient.java b/base/common/src/com/netscape/certsrv/token/TokenClient.java
index d14fb9e2e4cad86c194b1c406ed892fba0e4d843..ecabf90f1cfd52fd6cfe420b5eb7aa2ac87081ad 100644
--- a/base/common/src/com/netscape/certsrv/token/TokenClient.java
+++ b/base/common/src/com/netscape/certsrv/token/TokenClient.java
@@ -23,22 +23,23 @@ import org.jboss.resteasy.client.ClientResponse;
 
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.Client;
 
 /**
  * @author Endi S. Dewata
  */
-public class TokenClient {
+public class TokenClient extends Client {
 
-    public PKIClient client;
     public TokenResource resource;
 
-    public TokenClient(ClientConfig config) throws URISyntaxException {
-        this(new PKIClient(config));
+    public TokenClient(ClientConfig config, String subsystem) throws URISyntaxException {
+        this(new PKIClient(config), subsystem);
     }
 
-    public TokenClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
-        resource = client.createProxy(TokenResource.class);
+    public TokenClient(PKIClient client, String subsystem) throws URISyntaxException {
+        super(client, "token");
+
+        resource = client.createProxy(subsystem, TokenResource.class);
     }
 
     public TokenCollection findTokens(Integer start, Integer size) {
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 2ab50ac1b20721e05d7b8adeaa0e744167511251..fd06f3fc8da345aa7bf133bc0da2a90dc2edfb7b 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -17,26 +17,18 @@
 //--- END COPYRIGHT BLOCK ---
 package com.netscape.certsrv.tps;
 
-import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.SubsystemClient;
 import com.netscape.certsrv.token.TokenClient;
 
 /**
  * @author Endi S. Dewata
  */
-public class TPSClient {
-
-    public TokenClient tokenClient;
-
-    public TPSClient(ClientConfig config) throws Exception {
-        this(new PKIClient(config));
-    }
+public class TPSClient extends SubsystemClient {
 
     public TPSClient(PKIClient client) throws Exception {
-        tokenClient = new TokenClient(client);
-    }
+        super(client, "tps");
 
-    public TokenClient getTokenClient() {
-        return tokenClient;
+        addClient(new TokenClient(client, name));
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/user/UserClient.java b/base/common/src/com/netscape/certsrv/user/UserClient.java
index 5f1ebd5b8a1935d61af3229f58720ffddc26946f..bde2d919c609a2a0d4ea9aa1ad2847c175a3a247 100644
--- a/base/common/src/com/netscape/certsrv/user/UserClient.java
+++ b/base/common/src/com/netscape/certsrv/user/UserClient.java
@@ -21,15 +21,15 @@ import java.net.URISyntaxException;
 
 import org.jboss.resteasy.client.ClientResponse;
 
+import com.netscape.certsrv.client.Client;
 import com.netscape.certsrv.client.ClientConfig;
 import com.netscape.certsrv.client.PKIClient;
 
 /**
  * @author Endi S. Dewata
  */
-public class UserClient {
+public class UserClient extends Client {
 
-    public PKIClient client;
     public UserResource userClient;
     public UserCertResource userCertClient;
     public UserMembershipResource userMembershipClient;
@@ -39,7 +39,7 @@ public class UserClient {
     }
 
     public UserClient(PKIClient client) throws URISyntaxException {
-        this.client = client;
+        super(client, "user");
         init();
     }
 
-- 
1.8.1.4

