From 63ac1beaa52025dc3ffd5bc9ffddb515c1c358c5 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 29 Aug 2013 17:29:35 -0400
Subject: [PATCH] Fixed duplicate TPSSubsystem instance.

Previously there were two TPSSubsystem instances: one created by CMSEngine
and the other created by the static code in TPSSubsystem. The second instance
has been removed since it's a duplicate and not initialized properly.
---
 .../src/org/dogtagpki/server/tps/TPSSubsystem.java           |  6 +-----
 .../server/tps/authenticator/AuthenticatorService.java       | 12 ++++++------
 .../src/org/dogtagpki/server/tps/cert/TPSCertService.java    |  5 +++--
 .../dogtagpki/server/tps/connection/ConnectionService.java   | 12 ++++++------
 .../org/dogtagpki/server/tps/logging/ActivityService.java    |  4 ++--
 .../src/org/dogtagpki/server/tps/token/TokenService.java     | 12 ++++++------
 6 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
index 8814014dacb07e7b2a0bac9a5609850e4f8cb1ba..34edc58f46b134987333e155d33a11986ea63ad5 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
@@ -41,7 +41,7 @@ import com.netscape.certsrv.request.IRequestQueue;
  */
 public class TPSSubsystem implements IAuthority, ISubsystem {
 
-    public final static TPSSubsystem INSTANCE = new TPSSubsystem();
+    public final static String ID = "tps";
 
     public ILogger logger = CMS.getLogger();
 
@@ -56,10 +56,6 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
     public TPSCertDatabase certDatabase = new TPSCertDatabase();
     public TokenDatabase tokenDatabase = new TokenDatabase();
 
-    public static TPSSubsystem getInstance() {
-        return INSTANCE;
-    }
-
     @Override
     public String getId() {
         return id;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
index dfe042b6641db160f72df72d4be70398034ddc41..74ae5faa008b883120379fef70acf97fded4f214 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
@@ -109,7 +109,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
             start = start == null ? 0 : start;
             size = size == null ? DEFAULT_SIZE : size;
 
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
             Iterator<AuthenticatorRecord> authenticators = database.getRecords().iterator();
@@ -153,7 +153,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
         CMS.debug("AuthenticatorService.getAuthenticator(\"" + authenticatorID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
             return createAuthenticatorData(database.getRecord(authenticatorID));
@@ -170,7 +170,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
         CMS.debug("AuthenticatorService.addAuthenticator(\"" + authenticatorData.getID() + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
             database.addRecord(createAuthenticatorRecord(authenticatorData));
@@ -194,7 +194,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
         CMS.debug("AuthenticatorService.updateAuthenticator(\"" + authenticatorID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
             database.updateRecord(createAuthenticatorRecord(authenticatorData));
@@ -217,7 +217,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
         CMS.debug("AuthenticatorService.modifyAuthenticator(\"" + authenticatorID + "\", request");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
             AuthenticatorRecord authenticatorRecord = database.getRecord(authenticatorID);
@@ -252,7 +252,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
         CMS.debug("AuthenticatorService.removeAuthenticator(\"" + authenticatorID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
             database.removeRecord(authenticatorID);
 
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
index e0534e3f53f1032ccc7f7cba2a4a562086622033..140a8cc2a25dbe891b05da0c971130b88f66fc11 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import org.dogtagpki.server.tps.TPSSubsystem;
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
+import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.PKIException;
 import com.netscape.certsrv.tps.cert.TPSCertCollection;
 import com.netscape.certsrv.tps.cert.TPSCertData;
@@ -95,7 +96,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
             start = start == null ? 0 : start;
             size = size == null ? DEFAULT_SIZE : size;
 
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TPSCertDatabase database = subsystem.getCertDatabase();
 
             Iterator<TPSCertRecord> activities = database.getRecords().iterator();
@@ -139,7 +140,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
         System.out.println("TPSCertService.getCert(\"" + certID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TPSCertDatabase database = subsystem.getCertDatabase();
 
             return createCertData(database.getRecord(certID));
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
index a6ecbbadde75510e4866a8d3f971d91bd93a3a06..27c68892b34002102c6a79833791b6d4a721e19a 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/connection/ConnectionService.java
@@ -109,7 +109,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
             start = start == null ? 0 : start;
             size = size == null ? DEFAULT_SIZE : size;
 
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
             Iterator<ConnectionRecord> connections = database.getRecords().iterator();
@@ -153,7 +153,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
         CMS.debug("ConnectionService.getConnection(\"" + connectionID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
             return createConnectionData(database.getRecord(connectionID));
@@ -170,7 +170,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
         CMS.debug("ConnectionService.addConnection(\"" + connectionData.getID() + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
             database.addRecord(createConnectionRecord(connectionData));
@@ -194,7 +194,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
         CMS.debug("ConnectionService.updateConnection(\"" + connectionID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
             database.updateRecord(createConnectionRecord(connectionData));
@@ -217,7 +217,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
         CMS.debug("ConnectionService.modifyConnection(\"" + connectionID + "\", request");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
             ConnectionRecord connectionRecord = database.getRecord(connectionID);
@@ -252,7 +252,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
         CMS.debug("ConnectionService.removeConnection(\"" + connectionID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
             database.removeRecord(connectionID);
 
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java
index 491447c614aac99bac629ba1adfddbb2d3dbfc4e..fdbda48160b5c78149d7dda7a5fd48f6f05f88a8 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java
@@ -86,7 +86,7 @@ public class ActivityService extends PKIService implements ActivityResource {
             start = start == null ? 0 : start;
             size = size == null ? DEFAULT_SIZE : size;
 
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ActivityDatabase database = subsystem.getActivityDatabase();
 
             Iterator<ActivityRecord> activities = database.getRecords().iterator();
@@ -130,7 +130,7 @@ public class ActivityService extends PKIService implements ActivityResource {
         CMS.debug("ActivityService.getActivity(\"" + activityID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ActivityDatabase database = subsystem.getActivityDatabase();
 
             return createActivityData(database.getRecord(activityID));
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
index 06c92b7ffc64885ce48815b29a8c30a3f7d1b795..3cf3b9e4e29f38090ab975f7462d427bbe5a8f77 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java
@@ -98,7 +98,7 @@ public class TokenService extends PKIService implements TokenResource {
             start = start == null ? 0 : start;
             size = size == null ? DEFAULT_SIZE : size;
 
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
             Iterator<TokenRecord> tokens = database.getRecords().iterator();
@@ -142,7 +142,7 @@ public class TokenService extends PKIService implements TokenResource {
         CMS.debug("TokenService.getToken(\"" + tokenID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
             return createTokenData(database.getRecord(tokenID));
@@ -159,7 +159,7 @@ public class TokenService extends PKIService implements TokenResource {
         CMS.debug("TokenService.addToken(\"" + tokenData.getID() + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
             database.addRecord(createTokenRecord(tokenData));
@@ -183,7 +183,7 @@ public class TokenService extends PKIService implements TokenResource {
         CMS.debug("TokenService.updateToken(\"" + tokenID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
             TokenRecord tokenRecord = database.getRecord(tokenID);
@@ -209,7 +209,7 @@ public class TokenService extends PKIService implements TokenResource {
         CMS.debug("TokenService.modifyToken(\"" + tokenID + "\", request");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
             TokenRecord tokenRecord = database.getRecord(tokenID);
@@ -234,7 +234,7 @@ public class TokenService extends PKIService implements TokenResource {
         CMS.debug("TokenService.removeToken(\"" + tokenID + "\")");
 
         try {
-            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
             database.removeRecord(tokenID);
 
-- 
1.8.1.4

