summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-08-22 17:48:58 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-08-24 01:39:04 -0400
commitffb49f1552a9eabb8ec083edd91841253e173ae5 (patch)
treef4c47644c8c5f7f8d9132656599b18c3130d51cf /base
parentc587da42da2b87dec2d1fbfd262a1fc6e8598452 (diff)
downloadpki-ffb49f1552a9eabb8ec083edd91841253e173ae5.tar.gz
pki-ffb49f1552a9eabb8ec083edd91841253e173ae5.tar.xz
pki-ffb49f1552a9eabb8ec083edd91841253e173ae5.zip
Added TPS activities resource.
New REST services and clients have been added for TPS activities. The activity database is currently implemented as in-memory database with some sample data. Later it will be converted into LDAP database. Ticket #652
Diffstat (limited to 'base')
-rw-r--r--base/common/src/com/netscape/certsrv/logging/ActivityClient.java52
-rw-r--r--base/common/src/com/netscape/certsrv/logging/ActivityCollection.java38
-rw-r--r--base/common/src/com/netscape/certsrv/logging/ActivityData.java208
-rw-r--r--base/common/src/com/netscape/certsrv/logging/ActivityResource.java44
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSClient.java2
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java2
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java83
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java94
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java56
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java70
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java197
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java143
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java4
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java6
-rw-r--r--base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java21
15 files changed, 999 insertions, 21 deletions
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityClient.java b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
new file mode 100644
index 000000000..251183ec5
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
@@ -0,0 +1,52 @@
+//--- 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.logging;
+
+import java.net.URISyntaxException;
+
+import com.netscape.certsrv.client.Client;
+import com.netscape.certsrv.client.PKIClient;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityClient extends Client {
+
+ public ActivityResource resource;
+
+ public ActivityClient(PKIClient client) throws URISyntaxException {
+ this(client, client.getSubsystem());
+ }
+
+ public ActivityClient(PKIClient client, String subsystem) throws URISyntaxException {
+ super(client, subsystem, "activity");
+ init();
+ }
+
+ public void init() throws URISyntaxException {
+ resource = createProxy(ActivityResource.class);
+ }
+
+ public ActivityCollection findActivities(Integer start, Integer size) {
+ return resource.findActivities(start, size);
+ }
+
+ public ActivityData getActivity(String tokenID) {
+ return resource.getActivity(tokenID);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityCollection.java b/base/common/src/com/netscape/certsrv/logging/ActivityCollection.java
new file mode 100644
index 000000000..d6f998843
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityCollection.java
@@ -0,0 +1,38 @@
+// --- 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.logging;
+
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.netscape.certsrv.base.DataCollection;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="Activities")
+public class ActivityCollection extends DataCollection<ActivityData> {
+
+ @XmlElementRef
+ public Collection<ActivityData> getEntries() {
+ return super.getEntries();
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityData.java b/base/common/src/com/netscape/certsrv/logging/ActivityData.java
new file mode 100644
index 000000000..0624cc73b
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityData.java
@@ -0,0 +1,208 @@
+// --- 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.logging;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Date;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="Activity")
+public class ActivityData {
+
+ public static Marshaller marshaller;
+ public static Unmarshaller unmarshaller;
+
+ static {
+ try {
+ marshaller = JAXBContext.newInstance(ActivityData.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshaller = JAXBContext.newInstance(ActivityData.class).createUnmarshaller();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String id;
+ String tokenID;
+ String userID;
+ String ip;
+ String operation;
+ String result;
+ Date date;
+
+ Link link;
+
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @XmlElement(name="TokenID")
+ public String getTokenID() {
+ return tokenID;
+ }
+
+ public void setTokenID(String tokenID) {
+ this.tokenID = tokenID;
+ }
+
+ @XmlElement(name="UserID")
+ public String getUserID() {
+ return userID;
+ }
+
+ public void setUserID(String userID) {
+ this.userID = userID;
+ }
+
+ @XmlElement(name="IP")
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ @XmlElement(name="Operation")
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ @XmlElement(name="Result")
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+ @XmlElement(name="Date")
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @XmlElement(name="Link")
+ public Link getLink() {
+ return link;
+ }
+
+ public void setLink(Link link) {
+ this.link = link;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((link == null) ? 0 : link.hashCode());
+ result = prime * result + ((userID == null) ? 0 : userID.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ActivityData other = (ActivityData) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (link == null) {
+ if (other.link != null)
+ return false;
+ } else if (!link.equals(other.link))
+ return false;
+ if (userID == null) {
+ if (other.userID != null)
+ return false;
+ } else if (!userID.equals(other.userID))
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ try {
+ StringWriter sw = new StringWriter();
+ marshaller.marshal(this, sw);
+ return sw.toString();
+
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+ public static ActivityData valueOf(String string) throws Exception {
+ try {
+ return (ActivityData)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ ActivityData before = new ActivityData();
+ before.setID("activity1");
+ before.setTokenID("TOKEN1234");
+ before.setUserID("user1");
+ before.setIp("192.168.1.1");
+ before.setOperation("enroll");
+ before.setResult("success");
+ before.setDate(new Date());
+
+ String string = before.toString();
+ System.out.println(string);
+
+ ActivityData after = ActivityData.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityResource.java b/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
new file mode 100644
index 000000000..6ecf41dd2
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
@@ -0,0 +1,44 @@
+// --- 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.logging;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+@Path("activities")
+public interface ActivityResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ActivityCollection findActivities(
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @GET
+ @Path("{activityID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ActivityData getActivity(@PathParam("activityID") String activityID);
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 7b35ab208..38aff46bd 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
import com.netscape.certsrv.client.PKIClient;
import com.netscape.certsrv.client.SubsystemClient;
+import com.netscape.certsrv.logging.ActivityClient;
import com.netscape.certsrv.token.TokenClient;
/**
@@ -34,6 +35,7 @@ public class TPSClient extends SubsystemClient {
}
public void init() throws URISyntaxException {
+ addClient(new ActivityClient(client, name));
addClient(new TokenClient(client, name));
}
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
index 1f10e959a..4c9e501ad 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cli;
import com.netscape.certsrv.client.Client;
import com.netscape.certsrv.tps.TPSClient;
+import com.netscape.cmstools.logging.ActivityCLI;
import com.netscape.cmstools.token.TokenCLI;
/**
@@ -32,6 +33,7 @@ public class TPSCLI extends SubsystemCLI {
public TPSCLI(MainCLI mainCLI) {
super("tps", "TPS management commands", mainCLI);
+ addModule(new ActivityCLI(this));
addModule(new TokenCLI(this));
}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
new file mode 100644
index 000000000..4a9bf3828
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
@@ -0,0 +1,83 @@
+// --- 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.util.Arrays;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.logging.ActivityClient;
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityCLI extends CLI {
+
+ public ActivityClient activityClient;
+
+ public ActivityCLI(CLI parent) {
+ super("activity", "Activity management commands", parent);
+
+ addModule(new ActivityFindCLI(this));
+ addModule(new ActivityShowCLI(this));
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ client = parent.getClient();
+ activityClient = (ActivityClient)parent.getClient("activity");
+
+ if (args.length == 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String command = args[0];
+ String[] commandArgs = Arrays.copyOfRange(args, 1, args.length);
+
+ if (command == null) {
+ printHelp();
+ System.exit(1);
+ }
+
+ CLI module = getModule(command);
+ if (module != null) {
+ module.execute(commandArgs);
+
+ } else {
+ System.err.println("Error: Invalid command \"" + command + "\"");
+ printHelp();
+ System.exit(1);
+ }
+ }
+
+ public static void printActivity(ActivityData activity) {
+ System.out.println(" Activity ID: " + activity.getID());
+ if (activity.getTokenID() != null) System.out.println(" Token ID: " + activity.getTokenID());
+ if (activity.getUserID() != null) System.out.println(" User ID: " + activity.getUserID());
+ if (activity.getDate() != null) System.out.println(" Date: " + activity.getDate());
+
+ Link link = activity.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
new file mode 100644
index 000000000..0808a0a70
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -0,0 +1,94 @@
+// --- 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.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.logging.ActivityCollection;
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityFindCLI extends CLI {
+
+ public ActivityCLI activityCLI;
+
+ public ActivityFindCLI(ActivityCLI activityCLI) {
+ super("find", "Find activities", activityCLI);
+ this.activityCLI = activityCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ 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 s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ ActivityCollection result = activityCLI.activityClient.findActivities(start, size);
+ Collection<ActivityData> activities = result.getEntries();
+
+ MainCLI.printMessage(activities.size() + " activity(s) matched");
+
+ boolean first = true;
+
+ for (ActivityData activityData : activities) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ ActivityCLI.printActivity(activityData);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + activities.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
new file mode 100644
index 000000000..6fa49c90c
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
@@ -0,0 +1,56 @@
+// --- 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 com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityShowCLI extends CLI {
+
+ public ActivityCLI activityCLI;
+
+ public ActivityShowCLI(ActivityCLI activityCLI) {
+ super("show", "Show activity", activityCLI);
+ this.activityCLI = activityCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Activity ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String activityID = args[0];
+
+ ActivityData activityData = activityCLI.activityClient.getActivity(activityID);
+
+ MainCLI.printMessage("Activity \"" + activityID + "\"");
+
+ ActivityCLI.printActivity(activityData);
+ }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java
new file mode 100644
index 000000000..28c0935da
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java
@@ -0,0 +1,70 @@
+// --- 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 org.dogtagpki.tps.logging;
+
+import java.util.Date;
+
+import com.netscape.cmscore.dbs.Database;
+
+/**
+ * This class implements in-memory activity database. In the future this
+ * will be replaced with LDAP database.
+ *
+ * @author Endi S. Dewata
+ */
+public class ActivityDatabase extends Database<ActivityRecord> {
+
+ public ActivityDatabase() {
+ super("Activity");
+
+ // add sample records
+ try {
+ ActivityRecord record1 = new ActivityRecord();
+ record1.setID("activity1");
+ record1.setTokenID("token1");
+ record1.setUserID("user1");
+ record1.setIp("192.168.1.1");
+ record1.setOperation("enroll");
+ record1.setResult("success");
+ addRecord(record1);
+
+ ActivityRecord record2 = new ActivityRecord();
+ record2.setID("activity2");
+ record2.setTokenID("token2");
+ record2.setUserID("user2");
+ record2.setIp("192.168.1.2");
+ record2.setOperation("enroll");
+ record2.setResult("failed");
+ addRecord(record2);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void addRecord(ActivityRecord activityRecord) throws Exception {
+ activityRecord.setDate(new Date());
+
+ addRecord(activityRecord.getID(), activityRecord);
+ }
+
+ public void updateRecord(ActivityRecord activityRecord) throws Exception {
+ updateRecord(activityRecord.getID(), activityRecord);
+ }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java
new file mode 100644
index 000000000..e845955ca
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java
@@ -0,0 +1,197 @@
+// --- 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 org.dogtagpki.tps.logging;
+
+import java.util.Date;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityRecord {
+
+ String id;
+ String tokenID;
+ String userID;
+ String ip;
+ String operation;
+ String result;
+ String message;
+ String extensions;
+ String type;
+ Date date;
+
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ public String getTokenID() {
+ return tokenID;
+ }
+
+ public void setTokenID(String tokenID) {
+ this.tokenID = tokenID;
+ }
+
+ public String getUserID() {
+ return userID;
+ }
+
+ public void setUserID(String userID) {
+ this.userID = userID;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getExtensions() {
+ return extensions;
+ }
+
+ public void setExtensions(String extensions) {
+ this.extensions = extensions;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((date == null) ? 0 : date.hashCode());
+ result = prime * result + ((extensions == null) ? 0 : extensions.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((ip == null) ? 0 : ip.hashCode());
+ result = prime * result + ((message == null) ? 0 : message.hashCode());
+ result = prime * result + ((operation == null) ? 0 : operation.hashCode());
+ result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
+ result = prime * result + ((tokenID == null) ? 0 : tokenID.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ result = prime * result + ((userID == null) ? 0 : userID.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ActivityRecord other = (ActivityRecord) obj;
+ if (date == null) {
+ if (other.date != null)
+ return false;
+ } else if (!date.equals(other.date))
+ return false;
+ if (extensions == null) {
+ if (other.extensions != null)
+ return false;
+ } else if (!extensions.equals(other.extensions))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (ip == null) {
+ if (other.ip != null)
+ return false;
+ } else if (!ip.equals(other.ip))
+ return false;
+ if (message == null) {
+ if (other.message != null)
+ return false;
+ } else if (!message.equals(other.message))
+ return false;
+ if (operation == null) {
+ if (other.operation != null)
+ return false;
+ } else if (!operation.equals(other.operation))
+ return false;
+ if (result == null) {
+ if (other.result != null)
+ return false;
+ } else if (!result.equals(other.result))
+ return false;
+ if (tokenID == null) {
+ if (other.tokenID != null)
+ return false;
+ } else if (!tokenID.equals(other.tokenID))
+ return false;
+ if (type == null) {
+ if (other.type != null)
+ return false;
+ } else if (!type.equals(other.type))
+ return false;
+ if (userID == null) {
+ if (other.userID != null)
+ return false;
+ } else if (!userID.equals(other.userID))
+ return false;
+ return true;
+ }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java
new file mode 100644
index 000000000..174fd554f
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java
@@ -0,0 +1,143 @@
+// --- 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 org.dogtagpki.tps.logging;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLEncoder;
+import java.util.Iterator;
+
+import org.dogtagpki.tps.server.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.logging.ActivityCollection;
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.certsrv.logging.ActivityResource;
+import com.netscape.cms.servlet.base.PKIService;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityService extends PKIService implements ActivityResource {
+
+ public final static int DEFAULT_SIZE = 20;
+
+ public ActivityService() {
+ CMS.debug("ActivityService.<init>()");
+ }
+
+ public ActivityData createActivityData(ActivityRecord activityRecord) {
+
+ ActivityData activityData = new ActivityData();
+ activityData.setID(activityRecord.getID());
+ activityData.setTokenID(activityRecord.getTokenID());
+ activityData.setUserID(activityRecord.getUserID());
+ activityData.setDate(activityRecord.getDate());
+
+ String activityID = activityRecord.getID();
+ try {
+ activityID = URLEncoder.encode(activityID, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ throw new PKIException(e.getMessage());
+ }
+
+ URI uri = uriInfo.getBaseUriBuilder().path(ActivityResource.class).path("{activityID}").build(activityID);
+ activityData.setLink(new Link("self", uri));
+
+ return activityData;
+ }
+
+ public ActivityRecord createActivityRecord(ActivityData activityData) {
+
+ ActivityRecord activityRecord = new ActivityRecord();
+ activityRecord.setID(activityData.getID());
+ activityRecord.setTokenID(activityData.getTokenID());
+ activityRecord.setUserID(activityData.getUserID());
+ activityRecord.setDate(activityData.getDate());
+
+ return activityRecord;
+ }
+
+ @Override
+ public ActivityCollection findActivities(Integer start, Integer size) {
+
+ CMS.debug("ActivityService.findActivities()");
+
+ try {
+ start = start == null ? 0 : start;
+ size = size == null ? DEFAULT_SIZE : size;
+
+ TPSSubsystem subsystem = TPSSubsystem.getInstance();
+ ActivityDatabase database = subsystem.getActivityDatabase();
+
+ Iterator<ActivityRecord> activities = database.getRecords().iterator();
+
+ ActivityCollection response = new ActivityCollection();
+
+ int i = 0;
+
+ // skip to the start of the page
+ for ( ; i<start && activities.hasNext(); i++) activities.next();
+
+ // return entries up to the page size
+ for ( ; i<start+size && activities.hasNext(); i++) {
+ response.addEntry(createActivityData(activities.next()));
+ }
+
+ // count the total entries
+ for ( ; activities.hasNext(); i++) activities.next();
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start-size, 0)).build();
+ response.addLink(new Link("prev", uri));
+ }
+
+ if (start+size < i) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start+size).build();
+ response.addLink(new Link("next", uri));
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new PKIException(e.getMessage());
+ }
+ }
+
+ @Override
+ public ActivityData getActivity(String activityID) {
+
+ CMS.debug("ActivityService.getActivity(\"" + activityID + "\")");
+
+ try {
+ TPSSubsystem subsystem = TPSSubsystem.getInstance();
+ ActivityDatabase database = subsystem.getActivityDatabase();
+
+ return createActivityData(database.getRecord(activityID));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new PKIException(e.getMessage());
+ }
+ }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java
index fc3c18ee2..8f1a97db3 100644
--- a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java
@@ -22,6 +22,7 @@ import java.util.Set;
import javax.ws.rs.core.Application;
+import org.dogtagpki.tps.logging.ActivityService;
import org.dogtagpki.tps.token.TokenService;
import com.netscape.certsrv.base.PKIException;
@@ -62,6 +63,9 @@ public class TPSApplication extends Application {
// system certs
classes.add(SystemCertService.class);
+ // activities
+ classes.add(ActivityService.class);
+
// tokens
classes.add(TokenService.class);
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java
index ef92c7284..08afe0a09 100644
--- a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package org.dogtagpki.tps.server;
+import org.dogtagpki.tps.logging.ActivityDatabase;
import org.dogtagpki.tps.token.TokenDatabase;
import org.mozilla.jss.CryptoManager;
import org.mozilla.jss.CryptoManager.NotInitializedException;
@@ -46,6 +47,7 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
public ISubsystem owner;
public IConfigStore config;
+ public ActivityDatabase activityDatabase = new ActivityDatabase();
public TokenDatabase tokenDatabase = new TokenDatabase();
public static TPSSubsystem getInstance() {
@@ -113,6 +115,10 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
return "tps";
}
+ public ActivityDatabase getActivityDatabase() {
+ return activityDatabase;
+ }
+
public TokenDatabase getTokenDatabase() {
return tokenDatabase;
}
diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java b/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java
index 1f9d9caf5..85130e8bc 100644
--- a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java
+++ b/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java
@@ -20,8 +20,6 @@ package org.dogtagpki.tps.token;
import java.util.Date;
-import com.netscape.certsrv.token.TokenData;
-
/**
* @author Endi S. Dewata
*/
@@ -166,23 +164,4 @@ public class TokenRecord {
return false;
return true;
}
-
- public static void main(String args[]) throws Exception {
-
- TokenData before = new TokenData();
- before.setID("token1");
- before.setUserID("user1");
- before.setStatus("revoked");
- before.setReason("lost");
- before.setAppletID("APPLET1234");
- before.setKeyInfo("key info");
- before.setCreateTimestamp(new Date());
- before.setModifyTimestamp(new Date());
-
- String string = before.toString();
- System.out.println(string);
-
- TokenData after = TokenData.valueOf(string);
- System.out.println(before.equals(after));
- }
}