[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();
-   

[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