[Pki-devel] [PATCH] 932 Cleaned up error handling in TPS CLIs.

2017-02-07 Thread Endi Sukma Dewata

The TPS CLIs have been modified to use Exceptions instead of
System.exit() such that errors can be handled consistently.

Pushed to master under trivial rule.

--
Endi S. Dewata
>From cb06ebebc6758ae7e1571ee09074810dc9f33b4f Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" 
Date: Wed, 18 Jan 2017 03:08:02 +0100
Subject: [PATCH] Cleaned up error handling in TPS CLIs.

The TPS CLIs have been modified to use Exceptions instead of
System.exit() such that errors can be handled consistently.
---
 .../tps/authenticator/AuthenticatorAddCLI.java | 18 +++--
 .../tps/authenticator/AuthenticatorFindCLI.java| 14 ++---
 .../tps/authenticator/AuthenticatorModifyCLI.java  | 23 --
 .../tps/authenticator/AuthenticatorRemoveCLI.java  | 18 +++--
 .../tps/authenticator/AuthenticatorShowCLI.java| 18 +++--
 .../netscape/cmstools/tps/cert/TPSCertFindCLI.java | 20 ---
 .../netscape/cmstools/tps/cert/TPSCertShowCLI.java | 20 ---
 .../cmstools/tps/config/ConfigModifyCLI.java   | 18 +++--
 .../cmstools/tps/config/ConfigShowCLI.java | 18 +++--
 .../cmstools/tps/connector/ConnectorAddCLI.java| 18 +++--
 .../cmstools/tps/connector/ConnectorFindCLI.java   | 14 ++---
 .../cmstools/tps/connector/ConnectorModifyCLI.java | 23 --
 .../cmstools/tps/connector/ConnectorRemoveCLI.java | 18 +++--
 .../cmstools/tps/connector/ConnectorShowCLI.java   | 18 +++--
 .../cmstools/tps/profile/ProfileAddCLI.java| 18 +++--
 .../cmstools/tps/profile/ProfileFindCLI.java   | 14 ++---
 .../cmstools/tps/profile/ProfileMappingAddCLI.java | 18 +++--
 .../tps/profile/ProfileMappingFindCLI.java | 14 ++---
 .../tps/profile/ProfileMappingModifyCLI.java   | 23 --
 .../tps/profile/ProfileMappingRemoveCLI.java   | 18 +++--
 .../tps/profile/ProfileMappingShowCLI.java | 20 ---
 .../cmstools/tps/profile/ProfileModifyCLI.java | 23 --
 .../cmstools/tps/profile/ProfileRemoveCLI.java | 18 +++--
 .../cmstools/tps/profile/ProfileShowCLI.java   | 18 +++--
 .../netscape/cmstools/tps/token/TokenAddCLI.java   | 18 +++--
 .../netscape/cmstools/tps/token/TokenFindCLI.java  | 14 ++---
 .../cmstools/tps/token/TokenModifyCLI.java | 22 -
 .../cmstools/tps/token/TokenRemoveCLI.java | 18 +++--
 .../netscape/cmstools/tps/token/TokenShowCLI.java  | 18 +++--
 29 files changed, 90 insertions(+), 442 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
