summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/logging
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-10-02 12:39:13 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-10-08 19:01:18 -0400
commit53ef3a1a1c80539a470537a03ec77cdcb71b2fd3 (patch)
treeb51352a2e48c6d68c558bcd048e9b3be5aae4b8f /base/java-tools/src/com/netscape/cmstools/logging
parentae753b2f5775b5f523d5183235d8820a65cf0eea (diff)
downloadpki-53ef3a1a1c80539a470537a03ec77cdcb71b2fd3.tar.gz
pki-53ef3a1a1c80539a470537a03ec77cdcb71b2fd3.tar.xz
pki-53ef3a1a1c80539a470537a03ec77cdcb71b2fd3.zip
Added audit resource.
A new REST service and clients have been added to manage the audit configuration in all subsystems. Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/logging')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/AuditCLI.java71
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java115
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/AuditShowCLI.java86
3 files changed, 272 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/AuditCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/AuditCLI.java
new file mode 100644
index 000000000..42e735eca
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/AuditCLI.java
@@ -0,0 +1,71 @@
+// --- 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.logging;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.logging.AuditClient;
+import com.netscape.certsrv.logging.AuditConfig;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuditCLI extends CLI {
+
+ public AuditClient auditClient;
+
+ public AuditCLI(CLI parent) {
+ super("audit", "Audit management commands", parent);
+
+ addModule(new AuditModifyCLI(this));
+ addModule(new AuditShowCLI(this));
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ client = parent.getClient();
+ auditClient = (AuditClient)parent.getClient("audit");
+
+ super.execute(args);
+ }
+
+ public static void printAuditConfig(AuditConfig auditConfig) throws IOException {
+
+ if (auditConfig.getEnabled() != null) System.out.println(" Enabled: " + auditConfig.getEnabled());
+ if (auditConfig.getSigned() != null) System.out.println(" Signed: " + auditConfig.getSigned());
+ if (auditConfig.getInterval() != null) System.out.println(" Interval (seconds): " + auditConfig.getInterval());
+ if (auditConfig.getBufferSize() != null) System.out.println(" Buffer size (bytes): " + auditConfig.getBufferSize());
+
+ System.out.println(" Events:");
+ Map<String, Boolean> events = auditConfig.getOptionalEvents();
+ for (String name : events.keySet()) {
+ Boolean value = events.get(name);
+ System.out.println(" " + name + ": " + value);
+ }
+
+ Link link = auditConfig.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java
new file mode 100644
index 000000000..9906c20ee
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/AuditModifyCLI.java
@@ -0,0 +1,115 @@
+// --- 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.logging;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.logging.AuditConfig;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuditModifyCLI extends CLI {
+
+ public AuditCLI auditCLI;
+
+ public AuditModifyCLI(AuditCLI auditCLI) {
+ super("mod", "Modify audit configuration", auditCLI);
+ this.auditCLI = auditCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "input", true, "Input file containing audit configuration.");
+ option.setArgName("file");
+ option.setRequired(true);
+ options.addOption(option);
+
+ option = new Option(null, "output", true, "Output file to store audit configuration.");
+ option.setArgName("file");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String input = cmd.getOptionValue("input");
+ String output = cmd.getOptionValue("output");
+
+ if (input == null) {
+ System.err.println("Error: Input file is required.");
+ printHelp();
+ System.exit(1);
+ }
+
+ AuditConfig auditConfig;
+
+ try (BufferedReader in = new BufferedReader(new FileReader(input));
+ StringWriter sw = new StringWriter();
+ PrintWriter out = new PrintWriter(sw, true)) {
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+
+ auditConfig = AuditConfig.valueOf(sw.toString());
+ }
+
+ auditConfig = auditCLI.auditClient.updateAuditConfig(auditConfig);
+
+ MainCLI.printMessage("Updated audit configuration");
+
+ if (output == null) {
+ AuditCLI.printAuditConfig(auditConfig);
+
+ } else {
+ try (PrintWriter out = new PrintWriter(new FileWriter(output))) {
+ out.println(auditConfig);
+ }
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/AuditShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/AuditShowCLI.java
new file mode 100644
index 000000000..9968d722d
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/AuditShowCLI.java
@@ -0,0 +1,86 @@
+// --- 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.logging;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.logging.AuditConfig;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuditShowCLI extends CLI {
+
+ public AuditCLI auditCLI;
+
+ public AuditShowCLI(AuditCLI auditCLI) {
+ super("show", "Show audit configuration", auditCLI);
+ this.auditCLI = auditCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName(), options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "output", true, "Output file to store audit configuration.");
+ option.setArgName("file");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String output = cmd.getOptionValue("output");
+
+ AuditConfig auditConfig = auditCLI.auditClient.getAuditConfig();
+
+ if (output == null) {
+ MainCLI.printMessage("Audit configuration");
+ AuditCLI.printAuditConfig(auditConfig);
+
+ } else {
+ try (PrintWriter out = new PrintWriter(new FileWriter(output))) {
+ out.println(auditConfig);
+ }
+ MainCLI.printMessage("Stored audit configuration into " + output);
+ }
+ }
+}