index 52475094790ceec52b90b9ec7470c8dcf59ba9d3..5ae04afa5f31d0cd9269b5177616a07e354c51e8 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
@@ -59,28 +59,16 @@ public class AuthenticatorAddCLI extends CLI {
 public void execute(String[] args) throws Exception {
 // Always check for "--help" prior to parsing
 if (Arrays.asList(args).contains("--help")) {
-// Display usage
 printHelp();
-System.exit(0);
+return;
 }
 
-CommandLine cmd = null;
-
-try {
-cmd = parser.parse(options, args);
-
-} catch (Exception e) {
-System.err.println("Error: " + e.getMessage());
-printHelp();
-System.exit(-1);
-}
+CommandLine cmd = parser.parse(options, args);
 
 String[] cmdArgs = cmd.getArgs();
 
 if (cmdArgs.length != 0) {
-System.err.println("Error: Too many arguments specified.");
-printHelp();
-System.exit(-1);
+throw new Exception("Too many arguments specified.");
 }
 
 String input = cmd.getOptionValue("input");
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
index 58532de554f465e4ecdb06f5c389d66d4e779f24..778f370f00efb34ce7e35a1731e9ba7282e417ca 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
@@ -60,21 +60,11 @@ public class AuthenticatorFindCLI extends CLI {
 public void execute(String[] args) throws Exception {
 // Always check for "--help" prior to parsing
 if (Arrays.asList(args).contains("--help")) {
-// Display usage
 printHelp();
-System.exit

[Pki-devel] [PATCH] 931 Cleaned up error handling in system, logging, and selftest CLIs.

2017-02-07 Thread Endi Sukma Dewata

The system, logging, and selftest CLIs have been modified to use
Exceptions instead of System.exit() such that errors can be
handled consistently.

Pushed to master under trivial rule.

--
Endi S. Dewata
>From c11e7f745f246426addb48c83ed9b25ff7933157 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" 
Date: Wed, 18 Jan 2017 02:21:07 +0100
Subject: [PATCH] Cleaned up error handling in system, logging, and selftest
 CLIs.

The system, logging, and selftest CLIs have been modified to use
Exceptions instead of System.exit() such that errors can be
handled consistently.
---
 .../netscape/cmstools/logging/ActivityFindCLI.java | 14 ++--
 .../netscape/cmstools/logging/ActivityShowCLI.java | 18 +++
 .../netscape/cmstools/logging/AuditModifyCLI.java  | 26 +-
 .../netscape/cmstools/logging/AuditShowCLI.java| 18 +++
 .../cmstools/selftests/SelfTestFindCLI.java| 14 ++--
 .../cmstools/selftests/SelfTestRunCLI.java | 14 ++--
 .../cmstools/selftests/SelfTestShowCLI.java| 18 +++
 .../cmstools/system/KRAConnectorAddCLI.java| 24 +---
 .../cmstools/system/KRAConnectorRemoveCLI.java | 18 +++
 .../cmstools/system/KRAConnectorShowCLI.java   |  3 +--
 .../cmstools/system/SecurityDomainShowCLI.java | 18 +++
 .../cmstools/system/TPSConnectorAddCLI.java| 18 +++
 .../cmstools/system/TPSConnectorFindCLI.java   | 18 +++
 .../cmstools/system/TPSConnectorModCLI.java| 18 +++
 .../cmstools/system/TPSConnectorRemoveCLI.java | 18 +++
 .../cmstools/system/TPSConnectorShowCLI.java   | 18 +++
 16 files changed, 47 insertions(+), 228 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
index 413eae10155c9298c9c510ed186b451cb8843239..9e31795b4415fe34dc37a6e2f835c4a0a39b3d3e 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -60,21 +60,11 @@ public class ActivityFindCLI extends CLI {
 public void execute(String[] args) throws Exception {
 // Always check for "--help" prior to parsing
 if (Arrays.asList(args).contains("--help")) {
-// Display usage
 printHelp();
-System.exit(0);
+return;
 }
 
-CommandLine cmd = null;
-
-try {
-cmd = parser.parse(options, args);
-
-} catch (Exception e) {
-System.err.println("Error: " + e.getMessage());
-printHelp();
-System.exit(-1);
-}
+CommandLine cmd = parser.parse(options, args);
 
 String[] cmdArgs = cmd.getArgs();
 String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
index b68d6adb547f891061d1de2731a0400dff859302..bae172c7912eb854ecdfb716cb1eafa67efdcfa3 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
@@ -45,28 +45,16 @@ public class ActivityShowCLI extends CLI {
 public void execute(String[] args) throws Exception {
 // Always check for "--help" prior to parsing
 if (Arrays.asList(args).contains("--help")) {
-// Display usage
 printHelp();
-System.exit(0);
+return;
 }
 
-CommandLine cmd = null;
-
-try {
-cmd = parser.parse(options, args);
-
-} catch (Exception e) {
-System.err.println("Error: " + e.getMessage());
-printHelp();
-System.exit(-1);
-}
+CommandLine cmd = parser.parse(options, args);
 
 String[] cmdArgs = cmd.getArgs();
 
 if (cmdArgs.length != 1) {
-System.err.println("Error: No Activity ID specified.");
-printHelp();
-System.exit(-1);
+throw new Exception("No Activity ID specified.");
 }
 
 String activityID = args[0];
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java
index ab9f821b3873787f7e46afa33f2ac94077b694dc..4dc5d8bdc0426dbd1a9ae5a298e573df8e5cfb4d 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java
@@ -67,28 +67,16 @@ public class AuditModifyCLI extends CLI {
 public void execute(String[] args) throws Exception {
 // Always check for "--help" prior to parsing
 if (Arrays.asList(args).contains("--help"

[Pki-devel] [PATCH] 0159..0161 Fix config param removal in profile modification

2017-02-07 Thread Fraser Tweedale
Please review the attached patches which fix
https://fedorahosted.org/pki/ticket/2588, a bug in profile
modification where config params can only be added or changed, but
not removed.

Thanks,
Fraser
From 0a86f63cfe2d5391befe401541e9dcc0dae6ce29 Mon Sep 17 00:00:00 2001
From: Fraser Tweedale 
Date: Tue, 7 Feb 2017 17:27:06 +1000
Subject: [PATCH 159/161] LDAPProfileSubsystem: avoid duplicating logic in
 superclass

Part of: https://fedorahosted.org/pki/ticket/2588
---
 .../cmscore/profile/AbstractProfileSubsystem.java  |  7 +++-
 .../cmscore/profile/LDAPProfileSubsystem.java  | 43 --
 2 files changed, 13 insertions(+), 37 deletions(-)

diff --git 
a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
 
b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
index 
116b8e2026e80b012fb87647fd8924b567194fa3..2a209ad5b2656d65db57d36b7ecb2745527ab081
 100644
--- 
a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
+++ 
b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
@@ -121,7 +121,7 @@ public abstract class AbstractProfileSubsystem implements 
IProfileSubsystem {
 /**
  * Commits a profile.
  */
-public void commitProfile(String id)
+public synchronized void commitProfile(String id)
 throws EProfileException {
 IConfigStore cs = mProfiles.get(id).getConfigStore();
 
@@ -157,6 +157,11 @@ public abstract class AbstractProfileSubsystem implements 
IProfileSubsystem {
 
 // finally commit the configStore
 //
+commitConfigStore(id, cs);
+}
+
+protected void commitConfigStore(String id, IConfigStore cs)
+throws EProfileException {
 try {
 cs.commit(false);
 } catch (EBaseException e) {
diff --git 
a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
 
b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
index 
fff8ead3f2088aedaf5856c308dd33be90af7779..bce675e7bf993d97a086fb830e34d5c4f396
 100644
--- 
a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
+++ 
b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
@@ -303,43 +303,14 @@ public class LDAPProfileSubsystem
 readProfile(entry);
 }
 
+/**
+ * Commit the configStore and track the resulting
+ * entryUSN and (in case of add) the nsUniqueId
+ */
 @Override
-public synchronized void commitProfile(String id) throws EProfileException 
{
-LDAPConfigStore cs = (LDAPConfigStore) 
mProfiles.get(id).getConfigStore();
-
-// first create a *new* profile object from the configStore
-// and initialise it with the updated configStore
-//
-IPluginRegistry registry = (IPluginRegistry)
-CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY);
-String classId = mProfileClassIds.get(id);
-IPluginInfo info = registry.getPluginInfo("profile", classId);
-String className = info.getClassName();
-IProfile newProfile = null;
-try {
-newProfile = (IProfile) Class.forName(className).newInstance();
-} catch (ClassNotFoundException | InstantiationException | 
IllegalAccessException e) {
-throw new EProfileException("Could not instantiate class '"
-+ classId + "' for profile '" + id + "': " + e);
-}
-newProfile.setId(id);
-try {
-newProfile.init(this, cs);
-} catch (EBaseException e) {
-throw new EProfileException(
-"Failed to initialise profile '" + id + "': " + e);
-}
-
-// next replace the existing profile with the new profile;
-// this is to avoid any intermediate state where the profile
-// is not fully initialised with its inputs, outputs and
-// policy objects.
-//
-mProfiles.put(id, newProfile);
-
-// finally commit the configStore and track the resulting
-// entryUSN and (in case of add) the nsUniqueId
-//
+protected void commitConfigStore(String id, IConfigStore configStore)
+throws EProfileException {
+LDAPConfigStore cs = (LDAPConfigStore) configStore;
 try {
 String[] attrs = {"entryUSN", "nsUniqueId"};
 LDAPEntry entry = cs.commitReturn(false, attrs);
-- 
2.9.3

From ca09f58f4a953fb8d40898a1924f236bba42fa29 Mon Sep 17 00:00:00 2001
From: Fraser Tweedale 
Date: Tue, 7 Feb 2017 17:39:33 +1000
Subject: [PATCH 160/161] ISourceConfigStore: add clear() method to interface

The SourceConfigStore load() method does not clear the config store,
but this might be necessary to avoid stale data if wanting to
perform a complete replacement of the data (e.g. reload from file).

We should not change the behaviour of load() in case some code is
rely