From a847bcb7c71836f7c0498163e31238f118740339 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 26 Aug 2013 13:21:58 -0400 Subject: Reorganized TPS classes. The TPS classes have been reorganized as follows: * common: com.netscape.certsrv.tps * CLI: com.netscape.cmstools.tps * server: org.dogtagpki.server.tps TPSConnection and TPSMessage were moved from server package into common package. The build script and configuration files have been modified accordingly. --- .../com/netscape/certsrv/token/TokenClient.java | 70 ----- .../netscape/certsrv/token/TokenCollection.java | 38 --- .../src/com/netscape/certsrv/token/TokenData.java | 219 ---------------- .../netscape/certsrv/token/TokenModifyRequest.java | 152 ----------- .../com/netscape/certsrv/token/TokenResource.java | 80 ------ .../src/com/netscape/certsrv/tps/TPSClient.java | 2 +- .../com/netscape/certsrv/tps/TPSConnection.java | 98 +++++++ .../src/com/netscape/certsrv/tps/TPSMessage.java | 101 ++++++++ .../netscape/certsrv/tps/token/TokenClient.java | 70 +++++ .../certsrv/tps/token/TokenCollection.java | 38 +++ .../com/netscape/certsrv/tps/token/TokenData.java | 219 ++++++++++++++++ .../certsrv/tps/token/TokenModifyRequest.java | 152 +++++++++++ .../netscape/certsrv/tps/token/TokenResource.java | 80 ++++++ .../src/com/netscape/cmstools/cli/TPSCLI.java | 2 +- .../com/netscape/cmstools/token/TokenAddCLI.java | 81 ------ .../src/com/netscape/cmstools/token/TokenCLI.java | 90 ------- .../com/netscape/cmstools/token/TokenFindCLI.java | 94 ------- .../netscape/cmstools/token/TokenModifyCLI.java | 81 ------ .../netscape/cmstools/token/TokenRemoveCLI.java | 53 ---- .../com/netscape/cmstools/token/TokenShowCLI.java | 56 ---- .../netscape/cmstools/tps/token/TokenAddCLI.java | 81 ++++++ .../com/netscape/cmstools/tps/token/TokenCLI.java | 90 +++++++ .../netscape/cmstools/tps/token/TokenFindCLI.java | 94 +++++++ .../cmstools/tps/token/TokenModifyCLI.java | 81 ++++++ .../cmstools/tps/token/TokenRemoveCLI.java | 53 ++++ .../netscape/cmstools/tps/token/TokenShowCLI.java | 56 ++++ base/tps-tomcat/shared/conf/CS.cfg.in | 6 +- base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml | 4 +- base/tps-tomcat/src/CMakeLists.txt | 4 +- .../org/dogtagpki/server/tps/TPSApplication.java | 92 +++++++ .../src/org/dogtagpki/server/tps/TPSServlet.java | 61 +++++ .../src/org/dogtagpki/server/tps/TPSSubsystem.java | 143 ++++++++++ .../dogtagpki/server/tps/cert/TPSCertDatabase.java | 76 ++++++ .../dogtagpki/server/tps/cert/TPSCertRecord.java | 288 +++++++++++++++++++++ .../dogtagpki/server/tps/cert/TPSCertService.java | 152 +++++++++++ .../server/tps/logging/ActivityDatabase.java | 70 +++++ .../server/tps/logging/ActivityRecord.java | 197 ++++++++++++++ .../server/tps/logging/ActivityService.java | 143 ++++++++++ .../server/tps/selftests/TPSPresence.java | 187 +++++++++++++ .../server/tps/selftests/TPSValidity.java | 197 ++++++++++++++ .../dogtagpki/server/tps/token/TokenDatabase.java | 49 ++++ .../dogtagpki/server/tps/token/TokenRecord.java | 167 ++++++++++++ .../dogtagpki/server/tps/token/TokenService.java | 245 ++++++++++++++++++ .../src/org/dogtagpki/tps/TPSConnection.java | 98 ------- .../src/org/dogtagpki/tps/TPSMessage.java | 101 -------- .../org/dogtagpki/tps/cert/TPSCertDatabase.java | 76 ------ .../src/org/dogtagpki/tps/cert/TPSCertRecord.java | 288 --------------------- .../src/org/dogtagpki/tps/cert/TPSCertService.java | 152 ----------- .../dogtagpki/tps/logging/ActivityDatabase.java | 70 ----- .../org/dogtagpki/tps/logging/ActivityRecord.java | 197 -------------- .../org/dogtagpki/tps/logging/ActivityService.java | 143 ---------- .../org/dogtagpki/tps/selftests/TPSPresence.java | 187 ------------- .../org/dogtagpki/tps/selftests/TPSValidity.java | 197 -------------- .../org/dogtagpki/tps/server/TPSApplication.java | 92 ------- .../src/org/dogtagpki/tps/server/TPSServlet.java | 61 ----- .../src/org/dogtagpki/tps/server/TPSSubsystem.java | 143 ---------- .../src/org/dogtagpki/tps/token/TokenDatabase.java | 49 ---- .../src/org/dogtagpki/tps/token/TokenRecord.java | 167 ------------ .../src/org/dogtagpki/tps/token/TokenService.java | 245 ------------------ 59 files changed, 3289 insertions(+), 3289 deletions(-) delete mode 100644 base/common/src/com/netscape/certsrv/token/TokenClient.java delete mode 100644 base/common/src/com/netscape/certsrv/token/TokenCollection.java delete mode 100644 base/common/src/com/netscape/certsrv/token/TokenData.java delete mode 100644 base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java delete mode 100644 base/common/src/com/netscape/certsrv/token/TokenResource.java create mode 100644 base/common/src/com/netscape/certsrv/tps/TPSConnection.java create mode 100644 base/common/src/com/netscape/certsrv/tps/TPSMessage.java create mode 100644 base/common/src/com/netscape/certsrv/tps/token/TokenClient.java create mode 100644 base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java create mode 100644 base/common/src/com/netscape/certsrv/tps/token/TokenData.java create mode 100644 base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java create mode 100644 base/common/src/com/netscape/certsrv/tps/token/TokenResource.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertDatabase.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertRecord.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityDatabase.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityRecord.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSPresence.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSValidity.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenDatabase.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenRecord.java create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/TPSConnection.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/TPSMessage.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertDatabase.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertRecord.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertService.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSPresence.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSValidity.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/server/TPSServlet.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/token/TokenDatabase.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java delete mode 100644 base/tps-tomcat/src/org/dogtagpki/tps/token/TokenService.java diff --git a/base/common/src/com/netscape/certsrv/token/TokenClient.java b/base/common/src/com/netscape/certsrv/token/TokenClient.java deleted file mode 100644 index d6fbd4e1f..000000000 --- a/base/common/src/com/netscape/certsrv/token/TokenClient.java +++ /dev/null @@ -1,70 +0,0 @@ -//--- 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.token; - -import java.net.URISyntaxException; - -import org.jboss.resteasy.client.ClientResponse; - -import com.netscape.certsrv.client.Client; -import com.netscape.certsrv.client.PKIClient; - -/** - * @author Endi S. Dewata - */ -public class TokenClient extends Client { - - public TokenResource resource; - - public TokenClient(PKIClient client) throws URISyntaxException { - this(client, client.getSubsystem()); - } - - public TokenClient(PKIClient client, String subsystem) throws URISyntaxException { - super(client, subsystem, "token"); - init(); - } - - public void init() throws URISyntaxException { - resource = createProxy(TokenResource.class); - } - - public TokenCollection findTokens(Integer start, Integer size) { - return resource.findTokens(start, size); - } - - public TokenData getToken(String tokenID) { - return resource.getToken(tokenID); - } - - public TokenData addToken(TokenData tokenData) { - @SuppressWarnings("unchecked") - ClientResponse response = (ClientResponse)resource.addToken(tokenData); - return client.getEntity(response); - } - - public TokenData updateToken(String tokenID, TokenData tokenData) { - @SuppressWarnings("unchecked") - ClientResponse response = (ClientResponse)resource.updateToken(tokenID, tokenData); - return client.getEntity(response); - } - - public void removeToken(String tokenID) { - resource.removeToken(tokenID); - } -} diff --git a/base/common/src/com/netscape/certsrv/token/TokenCollection.java b/base/common/src/com/netscape/certsrv/token/TokenCollection.java deleted file mode 100644 index e5de21f74..000000000 --- a/base/common/src/com/netscape/certsrv/token/TokenCollection.java +++ /dev/null @@ -1,38 +0,0 @@ -// --- 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.token; - -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="Tokens") -public class TokenCollection extends DataCollection { - - @XmlElementRef - public Collection getEntries() { - return super.getEntries(); - } -} diff --git a/base/common/src/com/netscape/certsrv/token/TokenData.java b/base/common/src/com/netscape/certsrv/token/TokenData.java deleted file mode 100644 index 9dc8a9cec..000000000 --- a/base/common/src/com/netscape/certsrv/token/TokenData.java +++ /dev/null @@ -1,219 +0,0 @@ -// --- 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.token; - -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="Token") -public class TokenData { - - public static Marshaller marshaller; - public static Unmarshaller unmarshaller; - - static { - try { - marshaller = JAXBContext.newInstance(TokenData.class).createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - unmarshaller = JAXBContext.newInstance(TokenData.class).createUnmarshaller(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - String id; - String userID; - String status; - String reason; - String appletID; - String keyInfo; - Date createTimestamp; - Date modifyTimestamp; - - Link link; - - @XmlAttribute(name="id") - public String getID() { - return id; - } - - public void setID(String id) { - this.id = id; - } - - @XmlElement(name="UserID") - public String getUserID() { - return userID; - } - - public void setUserID(String userID) { - this.userID = userID; - } - - @XmlElement(name="Status") - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - @XmlElement(name="Reason") - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - @XmlElement(name="AppletID") - public String getAppletID() { - return appletID; - } - - public void setAppletID(String appletID) { - this.appletID = appletID; - } - - @XmlElement(name="KeyInfo") - public String getKeyInfo() { - return keyInfo; - } - - public void setKeyInfo(String keyInfo) { - this.keyInfo = keyInfo; - } - - @XmlElement(name="CreateTimestamp") - public Date getCreateTimestamp() { - return createTimestamp; - } - - public void setCreateTimestamp(Date createTimestamp) { - this.createTimestamp = createTimestamp; - } - - @XmlElement(name="ModifyTimestamp") - public Date getModifyTimestamp() { - return modifyTimestamp; - } - - public void setModifyTimestamp(Date modifyTimestamp) { - this.modifyTimestamp = modifyTimestamp; - } - - @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; - TokenData other = (TokenData) 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 TokenData valueOf(String string) throws Exception { - try { - return (TokenData)unmarshaller.unmarshal(new StringReader(string)); - } catch (Exception e) { - return null; - } - } - - 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)); - } -} diff --git a/base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java b/base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java deleted file mode 100644 index bf0c4b6ea..000000000 --- a/base/common/src/com/netscape/certsrv/token/TokenModifyRequest.java +++ /dev/null @@ -1,152 +0,0 @@ -// --- 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.token; - -import java.io.StringReader; -import java.io.StringWriter; - -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="TokenModifyRequest") -public class TokenModifyRequest { - - public static Marshaller marshaller; - public static Unmarshaller unmarshaller; - - static { - try { - marshaller = JAXBContext.newInstance(TokenModifyRequest.class).createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - unmarshaller = JAXBContext.newInstance(TokenModifyRequest.class).createUnmarshaller(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - String id; - String userID; - - Link link; - - @XmlAttribute(name="id") - public String getID() { - return id; - } - - public void setID(String id) { - this.id = id; - } - - @XmlElement(name="UserID") - public String getUserID() { - return userID; - } - - public void setUserID(String userID) { - this.userID = userID; - } - - @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; - TokenModifyRequest other = (TokenModifyRequest) 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 TokenModifyRequest valueOf(String string) throws Exception { - try { - return (TokenModifyRequest)unmarshaller.unmarshal(new StringReader(string)); - } catch (Exception e) { - return null; - } - } - - public static void main(String args[]) throws Exception { - - TokenModifyRequest before = new TokenModifyRequest(); - before.setID("token1"); - before.setUserID("user1"); - - String string = before.toString(); - System.out.println(string); - - TokenModifyRequest after = TokenModifyRequest.valueOf(string); - System.out.println(before.equals(after)); - } -} diff --git a/base/common/src/com/netscape/certsrv/token/TokenResource.java b/base/common/src/com/netscape/certsrv/token/TokenResource.java deleted file mode 100644 index 8fe733d88..000000000 --- a/base/common/src/com/netscape/certsrv/token/TokenResource.java +++ /dev/null @@ -1,80 +0,0 @@ -// --- 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.token; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -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; -import javax.ws.rs.core.Response; - -import org.jboss.resteasy.annotations.ClientResponseType; - - -/** - * @author Endi S. Dewata - */ -@Path("tokens") -public interface TokenResource { - - @GET - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public TokenCollection findTokens( - @QueryParam("start") Integer start, - @QueryParam("size") Integer size); - - @GET - @Path("{tokenID}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public TokenData getToken(@PathParam("tokenID") String tokenID); - - @POST - @ClientResponseType(entityType=TokenData.class) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response addToken(TokenData tokenData); - - @PUT - @Path("{tokenID}") - @ClientResponseType(entityType=TokenData.class) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response updateToken( - @PathParam("tokenID") String tokenID, - TokenData tokenData); - - @POST - @Path("{tokenID}") - @ClientResponseType(entityType=TokenData.class) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response modifyToken( - @PathParam("tokenID") String tokenID, - TokenModifyRequest request); - - @DELETE - @Path("{tokenID}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public void removeToken(@PathParam("tokenID") String tokenID); -} diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java index 65a1997ba..94a906cdf 100644 --- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java +++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java @@ -23,8 +23,8 @@ import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.client.SubsystemClient; import com.netscape.certsrv.group.GroupClient; import com.netscape.certsrv.logging.ActivityClient; -import com.netscape.certsrv.token.TokenClient; import com.netscape.certsrv.tps.cert.TPSCertClient; +import com.netscape.certsrv.tps.token.TokenClient; import com.netscape.certsrv.user.UserClient; /** diff --git a/base/common/src/com/netscape/certsrv/tps/TPSConnection.java b/base/common/src/com/netscape/certsrv/tps/TPSConnection.java new file mode 100644 index 000000000..00e201c25 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/TPSConnection.java @@ -0,0 +1,98 @@ +// --- 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.tps; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +/** + * @author Endi S. Dewata + */ +public class TPSConnection { + + public InputStream in; + public PrintStream out; + public boolean chunked; + + public TPSConnection(InputStream in, OutputStream out) { + this(in, out, false); + } + + public TPSConnection(InputStream in, OutputStream out, boolean chunked) { + this.in = in; + this.out = new PrintStream(out); + this.chunked = chunked; + } + + public TPSMessage read() throws IOException { + + StringBuilder sb = new StringBuilder(); + int b; + + // read the first parameter + while ((b = in.read()) >= 0) { + char c = (char)b; + if (c == '&') break; + sb.append(c); + } + + if (b < 0) throw new IOException("Unexpected end of stream"); + + // parse message size + String nvp = sb.toString(); + String[] s = nvp.split("="); + int size = Integer.parseInt(s[1]); + + sb.append('&'); + + // read the rest of message + for (int i=0; i + */ +public class TPSMessage { + + Map map = new LinkedHashMap(); + + public TPSMessage() { + } + + public TPSMessage(String message) { + decode(message); + } + + public TPSMessage(Map map) { + this.map.putAll(map); + } + + public void put(String key, String value) { + map.put(key, value); + } + + public void put(String key, Integer value) { + map.put(key, value.toString()); + } + + public void put(String key, byte[] bytes) { + StringBuilder sb = new StringBuilder(); + + for (byte b : bytes) { + sb.append("%"); + sb.append(String.format("%02X", b)); + } + + map.put(key, sb.toString()); + } + + public void decode(String message) { + + for (String nvp : message.split("&")) { + String[] s = nvp.split("="); + + String key = s[0]; + String value = s[1]; + + // skip message size + if (key.equals("s")) continue; + + map.put(key, value); + } + } + + public String encode() { + + StringBuilder sb = new StringBuilder(); + + // encode message type + String type = map.get("msg_type"); + sb.append("msg_type=" + type); + + // encode other parameters + for (String key : map.keySet()) { + + if (key.equals("msg_type")) continue; + + String value = map.get(key); + sb.append("&" + key + "=" + value); + } + + String message = sb.toString(); + + // encode message_size + return "s=" + message.length() + "&" + message; + } + + public String toString() { + return map.toString(); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java new file mode 100644 index 000000000..48bddded6 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.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 com.netscape.certsrv.tps.token; + +import java.net.URISyntaxException; + +import org.jboss.resteasy.client.ClientResponse; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Endi S. Dewata + */ +public class TokenClient extends Client { + + public TokenResource resource; + + public TokenClient(PKIClient client) throws URISyntaxException { + this(client, client.getSubsystem()); + } + + public TokenClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "token"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(TokenResource.class); + } + + public TokenCollection findTokens(Integer start, Integer size) { + return resource.findTokens(start, size); + } + + public TokenData getToken(String tokenID) { + return resource.getToken(tokenID); + } + + public TokenData addToken(TokenData tokenData) { + @SuppressWarnings("unchecked") + ClientResponse response = (ClientResponse)resource.addToken(tokenData); + return client.getEntity(response); + } + + public TokenData updateToken(String tokenID, TokenData tokenData) { + @SuppressWarnings("unchecked") + ClientResponse response = (ClientResponse)resource.updateToken(tokenID, tokenData); + return client.getEntity(response); + } + + public void removeToken(String tokenID) { + resource.removeToken(tokenID); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java b/base/common/src/com/netscape/certsrv/tps/token/TokenCollection.java new file mode 100644 index 000000000..8af483b8a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenCollection.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.tps.token; + +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="Tokens") +public class TokenCollection extends DataCollection { + + @XmlElementRef + public Collection getEntries() { + return super.getEntries(); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenData.java b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java new file mode 100644 index 000000000..cbd8275b2 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenData.java @@ -0,0 +1,219 @@ +// --- 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.tps.token; + +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="Token") +public class TokenData { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(TokenData.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(TokenData.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String userID; + String status; + String reason; + String appletID; + String keyInfo; + Date createTimestamp; + Date modifyTimestamp; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="UserID") + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Reason") + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + @XmlElement(name="AppletID") + public String getAppletID() { + return appletID; + } + + public void setAppletID(String appletID) { + this.appletID = appletID; + } + + @XmlElement(name="KeyInfo") + public String getKeyInfo() { + return keyInfo; + } + + public void setKeyInfo(String keyInfo) { + this.keyInfo = keyInfo; + } + + @XmlElement(name="CreateTimestamp") + public Date getCreateTimestamp() { + return createTimestamp; + } + + public void setCreateTimestamp(Date createTimestamp) { + this.createTimestamp = createTimestamp; + } + + @XmlElement(name="ModifyTimestamp") + public Date getModifyTimestamp() { + return modifyTimestamp; + } + + public void setModifyTimestamp(Date modifyTimestamp) { + this.modifyTimestamp = modifyTimestamp; + } + + @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; + TokenData other = (TokenData) 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 TokenData valueOf(String string) throws Exception { + try { + return (TokenData)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + 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)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java b/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java new file mode 100644 index 000000000..b4168261f --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenModifyRequest.java @@ -0,0 +1,152 @@ +// --- 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.tps.token; + +import java.io.StringReader; +import java.io.StringWriter; + +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="TokenModifyRequest") +public class TokenModifyRequest { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(TokenModifyRequest.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(TokenModifyRequest.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String userID; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="UserID") + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + @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; + TokenModifyRequest other = (TokenModifyRequest) 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 TokenModifyRequest valueOf(String string) throws Exception { + try { + return (TokenModifyRequest)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + TokenModifyRequest before = new TokenModifyRequest(); + before.setID("token1"); + before.setUserID("user1"); + + String string = before.toString(); + System.out.println(string); + + TokenModifyRequest after = TokenModifyRequest.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java new file mode 100644 index 000000000..5f98845e3 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java @@ -0,0 +1,80 @@ +// --- 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.tps.token; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +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; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + + +/** + * @author Endi S. Dewata + */ +@Path("tokens") +public interface TokenResource { + + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public TokenCollection findTokens( + @QueryParam("start") Integer start, + @QueryParam("size") Integer size); + + @GET + @Path("{tokenID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public TokenData getToken(@PathParam("tokenID") String tokenID); + + @POST + @ClientResponseType(entityType=TokenData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response addToken(TokenData tokenData); + + @PUT + @Path("{tokenID}") + @ClientResponseType(entityType=TokenData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response updateToken( + @PathParam("tokenID") String tokenID, + TokenData tokenData); + + @POST + @Path("{tokenID}") + @ClientResponseType(entityType=TokenData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response modifyToken( + @PathParam("tokenID") String tokenID, + TokenModifyRequest request); + + @DELETE + @Path("{tokenID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public void removeToken(@PathParam("tokenID") String tokenID); +} 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 8f740662c..2f28ada7d 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java @@ -22,8 +22,8 @@ import com.netscape.certsrv.client.Client; import com.netscape.certsrv.tps.TPSClient; import com.netscape.cmstools.group.GroupCLI; import com.netscape.cmstools.logging.ActivityCLI; -import com.netscape.cmstools.token.TokenCLI; import com.netscape.cmstools.tps.cert.TPSCertCLI; +import com.netscape.cmstools.tps.token.TokenCLI; import com.netscape.cmstools.user.UserCLI; /** diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java deleted file mode 100644 index 10405a906..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenAddCLI.java +++ /dev/null @@ -1,81 +0,0 @@ -// --- 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.token; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenAddCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenAddCLI(TokenCLI tokenCLI) { - super("add", "Add token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void execute(String[] args) throws Exception { - - Option option = new Option(null, "user", true, "User ID"); - option.setArgName("User ID"); - option.setRequired(true); - 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 != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = cmdArgs[0]; - - TokenData tokenData = new TokenData(); - tokenData.setID(tokenID); - tokenData.setUserID(cmd.getOptionValue("user")); - - tokenData = tokenCLI.tokenClient.addToken(tokenData); - - MainCLI.printMessage("Added token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java deleted file mode 100644 index 14e54af3d..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenCLI.java +++ /dev/null @@ -1,90 +0,0 @@ -// --- 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.token; - -import java.util.Arrays; - -import org.jboss.resteasy.plugins.providers.atom.Link; - -import com.netscape.certsrv.token.TokenClient; -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; - -/** - * @author Endi S. Dewata - */ -public class TokenCLI extends CLI { - - public TokenClient tokenClient; - - public TokenCLI(CLI parent) { - super("token", "Token management commands", parent); - - addModule(new TokenAddCLI(this)); - addModule(new TokenFindCLI(this)); - addModule(new TokenModifyCLI(this)); - addModule(new TokenRemoveCLI(this)); - addModule(new TokenShowCLI(this)); - } - - public void execute(String[] args) throws Exception { - - client = parent.getClient(); - tokenClient = (TokenClient)parent.getClient("token"); - - 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 printToken(TokenData token) { - System.out.println(" Token ID: " + token.getID()); - if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID()); - if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); - if (token.getReason() != null) System.out.println(" Reason: " + token.getReason()); - if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); - if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); - if (token.getCreateTimestamp() != null) System.out.println(" Date Created: " + token.getCreateTimestamp()); - if (token.getModifyTimestamp() != null) System.out.println(" Date Modified: " + token.getModifyTimestamp()); - - Link link = token.getLink(); - if (verbose && link != null) { - System.out.println(" Link: " + link.getHref()); - } - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java deleted file mode 100644 index b1fa04f47..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenFindCLI.java +++ /dev/null @@ -1,94 +0,0 @@ -// --- 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.token; - -import java.util.Collection; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenCollection; -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenFindCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenFindCLI(TokenCLI tokenCLI) { - super("find", "Find tokens", tokenCLI); - this.tokenCLI = tokenCLI; - } - - 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); - - TokenCollection result = tokenCLI.tokenClient.findTokens(start, size); - Collection tokens = result.getEntries(); - - MainCLI.printMessage(tokens.size() + " token(s) matched"); - - boolean first = true; - - for (TokenData tokenData : tokens) { - - if (first) { - first = false; - } else { - System.out.println(); - } - - TokenCLI.printToken(tokenData); - } - - MainCLI.printMessage("Number of entries returned " + tokens.size()); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java deleted file mode 100644 index 29f1a0741..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenModifyCLI.java +++ /dev/null @@ -1,81 +0,0 @@ -// --- 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.token; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenModifyCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenModifyCLI(TokenCLI tokenCLI) { - super("mod", "Modify token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void execute(String[] args) throws Exception { - - Option option = new Option(null, "user", true, "User ID"); - option.setArgName("User ID"); - option.setRequired(true); - 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 != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = cmdArgs[0]; - - TokenData tokenData = new TokenData(); - tokenData.setID(tokenID); - tokenData.setUserID(cmd.getOptionValue("user")); - - tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData); - - MainCLI.printMessage("Modified token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java deleted file mode 100644 index 4e986313c..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenRemoveCLI.java +++ /dev/null @@ -1,53 +0,0 @@ -// --- 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.token; - -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenRemoveCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenRemoveCLI(TokenCLI tokenCLI) { - super("del", "Remove token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " ", options); - } - - public void execute(String[] args) throws Exception { - - if (args.length != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = args[0]; - - tokenCLI.tokenClient.removeToken(tokenID); - - MainCLI.printMessage("Deleted token \"" + tokenID + "\""); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java deleted file mode 100644 index 4f074f60f..000000000 --- a/base/java-tools/src/com/netscape/cmstools/token/TokenShowCLI.java +++ /dev/null @@ -1,56 +0,0 @@ -// --- 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.token; - -import com.netscape.certsrv.token.TokenData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class TokenShowCLI extends CLI { - - public TokenCLI tokenCLI; - - public TokenShowCLI(TokenCLI tokenCLI) { - super("show", "Show token", tokenCLI); - this.tokenCLI = tokenCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " ", options); - } - - public void execute(String[] args) throws Exception { - - if (args.length != 1) { - printHelp(); - System.exit(1); - } - - String tokenID = args[0]; - - TokenData tokenData = tokenCLI.tokenClient.getToken(tokenID); - - MainCLI.printMessage("Token \"" + tokenID + "\""); - - TokenCLI.printToken(tokenData); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java new file mode 100644 index 000000000..0d495ddc7 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java @@ -0,0 +1,81 @@ +// --- 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.tps.token; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenAddCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenAddCLI(TokenCLI tokenCLI) { + super("add", "Add token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "user", true, "User ID"); + option.setArgName("User ID"); + option.setRequired(true); + 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 != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = cmdArgs[0]; + + TokenData tokenData = new TokenData(); + tokenData.setID(tokenID); + tokenData.setUserID(cmd.getOptionValue("user")); + + tokenData = tokenCLI.tokenClient.addToken(tokenData); + + MainCLI.printMessage("Added token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java new file mode 100644 index 000000000..16c2b213b --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java @@ -0,0 +1,90 @@ +// --- 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.tps.token; + +import java.util.Arrays; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.tps.token.TokenClient; +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; + +/** + * @author Endi S. Dewata + */ +public class TokenCLI extends CLI { + + public TokenClient tokenClient; + + public TokenCLI(CLI parent) { + super("token", "Token management commands", parent); + + addModule(new TokenAddCLI(this)); + addModule(new TokenFindCLI(this)); + addModule(new TokenModifyCLI(this)); + addModule(new TokenRemoveCLI(this)); + addModule(new TokenShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + tokenClient = (TokenClient)parent.getClient("token"); + + 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 printToken(TokenData token) { + System.out.println(" Token ID: " + token.getID()); + if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID()); + if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus()); + if (token.getReason() != null) System.out.println(" Reason: " + token.getReason()); + if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID()); + if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo()); + if (token.getCreateTimestamp() != null) System.out.println(" Date Created: " + token.getCreateTimestamp()); + if (token.getModifyTimestamp() != null) System.out.println(" Date Modified: " + token.getModifyTimestamp()); + + Link link = token.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java new file mode 100644 index 000000000..3ade40bb9 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.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.tps.token; + +import java.util.Collection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenCollection; +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenFindCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenFindCLI(TokenCLI tokenCLI) { + super("find", "Find tokens", tokenCLI); + this.tokenCLI = tokenCLI; + } + + 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); + + TokenCollection result = tokenCLI.tokenClient.findTokens(start, size); + Collection tokens = result.getEntries(); + + MainCLI.printMessage(tokens.size() + " token(s) matched"); + + boolean first = true; + + for (TokenData tokenData : tokens) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + TokenCLI.printToken(tokenData); + } + + MainCLI.printMessage("Number of entries returned " + tokens.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java new file mode 100644 index 000000000..28559e163 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java @@ -0,0 +1,81 @@ +// --- 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.tps.token; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenModifyCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenModifyCLI(TokenCLI tokenCLI) { + super("mod", "Modify token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "user", true, "User ID"); + option.setArgName("User ID"); + option.setRequired(true); + 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 != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = cmdArgs[0]; + + TokenData tokenData = new TokenData(); + tokenData.setID(tokenID); + tokenData.setUserID(cmd.getOptionValue("user")); + + tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData); + + MainCLI.printMessage("Modified token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java new file mode 100644 index 000000000..f522991cb --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java @@ -0,0 +1,53 @@ +// --- 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.tps.token; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenRemoveCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenRemoveCLI(TokenCLI tokenCLI) { + super("del", "Remove token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = args[0]; + + tokenCLI.tokenClient.removeToken(tokenID); + + MainCLI.printMessage("Deleted token \"" + tokenID + "\""); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java new file mode 100644 index 000000000..14190ef01 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.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.tps.token; + +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TokenShowCLI extends CLI { + + public TokenCLI tokenCLI; + + public TokenShowCLI(TokenCLI tokenCLI) { + super("show", "Show token", tokenCLI); + this.tokenCLI = tokenCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " ", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String tokenID = args[0]; + + TokenData tokenData = tokenCLI.tokenClient.getToken(tokenID); + + MainCLI.printMessage("Token \"" + tokenID + "\""); + + TokenCLI.printToken(tokenData); + } +} diff --git a/base/tps-tomcat/shared/conf/CS.cfg.in b/base/tps-tomcat/shared/conf/CS.cfg.in index 087ab483b..02ab97415 100644 --- a/base/tps-tomcat/shared/conf/CS.cfg.in +++ b/base/tps-tomcat/shared/conf/CS.cfg.in @@ -1380,8 +1380,8 @@ selftests._005=## tps.cert.list = selftests._006=## tps.cert..nickname selftests._007=## tps.cert..certusage selftests._008=## -selftests.container.instance.TPSPresence=org.dogtagpki.tps.selftests.TPSPresence -selftests.container.instance.TPSValidity=org.dogtagpki.tps.selftests.TPSValidity +selftests.container.instance.TPSPresence=org.dogtagpki.server.tps.selftests.TPSPresence +selftests.container.instance.TPSValidity=org.dogtagpki.server.tps.selftests.TPSValidity selftests.container.instance.SystemCertsVerification=com.netscape.cms.selftests.common.SystemCertsVerification selftests.container.logger.bufferSize=512 selftests.container.logger.class=com.netscape.cms.logging.RollingLogFile @@ -1407,7 +1407,7 @@ service.securePort=[PKI_AGENT_SECURE_PORT] service.unsecurePort=[PKI_UNSECURE_PORT] smtp.host=localhost smtp.port=25 -subsystem.0.class=org.dogtagpki.tps.server.TPSSubsystem +subsystem.0.class=org.dogtagpki.server.tps.TPSSubsystem subsystem.0.id=tps subsystem.1.class=com.netscape.cmscore.selftests.SelfTestSubsystem subsystem.1.id=selftests diff --git a/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml b/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml index 6e6aafb99..69316fa54 100644 --- a/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml +++ b/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml @@ -97,7 +97,7 @@ tps - org.dogtagpki.tps.server.TPSServlet + org.dogtagpki.server.tps.TPSServlet @@ -119,7 +119,7 @@ org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher javax.ws.rs.Application - org.dogtagpki.tps.server.TPSApplication + org.dogtagpki.server.tps.TPSApplication diff --git a/base/tps-tomcat/src/CMakeLists.txt b/base/tps-tomcat/src/CMakeLists.txt index 2c9af352a..4798d2004 100644 --- a/base/tps-tomcat/src/CMakeLists.txt +++ b/base/tps-tomcat/src/CMakeLists.txt @@ -96,7 +96,7 @@ find_file(SYMKEY_JAR # build pki-tps javac(pki-tps-classes SOURCES - org/dogtagpki/tps/*.java + org/dogtagpki/server/tps/*.java CLASSPATH ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSUTIL_JAR} ${PKI_NSUTIL_JAR} @@ -123,7 +123,7 @@ jar(pki-tps-jar INPUT_DIR ${CMAKE_BINARY_DIR}/classes FILES - org/dogtagpki/tps/*.class + org/dogtagpki/server/tps/*.class DEPENDS pki-tps-classes ) diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java new file mode 100644 index 000000000..b0eac50f8 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java @@ -0,0 +1,92 @@ +// --- 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.server.tps; + +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.core.Application; + +import org.dogtagpki.server.tps.cert.TPSCertService; +import org.dogtagpki.server.tps.logging.ActivityService; +import org.dogtagpki.server.tps.token.TokenService; + +import com.netscape.certsrv.base.PKIException; +import com.netscape.cms.authorization.ACLInterceptor; +import com.netscape.cms.authorization.AuthMethodInterceptor; +import com.netscape.cms.servlet.account.AccountService; +import com.netscape.cms.servlet.admin.GroupMemberService; +import com.netscape.cms.servlet.admin.GroupService; +import com.netscape.cms.servlet.admin.SystemCertService; +import com.netscape.cms.servlet.admin.UserCertService; +import com.netscape.cms.servlet.admin.UserMembershipService; +import com.netscape.cms.servlet.admin.UserService; +import com.netscape.cms.servlet.csadmin.SystemConfigService; + +/** + * @author Endi S. Dewata + */ +public class TPSApplication extends Application { + + private Set singletons = new HashSet(); + private Set> classes = new HashSet>(); + + public TPSApplication() { + + // account + classes.add(AccountService.class); + + // installer + classes.add(SystemConfigService.class); + + // user and group management + classes.add(GroupMemberService.class); + classes.add(GroupService.class); + classes.add(UserCertService.class); + classes.add(UserMembershipService.class); + classes.add(UserService.class); + + // system certs + classes.add(SystemCertService.class); + + // activities + classes.add(ActivityService.class); + + // certificates + classes.add(TPSCertService.class); + + // tokens + classes.add(TokenService.class); + + // exception mapper + classes.add(PKIException.Mapper.class); + + // interceptors + singletons.add(new AuthMethodInterceptor()); + singletons.add(new ACLInterceptor()); + } + + public Set> getClasses() { + return classes; + } + + public Set getSingletons() { + return singletons; + } + +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java new file mode 100644 index 000000000..4fcec9dee --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSServlet.java @@ -0,0 +1,61 @@ +// --- 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.server.tps; + +import java.io.IOException; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.netscape.certsrv.tps.TPSConnection; +import com.netscape.certsrv.tps.TPSMessage; + +/** + * @author Endi S. Dewata + */ +public class TPSServlet extends HttpServlet { + + private static final long serialVersionUID = -1092227495262381074L; + + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { + + response.setHeader("Transfer-Encoding", "chunked"); + + TPSConnection con = new TPSConnection( + request.getInputStream(), response.getOutputStream(), true); + + TPSMessage message = con.read(); + System.out.println("Receive: " + message); + + message = new TPSMessage(); + message.put("msg_type", 9); + message.put("pdu_size", 12); + message.put("pdu_data", new byte[] { + (byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, + (byte)0x07, (byte)0xA0, (byte)0x00, (byte)0x00, + (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00 + }); + + System.out.println("Send: " + message); + con.write(message); + + message = con.read(); + System.out.println("Receive: " + message); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java new file mode 100644 index 000000000..5c27c1233 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.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.server.tps; + +import org.dogtagpki.server.tps.cert.TPSCertDatabase; +import org.dogtagpki.server.tps.logging.ActivityDatabase; +import org.dogtagpki.server.tps.token.TokenDatabase; +import org.mozilla.jss.CryptoManager; +import org.mozilla.jss.CryptoManager.NotInitializedException; +import org.mozilla.jss.crypto.ObjectNotFoundException; +import org.mozilla.jss.crypto.TokenException; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.authority.IAuthority; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.base.ISubsystem; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.request.IRequestListener; +import com.netscape.certsrv.request.IRequestQueue; + +/** + * @author Endi S. Dewata + */ +public class TPSSubsystem implements IAuthority, ISubsystem { + + public final static TPSSubsystem INSTANCE = new TPSSubsystem(); + + public ILogger logger = CMS.getLogger(); + + public String id; + public String nickname; + public ISubsystem owner; + public IConfigStore config; + + public ActivityDatabase activityDatabase = new ActivityDatabase(); + public TPSCertDatabase certDatabase = new TPSCertDatabase(); + public TokenDatabase tokenDatabase = new TokenDatabase(); + + public static TPSSubsystem getInstance() { + return INSTANCE; + } + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) throws EBaseException { + this.id = id; + } + + @Override + public void init(ISubsystem owner, IConfigStore config) throws EBaseException { + this.owner = owner; + this.config = config; + } + + @Override + public void startup() throws EBaseException { + } + + @Override + public void shutdown() { + } + + @Override + public IConfigStore getConfigStore() { + return config; + } + + @Override + public IRequestQueue getRequestQueue() { + return null; + } + + @Override + public void registerRequestListener(IRequestListener listener) { + } + + @Override + public void registerPendingListener(IRequestListener listener) { + } + + @Override + public void log(int level, String msg) { + logger.log(ILogger.EV_SYSTEM, ILogger.S_TPS, level, msg); + } + + @Override + public String getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + @Override + public String getOfficialName() { + return "tps"; + } + + public ActivityDatabase getActivityDatabase() { + return activityDatabase; + } + + public TPSCertDatabase getCertDatabase() { + return certDatabase; + } + + public TokenDatabase getTokenDatabase() { + return tokenDatabase; + } + + public org.mozilla.jss.crypto.X509Certificate getSubsystemCert() throws EBaseException, NotInitializedException, + ObjectNotFoundException, TokenException { + IConfigStore cs = CMS.getConfigStore(); + String nickname = cs.getString("tps.subsystem.nickname", ""); + String tokenname = cs.getString("tps.subsystem.tokenname", ""); + if (!tokenname.equals("internal") && !tokenname.equals("Internal Key Storage Token")) + nickname = tokenname + ":" + nickname; + + CryptoManager cm = CryptoManager.getInstance(); + return cm.findCertByNickname(nickname); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertDatabase.java new file mode 100644 index 000000000..274ef0ec2 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertDatabase.java @@ -0,0 +1,76 @@ +// --- 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.server.tps.cert; + +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 TPSCertDatabase extends Database { + + public TPSCertDatabase() { + super("Certificate"); + + // add sample records + try { + TPSCertRecord record1 = new TPSCertRecord(); + record1.setID("cert1"); + record1.setSerialNumber("16"); + record1.setSubject("cn=someone"); + record1.setTokenID("TOKEN0001"); + record1.setKeyType("something"); + record1.setStatus("active"); + record1.setUserID("user1"); + record1.setCreateTime(new Date()); + record1.setModifyTime(new Date()); + addRecord(record1); + + TPSCertRecord record2 = new TPSCertRecord(); + record2.setID("cert2"); + record2.setSerialNumber("17"); + record2.setSubject("cn=someone"); + record2.setTokenID("TOKEN0002"); + record2.setKeyType("something"); + record2.setStatus("revoked"); + record2.setUserID("user2"); + record2.setCreateTime(new Date()); + record2.setModifyTime(new Date()); + addRecord(record2); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void addRecord(TPSCertRecord certRecord) throws Exception { + certRecord.setCreateTime(new Date()); + + addRecord(certRecord.getID(), certRecord); + } + + public void updateRecord(TPSCertRecord certRecord) throws Exception { + updateRecord(certRecord.getID(), certRecord); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertRecord.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertRecord.java new file mode 100644 index 000000000..26b2c156d --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertRecord.java @@ -0,0 +1,288 @@ +// --- 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.server.tps.cert; + +import java.util.Date; + +/** + * @author Endi S. Dewata + */ +public class TPSCertRecord { + + String id; + String serialNumber; + String subject; + String tokenID; + String keyType; + String status; + String userID; + String certificate; + String issuedBy; + String origin; + String type; + Date validNotBefore; + Date validNotAfter; + String extensions; + Date createTime; + Date modifyTime; + + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getTokenID() { + return tokenID; + } + + public void setTokenID(String tokenID) { + this.tokenID = tokenID; + } + + public String getKeyType() { + return keyType; + } + + public void setKeyType(String keyType) { + this.keyType = keyType; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + + public String getCertificate() { + return certificate; + } + + public void setCertificate(String certificate) { + this.certificate = certificate; + } + + public String getIssuedBy() { + return issuedBy; + } + + public void setIssuedBy(String issuedBy) { + this.issuedBy = issuedBy; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Date getValidNotBefore() { + return validNotBefore; + } + + public void setValidNotBefore(Date validNotBefore) { + this.validNotBefore = validNotBefore; + } + + public Date getValidNotAfter() { + return validNotAfter; + } + + public void setValidNotAfter(Date validNotAfter) { + this.validNotAfter = validNotAfter; + } + + public String getExtensions() { + return extensions; + } + + public void setExtensions(String extensions) { + this.extensions = extensions; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Date modifyTime) { + this.modifyTime = modifyTime; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((certificate == null) ? 0 : certificate.hashCode()); + result = prime * result + ((createTime == null) ? 0 : createTime.hashCode()); + result = prime * result + ((extensions == null) ? 0 : extensions.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((issuedBy == null) ? 0 : issuedBy.hashCode()); + result = prime * result + ((keyType == null) ? 0 : keyType.hashCode()); + result = prime * result + ((modifyTime == null) ? 0 : modifyTime.hashCode()); + result = prime * result + ((origin == null) ? 0 : origin.hashCode()); + result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((subject == null) ? 0 : subject.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()); + result = prime * result + ((validNotAfter == null) ? 0 : validNotAfter.hashCode()); + result = prime * result + ((validNotBefore == null) ? 0 : validNotBefore.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; + TPSCertRecord other = (TPSCertRecord) obj; + if (certificate == null) { + if (other.certificate != null) + return false; + } else if (!certificate.equals(other.certificate)) + return false; + if (createTime == null) { + if (other.createTime != null) + return false; + } else if (!createTime.equals(other.createTime)) + 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 (issuedBy == null) { + if (other.issuedBy != null) + return false; + } else if (!issuedBy.equals(other.issuedBy)) + return false; + if (keyType == null) { + if (other.keyType != null) + return false; + } else if (!keyType.equals(other.keyType)) + return false; + if (modifyTime == null) { + if (other.modifyTime != null) + return false; + } else if (!modifyTime.equals(other.modifyTime)) + return false; + if (origin == null) { + if (other.origin != null) + return false; + } else if (!origin.equals(other.origin)) + return false; + if (serialNumber == null) { + if (other.serialNumber != null) + return false; + } else if (!serialNumber.equals(other.serialNumber)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (subject == null) { + if (other.subject != null) + return false; + } else if (!subject.equals(other.subject)) + 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; + if (validNotAfter == null) { + if (other.validNotAfter != null) + return false; + } else if (!validNotAfter.equals(other.validNotAfter)) + return false; + if (validNotBefore == null) { + if (other.validNotBefore != null) + return false; + } else if (!validNotBefore.equals(other.validNotBefore)) + return false; + return true; + } +} 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 new file mode 100644 index 000000000..e0534e3f5 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/cert/TPSCertService.java @@ -0,0 +1,152 @@ +// --- 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.server.tps.cert; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +import java.util.Iterator; + +import org.dogtagpki.server.tps.TPSSubsystem; +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.base.PKIException; +import com.netscape.certsrv.tps.cert.TPSCertCollection; +import com.netscape.certsrv.tps.cert.TPSCertData; +import com.netscape.certsrv.tps.cert.TPSCertResource; +import com.netscape.cms.servlet.base.PKIService; + +/** + * @author Endi S. Dewata + */ +public class TPSCertService extends PKIService implements TPSCertResource { + + public final static int DEFAULT_SIZE = 20; + + public TPSCertService() { + System.out.println("TPSCertService.()"); + } + + public TPSCertData createCertData(TPSCertRecord certRecord) { + + TPSCertData certData = new TPSCertData(); + certData.setID(certRecord.getID()); + certData.setSerialNumber(certRecord.getSerialNumber()); + certData.setSubject(certRecord.getSubject()); + certData.setTokenID(certRecord.getTokenID()); + certData.setKeyType(certRecord.getKeyType()); + certData.setStatus(certRecord.getStatus()); + certData.setUserID(certRecord.getUserID()); + certData.setCreateTime(certRecord.getCreateTime()); + certData.setModifyTime(certRecord.getModifyTime()); + + String certID = certRecord.getID(); + try { + certID = URLEncoder.encode(certID, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + + URI uri = uriInfo.getBaseUriBuilder().path(TPSCertResource.class).path("{certID}").build(certID); + certData.setLink(new Link("self", uri)); + + return certData; + } + + public TPSCertRecord createCertRecord(TPSCertData certData) { + + TPSCertRecord certRecord = new TPSCertRecord(); + certRecord.setID(certData.getID()); + certRecord.setSerialNumber(certData.getSerialNumber()); + certRecord.setSubject(certData.getSubject()); + certRecord.setTokenID(certData.getTokenID()); + certRecord.setKeyType(certData.getKeyType()); + certRecord.setStatus(certData.getStatus()); + certRecord.setUserID(certData.getUserID()); + certRecord.setCreateTime(certData.getCreateTime()); + certRecord.setModifyTime(certData.getModifyTime()); + + return certRecord; + } + + @Override + public TPSCertCollection findCerts(Integer start, Integer size) { + + System.out.println("TPSCertService.findCerts()"); + + try { + start = start == null ? 0 : start; + size = size == null ? DEFAULT_SIZE : size; + + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TPSCertDatabase database = subsystem.getCertDatabase(); + + Iterator activities = database.getRecords().iterator(); + + TPSCertCollection response = new TPSCertCollection(); + + int i = 0; + + // skip to the start of the page + for ( ; i 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 TPSCertData getCert(String certID) { + + System.out.println("TPSCertService.getCert(\"" + certID + "\")"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TPSCertDatabase database = subsystem.getCertDatabase(); + + return createCertData(database.getRecord(certID)); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityDatabase.java new file mode 100644 index 000000000..0b74e5fe4 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/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.server.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 { + + 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/server/tps/logging/ActivityRecord.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityRecord.java new file mode 100644 index 000000000..387a85f00 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/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.server.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/server/tps/logging/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/logging/ActivityService.java new file mode 100644 index 000000000..491447c61 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/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.server.tps.logging; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +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.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.()"); + } + + 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 activities = database.getRecords().iterator(); + + ActivityCollection response = new ActivityCollection(); + + int i = 0; + + // skip to the start of the page + for ( ; i 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/server/tps/selftests/TPSPresence.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSPresence.java new file mode 100644 index 000000000..65ac197e7 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSPresence.java @@ -0,0 +1,187 @@ +// --- 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.server.tps.selftests; + +import java.security.PublicKey; +import java.util.Locale; + +import org.dogtagpki.server.tps.TPSSubsystem; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.logging.ILogEventListener; +import com.netscape.certsrv.selftests.EDuplicateSelfTestException; +import com.netscape.certsrv.selftests.EInvalidSelfTestException; +import com.netscape.certsrv.selftests.EMissingSelfTestException; +import com.netscape.certsrv.selftests.ESelfTestException; +import com.netscape.certsrv.selftests.ISelfTestSubsystem; +import com.netscape.cms.selftests.ASelfTest; + +/** + * This class implements a self test to check for TPS presence. + *

+ * + * @author alee + * @version $Revision$, $Date$ + */ +public class TPSPresence extends ASelfTest { + + public static final String PROP_TPS_SUB_ID = "TpsSubId"; + private String tpsSubId = null; + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + *

+ * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest(ISelfTestSubsystem subsystem, String instanceName, + IConfigStore parameters) throws EDuplicateSelfTestException, EInvalidSelfTestException, + EMissingSelfTestException { + super.initSelfTest(subsystem, instanceName, parameters); + + try { + tpsSubId = mConfig.getString(PROP_TPS_SUB_ID); + if (tpsSubId != null) { + tpsSubId = tpsSubId.trim(); + } else { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_VALUES", getSelfTestName(), + mPrefix + "." + PROP_TPS_SUB_ID)); + + throw new EMissingSelfTestException(PROP_TPS_SUB_ID); + } + } catch (EBaseException e) { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_NAME", getSelfTestName(), + mPrefix + "." + PROP_TPS_SUB_ID)); + + throw new EMissingSelfTestException(mPrefix, PROP_TPS_SUB_ID, null); + } + } + + /** + * Notifies this subsystem if it is in execution mode. + *

+ * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() throws ESelfTestException { + } + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + *

+ */ + public void shutdownSelfTest() { + } + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been initialized. + *

+ * + * @return instanceName of this self test + */ + public String getSelfTestName() { + return super.getSelfTestName(); + } + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + *

+ * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() { + return super.getSelfTestConfigStore(); + } + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + *

+ * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription(Locale locale) { + return CMS.getUserMessage(locale, + "CMS_SELFTESTS_TPS_PRESENCE_DESCRIPTION"); + } + + /** + * Execute an individual self test. + *

+ * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest(ILogEventListener logger) + throws ESelfTestException { + String logMessage = null; + TPSSubsystem tps = (TPSSubsystem) CMS.getSubsystem(tpsSubId); + if (tps == null) { + // log that the TPS is not installed + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_PRESENT", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // Retrieve the TPS certificate + org.mozilla.jss.crypto.X509Certificate tpsCert = null; + try { + tpsCert = tps.getSubsystemCert(); + } catch (Exception e) { + e.printStackTrace(); + // cert does not exist or is not yet configured + // tpsCert will remain null + } + + if (tpsCert == null) { + // log that the TPS is not yet initialized + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_INITIALIZED", + getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // Retrieve the TPS certificate public key + PublicKey tpsPubKey = tpsCert.getPublicKey(); + if (tpsPubKey == null) { + // log that something is seriously wrong with the TPS + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_CORRUPT", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // log that the TPS is present + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_PRESENT", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSValidity.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSValidity.java new file mode 100644 index 000000000..f140d6e7c --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/selftests/TPSValidity.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.server.tps.selftests; + +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.util.Locale; + +import netscape.security.x509.X509CertImpl; + +import org.dogtagpki.server.tps.TPSSubsystem; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.logging.ILogEventListener; +import com.netscape.certsrv.selftests.EDuplicateSelfTestException; +import com.netscape.certsrv.selftests.EInvalidSelfTestException; +import com.netscape.certsrv.selftests.EMissingSelfTestException; +import com.netscape.certsrv.selftests.ESelfTestException; +import com.netscape.certsrv.selftests.ISelfTestSubsystem; +import com.netscape.cms.selftests.ASelfTest; + +/** + * This class implements a self test to check the validity of the TPS. + *

+ * + * @author alee + * @version $Revision$, $Date$ + */ +public class TPSValidity extends ASelfTest { + + // parameter information + public static final String PROP_TPS_SUB_ID = "TpsSubId"; + private String tpsSubId = null; + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + *

+ * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest(ISelfTestSubsystem subsystem, String instanceName, + IConfigStore parameters) throws EDuplicateSelfTestException, + EInvalidSelfTestException, EMissingSelfTestException { + super.initSelfTest(subsystem, instanceName, parameters); + + try { + tpsSubId = mConfig.getString(PROP_TPS_SUB_ID); + if (tpsSubId != null) { + tpsSubId = tpsSubId.trim(); + } else { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_VALUES", getSelfTestName(), + mPrefix + "." + PROP_TPS_SUB_ID)); + + throw new EMissingSelfTestException(PROP_TPS_SUB_ID); + } + } catch (EBaseException e) { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_NAME", getSelfTestName(), + mPrefix + "." + PROP_TPS_SUB_ID)); + + throw new EMissingSelfTestException(mPrefix, PROP_TPS_SUB_ID, null); + } + } + + /** + * Notifies this subsystem if it is in execution mode. + *

+ * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() throws ESelfTestException { + } + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + *

+ */ + public void shutdownSelfTest() { + } + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + *

+ * + * @return instanceName of this self test + */ + public String getSelfTestName() { + return super.getSelfTestName(); + } + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + *

+ * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() { + return super.getSelfTestConfigStore(); + } + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + *

+ * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription(Locale locale) { + return CMS.getUserMessage(locale, + "CMS_SELFTESTS_TPS_VALIDITY_DESCRIPTION"); + } + + /** + * Execute an individual self test. + *

+ * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest(ILogEventListener logger) + throws ESelfTestException { + String logMessage = null; + TPSSubsystem tps = (TPSSubsystem) CMS.getSubsystem(tpsSubId); + + if (tps == null) { + // log that the TPS is not installed + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_PRESENT", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // Retrieve the TPS subsystem certificate + X509CertImpl tpsCert = null; + try { + tpsCert = new X509CertImpl(tps.getSubsystemCert().getEncoded()); + } catch (Exception e) { + // certificate is not present or has not been configured + // tpsCert will remain null + } + + if (tpsCert == null) { + // log that the TPS is not yet initialized + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_INITIALIZED", + getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // Check the TPS validity period + try { + tpsCert.checkValidity(); + } catch (CertificateNotYetValidException e) { + // log that the TPS is not yet valid + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_YET_VALID", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } catch (CertificateExpiredException e) { + // log that the TPS is expired + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_EXPIRED", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + throw new ESelfTestException(logMessage); + } + + // log that the TPS is valid + logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_VALID", getSelfTestName()); + mSelfTestSubsystem.log(logger, logMessage); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenDatabase.java new file mode 100644 index 000000000..87d4cbc5b --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenDatabase.java @@ -0,0 +1,49 @@ +// --- 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.server.tps.token; + +import java.util.Date; + +import com.netscape.cmscore.dbs.Database; + +/** + * This class implements in-memory token database. In the future this + * will be replaced with LDAP database. + * + * @author Endi S. Dewata + */ +public class TokenDatabase extends Database { + + public TokenDatabase() { + super("Token"); + } + + public void addRecord(TokenRecord tokenRecord) throws Exception { + tokenRecord.setStatus("ENABLED"); + tokenRecord.setCreateTimestamp(new Date()); + + addRecord(tokenRecord.getID(), tokenRecord); + } + + public void updateRecord(TokenRecord tokenRecord) throws Exception { + tokenRecord.setModifyTimestamp(new Date()); + + updateRecord(tokenRecord.getID(), tokenRecord); + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenRecord.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenRecord.java new file mode 100644 index 000000000..ff3af5776 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenRecord.java @@ -0,0 +1,167 @@ +// --- 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.server.tps.token; + +import java.util.Date; + +/** + * @author Endi S. Dewata + */ +public class TokenRecord { + + String id; + String userID; + String status; + String reason; + String appletID; + String keyInfo; + Date createTimestamp; + Date modifyTimestamp; + + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public String getAppletID() { + return appletID; + } + + public void setAppletID(String appletID) { + this.appletID = appletID; + } + + public String getKeyInfo() { + return keyInfo; + } + + public void setKeyInfo(String keyInfo) { + this.keyInfo = keyInfo; + } + + public Date getCreateTimestamp() { + return createTimestamp; + } + + public void setCreateTimestamp(Date createTimestamp) { + this.createTimestamp = createTimestamp; + } + + public Date getModifyTimestamp() { + return modifyTimestamp; + } + + public void setModifyTimestamp(Date modifyTimestamp) { + this.modifyTimestamp = modifyTimestamp; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((appletID == null) ? 0 : appletID.hashCode()); + result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((keyInfo == null) ? 0 : keyInfo.hashCode()); + result = prime * result + ((modifyTimestamp == null) ? 0 : modifyTimestamp.hashCode()); + result = prime * result + ((reason == null) ? 0 : reason.hashCode()); + result = prime * result + ((status == null) ? 0 : status.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; + TokenRecord other = (TokenRecord) obj; + if (appletID == null) { + if (other.appletID != null) + return false; + } else if (!appletID.equals(other.appletID)) + return false; + if (createTimestamp == null) { + if (other.createTimestamp != null) + return false; + } else if (!createTimestamp.equals(other.createTimestamp)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (keyInfo == null) { + if (other.keyInfo != null) + return false; + } else if (!keyInfo.equals(other.keyInfo)) + return false; + if (modifyTimestamp == null) { + if (other.modifyTimestamp != null) + return false; + } else if (!modifyTimestamp.equals(other.modifyTimestamp)) + return false; + if (reason == null) { + if (other.reason != null) + return false; + } else if (!reason.equals(other.reason)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + 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/server/tps/token/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java new file mode 100644 index 000000000..66f96f932 --- /dev/null +++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/token/TokenService.java @@ -0,0 +1,245 @@ +// --- 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.server.tps.token; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; +import java.util.Iterator; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.dogtagpki.server.tps.TPSSubsystem; +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.base.PKIException; +import com.netscape.certsrv.tps.token.TokenCollection; +import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.certsrv.tps.token.TokenModifyRequest; +import com.netscape.certsrv.tps.token.TokenResource; +import com.netscape.cms.servlet.base.PKIService; + +/** + * @author Endi S. Dewata + */ +public class TokenService extends PKIService implements TokenResource { + + public final static int DEFAULT_SIZE = 20; + + public TokenService() { + System.out.println("TokenService.()"); + } + + public TokenData createTokenData(TokenRecord tokenRecord) { + + TokenData tokenData = new TokenData(); + tokenData.setID(tokenRecord.getID()); + tokenData.setUserID(tokenRecord.getUserID()); + tokenData.setStatus(tokenRecord.getStatus()); + tokenData.setReason(tokenRecord.getReason()); + tokenData.setAppletID(tokenRecord.getAppletID()); + tokenData.setKeyInfo(tokenRecord.getKeyInfo()); + tokenData.setCreateTimestamp(tokenRecord.getCreateTimestamp()); + tokenData.setModifyTimestamp(tokenRecord.getModifyTimestamp()); + + String tokenID = tokenRecord.getID(); + try { + tokenID = URLEncoder.encode(tokenID, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + + URI uri = uriInfo.getBaseUriBuilder().path(TokenResource.class).path("{tokenID}").build(tokenID); + tokenData.setLink(new Link("self", uri)); + + return tokenData; + } + + public TokenRecord createTokenRecord(TokenData tokenData) { + + TokenRecord tokenRecord = new TokenRecord(); + tokenRecord.setID(tokenData.getID()); + tokenRecord.setUserID(tokenData.getUserID()); + tokenRecord.setStatus(tokenData.getStatus()); + tokenRecord.setReason(tokenData.getReason()); + tokenRecord.setAppletID(tokenData.getAppletID()); + tokenRecord.setKeyInfo(tokenData.getKeyInfo()); + tokenRecord.setCreateTimestamp(tokenData.getCreateTimestamp()); + tokenRecord.setModifyTimestamp(tokenData.getModifyTimestamp()); + + return tokenRecord; + } + + @Override + public TokenCollection findTokens(Integer start, Integer size) { + + System.out.println("TokenService.findTokens()"); + + try { + start = start == null ? 0 : start; + size = size == null ? DEFAULT_SIZE : size; + + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + + Iterator tokens = database.getRecords().iterator(); + + TokenCollection response = new TokenCollection(); + + int i = 0; + + // skip to the start of the page + for ( ; i 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 TokenData getToken(String tokenID) { + + System.out.println("TokenService.getToken(\"" + tokenID + "\")"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + + return createTokenData(database.getRecord(tokenID)); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public Response addToken(TokenData tokenData) { + + System.out.println("TokenService.addToken(\"" + tokenData.getID() + "\")"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + + database.addRecord(createTokenRecord(tokenData)); + tokenData = createTokenData(database.getRecord(tokenData.getID())); + + return Response + .created(tokenData.getLink().getHref()) + .entity(tokenData) + .type(MediaType.APPLICATION_XML) + .build(); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public Response updateToken(String tokenID, TokenData tokenData) { + + System.out.println("TokenService.updateToken(\"" + tokenID + "\")"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + + TokenRecord tokenRecord = database.getRecord(tokenID); + tokenRecord.setUserID(tokenData.getUserID()); + database.updateRecord(tokenData.getID(), tokenRecord); + + tokenData = createTokenData(database.getRecord(tokenID)); + + return Response + .ok(tokenData) + .type(MediaType.APPLICATION_XML) + .build(); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public Response modifyToken(String tokenID, TokenModifyRequest request) { + + System.out.println("TokenService.modifyToken(\"" + tokenID + "\", request"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + + TokenRecord tokenRecord = database.getRecord(tokenID); + // TODO: perform modification + + TokenData tokenData = createTokenData(tokenRecord); + + return Response + .ok(tokenData) + .type(MediaType.APPLICATION_XML) + .build(); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public void removeToken(String tokenID) { + + System.out.println("TokenService.removeToken(\"" + tokenID + "\")"); + + try { + TPSSubsystem subsystem = TPSSubsystem.getInstance(); + TokenDatabase database = subsystem.getTokenDatabase(); + database.removeRecord(tokenID); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } +} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/TPSConnection.java b/base/tps-tomcat/src/org/dogtagpki/tps/TPSConnection.java deleted file mode 100644 index cd62ff530..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/TPSConnection.java +++ /dev/null @@ -1,98 +0,0 @@ -// --- 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; - -/** - * @author Endi S. Dewata - */ -public class TPSConnection { - - public InputStream in; - public PrintStream out; - public boolean chunked; - - public TPSConnection(InputStream in, OutputStream out) { - this(in, out, false); - } - - public TPSConnection(InputStream in, OutputStream out, boolean chunked) { - this.in = in; - this.out = new PrintStream(out); - this.chunked = chunked; - } - - public TPSMessage read() throws IOException { - - StringBuilder sb = new StringBuilder(); - int b; - - // read the first parameter - while ((b = in.read()) >= 0) { - char c = (char)b; - if (c == '&') break; - sb.append(c); - } - - if (b < 0) throw new IOException("Unexpected end of stream"); - - // parse message size - String nvp = sb.toString(); - String[] s = nvp.split("="); - int size = Integer.parseInt(s[1]); - - sb.append('&'); - - // read the rest of message - for (int i=0; i - */ -public class TPSMessage { - - Map map = new LinkedHashMap(); - - public TPSMessage() { - } - - public TPSMessage(String message) { - decode(message); - } - - public TPSMessage(Map map) { - this.map.putAll(map); - } - - public void put(String key, String value) { - map.put(key, value); - } - - public void put(String key, Integer value) { - map.put(key, value.toString()); - } - - public void put(String key, byte[] bytes) { - StringBuilder sb = new StringBuilder(); - - for (byte b : bytes) { - sb.append("%"); - sb.append(String.format("%02X", b)); - } - - map.put(key, sb.toString()); - } - - public void decode(String message) { - - for (String nvp : message.split("&")) { - String[] s = nvp.split("="); - - String key = s[0]; - String value = s[1]; - - // skip message size - if (key.equals("s")) continue; - - map.put(key, value); - } - } - - public String encode() { - - StringBuilder sb = new StringBuilder(); - - // encode message type - String type = map.get("msg_type"); - sb.append("msg_type=" + type); - - // encode other parameters - for (String key : map.keySet()) { - - if (key.equals("msg_type")) continue; - - String value = map.get(key); - sb.append("&" + key + "=" + value); - } - - String message = sb.toString(); - - // encode message_size - return "s=" + message.length() + "&" + message; - } - - public String toString() { - return map.toString(); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertDatabase.java b/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertDatabase.java deleted file mode 100644 index a575eb7cf..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertDatabase.java +++ /dev/null @@ -1,76 +0,0 @@ -// --- 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.cert; - -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 TPSCertDatabase extends Database { - - public TPSCertDatabase() { - super("Certificate"); - - // add sample records - try { - TPSCertRecord record1 = new TPSCertRecord(); - record1.setID("cert1"); - record1.setSerialNumber("16"); - record1.setSubject("cn=someone"); - record1.setTokenID("TOKEN0001"); - record1.setKeyType("something"); - record1.setStatus("active"); - record1.setUserID("user1"); - record1.setCreateTime(new Date()); - record1.setModifyTime(new Date()); - addRecord(record1); - - TPSCertRecord record2 = new TPSCertRecord(); - record2.setID("cert2"); - record2.setSerialNumber("17"); - record2.setSubject("cn=someone"); - record2.setTokenID("TOKEN0002"); - record2.setKeyType("something"); - record2.setStatus("revoked"); - record2.setUserID("user2"); - record2.setCreateTime(new Date()); - record2.setModifyTime(new Date()); - addRecord(record2); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void addRecord(TPSCertRecord certRecord) throws Exception { - certRecord.setCreateTime(new Date()); - - addRecord(certRecord.getID(), certRecord); - } - - public void updateRecord(TPSCertRecord certRecord) throws Exception { - updateRecord(certRecord.getID(), certRecord); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertRecord.java b/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertRecord.java deleted file mode 100644 index c9303294f..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertRecord.java +++ /dev/null @@ -1,288 +0,0 @@ -// --- 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.cert; - -import java.util.Date; - -/** - * @author Endi S. Dewata - */ -public class TPSCertRecord { - - String id; - String serialNumber; - String subject; - String tokenID; - String keyType; - String status; - String userID; - String certificate; - String issuedBy; - String origin; - String type; - Date validNotBefore; - Date validNotAfter; - String extensions; - Date createTime; - Date modifyTime; - - public String getID() { - return id; - } - - public void setID(String id) { - this.id = id; - } - - public String getSerialNumber() { - return serialNumber; - } - - public void setSerialNumber(String serialNumber) { - this.serialNumber = serialNumber; - } - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - public String getTokenID() { - return tokenID; - } - - public void setTokenID(String tokenID) { - this.tokenID = tokenID; - } - - public String getKeyType() { - return keyType; - } - - public void setKeyType(String keyType) { - this.keyType = keyType; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getUserID() { - return userID; - } - - public void setUserID(String userID) { - this.userID = userID; - } - - - public String getCertificate() { - return certificate; - } - - public void setCertificate(String certificate) { - this.certificate = certificate; - } - - public String getIssuedBy() { - return issuedBy; - } - - public void setIssuedBy(String issuedBy) { - this.issuedBy = issuedBy; - } - - public String getOrigin() { - return origin; - } - - public void setOrigin(String origin) { - this.origin = origin; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Date getValidNotBefore() { - return validNotBefore; - } - - public void setValidNotBefore(Date validNotBefore) { - this.validNotBefore = validNotBefore; - } - - public Date getValidNotAfter() { - return validNotAfter; - } - - public void setValidNotAfter(Date validNotAfter) { - this.validNotAfter = validNotAfter; - } - - public String getExtensions() { - return extensions; - } - - public void setExtensions(String extensions) { - this.extensions = extensions; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getModifyTime() { - return modifyTime; - } - - public void setModifyTime(Date modifyTime) { - this.modifyTime = modifyTime; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((certificate == null) ? 0 : certificate.hashCode()); - result = prime * result + ((createTime == null) ? 0 : createTime.hashCode()); - result = prime * result + ((extensions == null) ? 0 : extensions.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((issuedBy == null) ? 0 : issuedBy.hashCode()); - result = prime * result + ((keyType == null) ? 0 : keyType.hashCode()); - result = prime * result + ((modifyTime == null) ? 0 : modifyTime.hashCode()); - result = prime * result + ((origin == null) ? 0 : origin.hashCode()); - result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((subject == null) ? 0 : subject.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()); - result = prime * result + ((validNotAfter == null) ? 0 : validNotAfter.hashCode()); - result = prime * result + ((validNotBefore == null) ? 0 : validNotBefore.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; - TPSCertRecord other = (TPSCertRecord) obj; - if (certificate == null) { - if (other.certificate != null) - return false; - } else if (!certificate.equals(other.certificate)) - return false; - if (createTime == null) { - if (other.createTime != null) - return false; - } else if (!createTime.equals(other.createTime)) - 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 (issuedBy == null) { - if (other.issuedBy != null) - return false; - } else if (!issuedBy.equals(other.issuedBy)) - return false; - if (keyType == null) { - if (other.keyType != null) - return false; - } else if (!keyType.equals(other.keyType)) - return false; - if (modifyTime == null) { - if (other.modifyTime != null) - return false; - } else if (!modifyTime.equals(other.modifyTime)) - return false; - if (origin == null) { - if (other.origin != null) - return false; - } else if (!origin.equals(other.origin)) - return false; - if (serialNumber == null) { - if (other.serialNumber != null) - return false; - } else if (!serialNumber.equals(other.serialNumber)) - return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - if (subject == null) { - if (other.subject != null) - return false; - } else if (!subject.equals(other.subject)) - 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; - if (validNotAfter == null) { - if (other.validNotAfter != null) - return false; - } else if (!validNotAfter.equals(other.validNotAfter)) - return false; - if (validNotBefore == null) { - if (other.validNotBefore != null) - return false; - } else if (!validNotBefore.equals(other.validNotBefore)) - return false; - return true; - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertService.java b/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertService.java deleted file mode 100644 index d49e3b700..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/cert/TPSCertService.java +++ /dev/null @@ -1,152 +0,0 @@ -// --- 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.cert; - -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.base.PKIException; -import com.netscape.certsrv.tps.cert.TPSCertCollection; -import com.netscape.certsrv.tps.cert.TPSCertData; -import com.netscape.certsrv.tps.cert.TPSCertResource; -import com.netscape.cms.servlet.base.PKIService; - -/** - * @author Endi S. Dewata - */ -public class TPSCertService extends PKIService implements TPSCertResource { - - public final static int DEFAULT_SIZE = 20; - - public TPSCertService() { - System.out.println("TPSCertService.()"); - } - - public TPSCertData createCertData(TPSCertRecord certRecord) { - - TPSCertData certData = new TPSCertData(); - certData.setID(certRecord.getID()); - certData.setSerialNumber(certRecord.getSerialNumber()); - certData.setSubject(certRecord.getSubject()); - certData.setTokenID(certRecord.getTokenID()); - certData.setKeyType(certRecord.getKeyType()); - certData.setStatus(certRecord.getStatus()); - certData.setUserID(certRecord.getUserID()); - certData.setCreateTime(certRecord.getCreateTime()); - certData.setModifyTime(certRecord.getModifyTime()); - - String certID = certRecord.getID(); - try { - certID = URLEncoder.encode(certID, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - - URI uri = uriInfo.getBaseUriBuilder().path(TPSCertResource.class).path("{certID}").build(certID); - certData.setLink(new Link("self", uri)); - - return certData; - } - - public TPSCertRecord createCertRecord(TPSCertData certData) { - - TPSCertRecord certRecord = new TPSCertRecord(); - certRecord.setID(certData.getID()); - certRecord.setSerialNumber(certData.getSerialNumber()); - certRecord.setSubject(certData.getSubject()); - certRecord.setTokenID(certData.getTokenID()); - certRecord.setKeyType(certData.getKeyType()); - certRecord.setStatus(certData.getStatus()); - certRecord.setUserID(certData.getUserID()); - certRecord.setCreateTime(certData.getCreateTime()); - certRecord.setModifyTime(certData.getModifyTime()); - - return certRecord; - } - - @Override - public TPSCertCollection findCerts(Integer start, Integer size) { - - System.out.println("TPSCertService.findCerts()"); - - try { - start = start == null ? 0 : start; - size = size == null ? DEFAULT_SIZE : size; - - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TPSCertDatabase database = subsystem.getCertDatabase(); - - Iterator activities = database.getRecords().iterator(); - - TPSCertCollection response = new TPSCertCollection(); - - int i = 0; - - // skip to the start of the page - for ( ; i 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 TPSCertData getCert(String certID) { - - System.out.println("TPSCertService.getCert(\"" + certID + "\")"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TPSCertDatabase database = subsystem.getCertDatabase(); - - return createCertData(database.getRecord(certID)); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java b/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java deleted file mode 100644 index 28c0935da..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityDatabase.java +++ /dev/null @@ -1,70 +0,0 @@ -// --- 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 { - - 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 deleted file mode 100644 index e845955ca..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityRecord.java +++ /dev/null @@ -1,197 +0,0 @@ -// --- 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 deleted file mode 100644 index 174fd554f..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/logging/ActivityService.java +++ /dev/null @@ -1,143 +0,0 @@ -// --- 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.()"); - } - - 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 activities = database.getRecords().iterator(); - - ActivityCollection response = new ActivityCollection(); - - int i = 0; - - // skip to the start of the page - for ( ; i 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/selftests/TPSPresence.java b/base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSPresence.java deleted file mode 100644 index 177d7f6a6..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSPresence.java +++ /dev/null @@ -1,187 +0,0 @@ -// --- 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.selftests; - -import java.security.PublicKey; -import java.util.Locale; - -import org.dogtagpki.tps.server.TPSSubsystem; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.IConfigStore; -import com.netscape.certsrv.logging.ILogEventListener; -import com.netscape.certsrv.selftests.EDuplicateSelfTestException; -import com.netscape.certsrv.selftests.EInvalidSelfTestException; -import com.netscape.certsrv.selftests.EMissingSelfTestException; -import com.netscape.certsrv.selftests.ESelfTestException; -import com.netscape.certsrv.selftests.ISelfTestSubsystem; -import com.netscape.cms.selftests.ASelfTest; - -/** - * This class implements a self test to check for TPS presence. - *

- * - * @author alee - * @version $Revision$, $Date$ - */ -public class TPSPresence extends ASelfTest { - - public static final String PROP_TPS_SUB_ID = "TpsSubId"; - private String tpsSubId = null; - - /** - * Initializes this subsystem with the configuration store - * associated with this instance name. - *

- * - * @param subsystem the associated subsystem - * @param instanceName the name of this self test instance - * @param parameters configuration store (self test parameters) - * @exception EDuplicateSelfTestException subsystem has duplicate name/value - * @exception EInvalidSelfTestException subsystem has invalid name/value - * @exception EMissingSelfTestException subsystem has missing name/value - */ - public void initSelfTest(ISelfTestSubsystem subsystem, String instanceName, - IConfigStore parameters) throws EDuplicateSelfTestException, EInvalidSelfTestException, - EMissingSelfTestException { - super.initSelfTest(subsystem, instanceName, parameters); - - try { - tpsSubId = mConfig.getString(PROP_TPS_SUB_ID); - if (tpsSubId != null) { - tpsSubId = tpsSubId.trim(); - } else { - mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), - CMS.getLogMessage("SELFTESTS_MISSING_VALUES", getSelfTestName(), - mPrefix + "." + PROP_TPS_SUB_ID)); - - throw new EMissingSelfTestException(PROP_TPS_SUB_ID); - } - } catch (EBaseException e) { - mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), - CMS.getLogMessage("SELFTESTS_MISSING_NAME", getSelfTestName(), - mPrefix + "." + PROP_TPS_SUB_ID)); - - throw new EMissingSelfTestException(mPrefix, PROP_TPS_SUB_ID, null); - } - } - - /** - * Notifies this subsystem if it is in execution mode. - *

- * - * @exception ESelfTestException failed to start - */ - public void startupSelfTest() throws ESelfTestException { - } - - /** - * Stops this subsystem. The subsystem may call shutdownSelfTest - * anytime after initialization. - *

- */ - public void shutdownSelfTest() { - } - - /** - * Returns the name associated with this self test. This method may - * return null if the self test has not been initialized. - *

- * - * @return instanceName of this self test - */ - public String getSelfTestName() { - return super.getSelfTestName(); - } - - /** - * Returns the root configuration storage (self test parameters) - * associated with this subsystem. - *

- * - * @return configuration store (self test parameters) of this subsystem - */ - public IConfigStore getSelfTestConfigStore() { - return super.getSelfTestConfigStore(); - } - - /** - * Retrieves description associated with an individual self test. - * This method may return null. - *

- * - * @param locale locale of the client that requests the description - * @return description of self test - */ - public String getSelfTestDescription(Locale locale) { - return CMS.getUserMessage(locale, - "CMS_SELFTESTS_TPS_PRESENCE_DESCRIPTION"); - } - - /** - * Execute an individual self test. - *

- * - * @param logger specifies logging subsystem - * @exception ESelfTestException self test exception - */ - public void runSelfTest(ILogEventListener logger) - throws ESelfTestException { - String logMessage = null; - TPSSubsystem tps = (TPSSubsystem) CMS.getSubsystem(tpsSubId); - if (tps == null) { - // log that the TPS is not installed - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_PRESENT", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // Retrieve the TPS certificate - org.mozilla.jss.crypto.X509Certificate tpsCert = null; - try { - tpsCert = tps.getSubsystemCert(); - } catch (Exception e) { - e.printStackTrace(); - // cert does not exist or is not yet configured - // tpsCert will remain null - } - - if (tpsCert == null) { - // log that the TPS is not yet initialized - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_INITIALIZED", - getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // Retrieve the TPS certificate public key - PublicKey tpsPubKey = tpsCert.getPublicKey(); - if (tpsPubKey == null) { - // log that something is seriously wrong with the TPS - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_CORRUPT", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // log that the TPS is present - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_PRESENT", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSValidity.java b/base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSValidity.java deleted file mode 100644 index 08c1ab088..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/selftests/TPSValidity.java +++ /dev/null @@ -1,197 +0,0 @@ -// --- 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.selftests; - -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateNotYetValidException; -import java.util.Locale; - -import netscape.security.x509.X509CertImpl; - -import org.dogtagpki.tps.server.TPSSubsystem; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.IConfigStore; -import com.netscape.certsrv.logging.ILogEventListener; -import com.netscape.certsrv.selftests.EDuplicateSelfTestException; -import com.netscape.certsrv.selftests.EInvalidSelfTestException; -import com.netscape.certsrv.selftests.EMissingSelfTestException; -import com.netscape.certsrv.selftests.ESelfTestException; -import com.netscape.certsrv.selftests.ISelfTestSubsystem; -import com.netscape.cms.selftests.ASelfTest; - -/** - * This class implements a self test to check the validity of the TPS. - *

- * - * @author alee - * @version $Revision$, $Date$ - */ -public class TPSValidity extends ASelfTest { - - // parameter information - public static final String PROP_TPS_SUB_ID = "TpsSubId"; - private String tpsSubId = null; - - /** - * Initializes this subsystem with the configuration store - * associated with this instance name. - *

- * - * @param subsystem the associated subsystem - * @param instanceName the name of this self test instance - * @param parameters configuration store (self test parameters) - * @exception EDuplicateSelfTestException subsystem has duplicate name/value - * @exception EInvalidSelfTestException subsystem has invalid name/value - * @exception EMissingSelfTestException subsystem has missing name/value - */ - public void initSelfTest(ISelfTestSubsystem subsystem, String instanceName, - IConfigStore parameters) throws EDuplicateSelfTestException, - EInvalidSelfTestException, EMissingSelfTestException { - super.initSelfTest(subsystem, instanceName, parameters); - - try { - tpsSubId = mConfig.getString(PROP_TPS_SUB_ID); - if (tpsSubId != null) { - tpsSubId = tpsSubId.trim(); - } else { - mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), - CMS.getLogMessage("SELFTESTS_MISSING_VALUES", getSelfTestName(), - mPrefix + "." + PROP_TPS_SUB_ID)); - - throw new EMissingSelfTestException(PROP_TPS_SUB_ID); - } - } catch (EBaseException e) { - mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), - CMS.getLogMessage("SELFTESTS_MISSING_NAME", getSelfTestName(), - mPrefix + "." + PROP_TPS_SUB_ID)); - - throw new EMissingSelfTestException(mPrefix, PROP_TPS_SUB_ID, null); - } - } - - /** - * Notifies this subsystem if it is in execution mode. - *

- * - * @exception ESelfTestException failed to start - */ - public void startupSelfTest() throws ESelfTestException { - } - - /** - * Stops this subsystem. The subsystem may call shutdownSelfTest - * anytime after initialization. - *

- */ - public void shutdownSelfTest() { - } - - /** - * Returns the name associated with this self test. This method may - * return null if the self test has not been intialized. - *

- * - * @return instanceName of this self test - */ - public String getSelfTestName() { - return super.getSelfTestName(); - } - - /** - * Returns the root configuration storage (self test parameters) - * associated with this subsystem. - *

- * - * @return configuration store (self test parameters) of this subsystem - */ - public IConfigStore getSelfTestConfigStore() { - return super.getSelfTestConfigStore(); - } - - /** - * Retrieves description associated with an individual self test. - * This method may return null. - *

- * - * @param locale locale of the client that requests the description - * @return description of self test - */ - public String getSelfTestDescription(Locale locale) { - return CMS.getUserMessage(locale, - "CMS_SELFTESTS_TPS_VALIDITY_DESCRIPTION"); - } - - /** - * Execute an individual self test. - *

- * - * @param logger specifies logging subsystem - * @exception ESelfTestException self test exception - */ - public void runSelfTest(ILogEventListener logger) - throws ESelfTestException { - String logMessage = null; - TPSSubsystem tps = (TPSSubsystem) CMS.getSubsystem(tpsSubId); - - if (tps == null) { - // log that the TPS is not installed - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_PRESENT", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // Retrieve the TPS subsystem certificate - X509CertImpl tpsCert = null; - try { - tpsCert = new X509CertImpl(tps.getSubsystemCert().getEncoded()); - } catch (Exception e) { - // certificate is not present or has not been configured - // tpsCert will remain null - } - - if (tpsCert == null) { - // log that the TPS is not yet initialized - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_INITIALIZED", - getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // Check the TPS validity period - try { - tpsCert.checkValidity(); - } catch (CertificateNotYetValidException e) { - // log that the TPS is not yet valid - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_NOT_YET_VALID", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } catch (CertificateExpiredException e) { - // log that the TPS is expired - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_EXPIRED", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - throw new ESelfTestException(logMessage); - } - - // log that the TPS is valid - logMessage = CMS.getLogMessage("SELFTESTS_TPS_IS_VALID", getSelfTestName()); - mSelfTestSubsystem.log(logger, logMessage); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java deleted file mode 100644 index caf43a2f0..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSApplication.java +++ /dev/null @@ -1,92 +0,0 @@ -// --- 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.server; - -import java.util.HashSet; -import java.util.Set; - -import javax.ws.rs.core.Application; - -import org.dogtagpki.tps.cert.TPSCertService; -import org.dogtagpki.tps.logging.ActivityService; -import org.dogtagpki.tps.token.TokenService; - -import com.netscape.certsrv.base.PKIException; -import com.netscape.cms.authorization.ACLInterceptor; -import com.netscape.cms.authorization.AuthMethodInterceptor; -import com.netscape.cms.servlet.account.AccountService; -import com.netscape.cms.servlet.admin.GroupMemberService; -import com.netscape.cms.servlet.admin.GroupService; -import com.netscape.cms.servlet.admin.SystemCertService; -import com.netscape.cms.servlet.admin.UserCertService; -import com.netscape.cms.servlet.admin.UserMembershipService; -import com.netscape.cms.servlet.admin.UserService; -import com.netscape.cms.servlet.csadmin.SystemConfigService; - -/** - * @author Endi S. Dewata - */ -public class TPSApplication extends Application { - - private Set singletons = new HashSet(); - private Set> classes = new HashSet>(); - - public TPSApplication() { - - // account - classes.add(AccountService.class); - - // installer - classes.add(SystemConfigService.class); - - // user and group management - classes.add(GroupMemberService.class); - classes.add(GroupService.class); - classes.add(UserCertService.class); - classes.add(UserMembershipService.class); - classes.add(UserService.class); - - // system certs - classes.add(SystemCertService.class); - - // activities - classes.add(ActivityService.class); - - // certificates - classes.add(TPSCertService.class); - - // tokens - classes.add(TokenService.class); - - // exception mapper - classes.add(PKIException.Mapper.class); - - // interceptors - singletons.add(new AuthMethodInterceptor()); - singletons.add(new ACLInterceptor()); - } - - public Set> getClasses() { - return classes; - } - - public Set getSingletons() { - return singletons; - } - -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSServlet.java b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSServlet.java deleted file mode 100644 index 78e6df4f8..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSServlet.java +++ /dev/null @@ -1,61 +0,0 @@ -// --- 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.server; - -import java.io.IOException; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.dogtagpki.tps.TPSConnection; -import org.dogtagpki.tps.TPSMessage; - -/** - * @author Endi S. Dewata - */ -public class TPSServlet extends HttpServlet { - - private static final long serialVersionUID = -1092227495262381074L; - - public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { - - response.setHeader("Transfer-Encoding", "chunked"); - - TPSConnection con = new TPSConnection( - request.getInputStream(), response.getOutputStream(), true); - - TPSMessage message = con.read(); - System.out.println("Receive: " + message); - - message = new TPSMessage(); - message.put("msg_type", 9); - message.put("pdu_size", 12); - message.put("pdu_data", new byte[] { - (byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, - (byte)0x07, (byte)0xA0, (byte)0x00, (byte)0x00, - (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00 - }); - - System.out.println("Send: " + message); - con.write(message); - - message = con.read(); - System.out.println("Receive: " + message); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java b/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java deleted file mode 100644 index 96ba4a9ef..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/server/TPSSubsystem.java +++ /dev/null @@ -1,143 +0,0 @@ -// --- 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.server; - -import org.dogtagpki.tps.cert.TPSCertDatabase; -import org.dogtagpki.tps.logging.ActivityDatabase; -import org.dogtagpki.tps.token.TokenDatabase; -import org.mozilla.jss.CryptoManager; -import org.mozilla.jss.CryptoManager.NotInitializedException; -import org.mozilla.jss.crypto.ObjectNotFoundException; -import org.mozilla.jss.crypto.TokenException; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.authority.IAuthority; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.IConfigStore; -import com.netscape.certsrv.base.ISubsystem; -import com.netscape.certsrv.logging.ILogger; -import com.netscape.certsrv.request.IRequestListener; -import com.netscape.certsrv.request.IRequestQueue; - -/** - * @author Endi S. Dewata - */ -public class TPSSubsystem implements IAuthority, ISubsystem { - - public final static TPSSubsystem INSTANCE = new TPSSubsystem(); - - public ILogger logger = CMS.getLogger(); - - public String id; - public String nickname; - public ISubsystem owner; - public IConfigStore config; - - public ActivityDatabase activityDatabase = new ActivityDatabase(); - public TPSCertDatabase certDatabase = new TPSCertDatabase(); - public TokenDatabase tokenDatabase = new TokenDatabase(); - - public static TPSSubsystem getInstance() { - return INSTANCE; - } - - @Override - public String getId() { - return id; - } - - @Override - public void setId(String id) throws EBaseException { - this.id = id; - } - - @Override - public void init(ISubsystem owner, IConfigStore config) throws EBaseException { - this.owner = owner; - this.config = config; - } - - @Override - public void startup() throws EBaseException { - } - - @Override - public void shutdown() { - } - - @Override - public IConfigStore getConfigStore() { - return config; - } - - @Override - public IRequestQueue getRequestQueue() { - return null; - } - - @Override - public void registerRequestListener(IRequestListener listener) { - } - - @Override - public void registerPendingListener(IRequestListener listener) { - } - - @Override - public void log(int level, String msg) { - logger.log(ILogger.EV_SYSTEM, ILogger.S_TPS, level, msg); - } - - @Override - public String getNickname() { - return nickname; - } - - public void setNickname(String nickname) { - this.nickname = nickname; - } - - @Override - public String getOfficialName() { - return "tps"; - } - - public ActivityDatabase getActivityDatabase() { - return activityDatabase; - } - - public TPSCertDatabase getCertDatabase() { - return certDatabase; - } - - public TokenDatabase getTokenDatabase() { - return tokenDatabase; - } - - public org.mozilla.jss.crypto.X509Certificate getSubsystemCert() throws EBaseException, NotInitializedException, - ObjectNotFoundException, TokenException { - IConfigStore cs = CMS.getConfigStore(); - String nickname = cs.getString("tps.subsystem.nickname", ""); - String tokenname = cs.getString("tps.subsystem.tokenname", ""); - if (!tokenname.equals("internal") && !tokenname.equals("Internal Key Storage Token")) - nickname = tokenname + ":" + nickname; - - CryptoManager cm = CryptoManager.getInstance(); - return cm.findCertByNickname(nickname); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenDatabase.java b/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenDatabase.java deleted file mode 100644 index 7cc5aca78..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenDatabase.java +++ /dev/null @@ -1,49 +0,0 @@ -// --- 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.token; - -import java.util.Date; - -import com.netscape.cmscore.dbs.Database; - -/** - * This class implements in-memory token database. In the future this - * will be replaced with LDAP database. - * - * @author Endi S. Dewata - */ -public class TokenDatabase extends Database { - - public TokenDatabase() { - super("Token"); - } - - public void addRecord(TokenRecord tokenRecord) throws Exception { - tokenRecord.setStatus("ENABLED"); - tokenRecord.setCreateTimestamp(new Date()); - - addRecord(tokenRecord.getID(), tokenRecord); - } - - public void updateRecord(TokenRecord tokenRecord) throws Exception { - tokenRecord.setModifyTimestamp(new Date()); - - updateRecord(tokenRecord.getID(), tokenRecord); - } -} diff --git a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java b/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java deleted file mode 100644 index 85130e8bc..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenRecord.java +++ /dev/null @@ -1,167 +0,0 @@ -// --- 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.token; - -import java.util.Date; - -/** - * @author Endi S. Dewata - */ -public class TokenRecord { - - String id; - String userID; - String status; - String reason; - String appletID; - String keyInfo; - Date createTimestamp; - Date modifyTimestamp; - - public String getID() { - return id; - } - - public void setID(String id) { - this.id = id; - } - - public String getUserID() { - return userID; - } - - public void setUserID(String userID) { - this.userID = userID; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } - - public String getAppletID() { - return appletID; - } - - public void setAppletID(String appletID) { - this.appletID = appletID; - } - - public String getKeyInfo() { - return keyInfo; - } - - public void setKeyInfo(String keyInfo) { - this.keyInfo = keyInfo; - } - - public Date getCreateTimestamp() { - return createTimestamp; - } - - public void setCreateTimestamp(Date createTimestamp) { - this.createTimestamp = createTimestamp; - } - - public Date getModifyTimestamp() { - return modifyTimestamp; - } - - public void setModifyTimestamp(Date modifyTimestamp) { - this.modifyTimestamp = modifyTimestamp; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((appletID == null) ? 0 : appletID.hashCode()); - result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((keyInfo == null) ? 0 : keyInfo.hashCode()); - result = prime * result + ((modifyTimestamp == null) ? 0 : modifyTimestamp.hashCode()); - result = prime * result + ((reason == null) ? 0 : reason.hashCode()); - result = prime * result + ((status == null) ? 0 : status.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; - TokenRecord other = (TokenRecord) obj; - if (appletID == null) { - if (other.appletID != null) - return false; - } else if (!appletID.equals(other.appletID)) - return false; - if (createTimestamp == null) { - if (other.createTimestamp != null) - return false; - } else if (!createTimestamp.equals(other.createTimestamp)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (keyInfo == null) { - if (other.keyInfo != null) - return false; - } else if (!keyInfo.equals(other.keyInfo)) - return false; - if (modifyTimestamp == null) { - if (other.modifyTimestamp != null) - return false; - } else if (!modifyTimestamp.equals(other.modifyTimestamp)) - return false; - if (reason == null) { - if (other.reason != null) - return false; - } else if (!reason.equals(other.reason)) - return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - 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/token/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenService.java deleted file mode 100644 index c2787ebf5..000000000 --- a/base/tps-tomcat/src/org/dogtagpki/tps/token/TokenService.java +++ /dev/null @@ -1,245 +0,0 @@ -// --- 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.token; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLEncoder; -import java.util.Iterator; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.dogtagpki.tps.server.TPSSubsystem; -import org.jboss.resteasy.plugins.providers.atom.Link; - -import com.netscape.certsrv.base.PKIException; -import com.netscape.certsrv.token.TokenCollection; -import com.netscape.certsrv.token.TokenData; -import com.netscape.certsrv.token.TokenModifyRequest; -import com.netscape.certsrv.token.TokenResource; -import com.netscape.cms.servlet.base.PKIService; - -/** - * @author Endi S. Dewata - */ -public class TokenService extends PKIService implements TokenResource { - - public final static int DEFAULT_SIZE = 20; - - public TokenService() { - System.out.println("TokenService.()"); - } - - public TokenData createTokenData(TokenRecord tokenRecord) { - - TokenData tokenData = new TokenData(); - tokenData.setID(tokenRecord.getID()); - tokenData.setUserID(tokenRecord.getUserID()); - tokenData.setStatus(tokenRecord.getStatus()); - tokenData.setReason(tokenRecord.getReason()); - tokenData.setAppletID(tokenRecord.getAppletID()); - tokenData.setKeyInfo(tokenRecord.getKeyInfo()); - tokenData.setCreateTimestamp(tokenRecord.getCreateTimestamp()); - tokenData.setModifyTimestamp(tokenRecord.getModifyTimestamp()); - - String tokenID = tokenRecord.getID(); - try { - tokenID = URLEncoder.encode(tokenID, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - - URI uri = uriInfo.getBaseUriBuilder().path(TokenResource.class).path("{tokenID}").build(tokenID); - tokenData.setLink(new Link("self", uri)); - - return tokenData; - } - - public TokenRecord createTokenRecord(TokenData tokenData) { - - TokenRecord tokenRecord = new TokenRecord(); - tokenRecord.setID(tokenData.getID()); - tokenRecord.setUserID(tokenData.getUserID()); - tokenRecord.setStatus(tokenData.getStatus()); - tokenRecord.setReason(tokenData.getReason()); - tokenRecord.setAppletID(tokenData.getAppletID()); - tokenRecord.setKeyInfo(tokenData.getKeyInfo()); - tokenRecord.setCreateTimestamp(tokenData.getCreateTimestamp()); - tokenRecord.setModifyTimestamp(tokenData.getModifyTimestamp()); - - return tokenRecord; - } - - @Override - public TokenCollection findTokens(Integer start, Integer size) { - - System.out.println("TokenService.findTokens()"); - - try { - start = start == null ? 0 : start; - size = size == null ? DEFAULT_SIZE : size; - - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - - Iterator tokens = database.getRecords().iterator(); - - TokenCollection response = new TokenCollection(); - - int i = 0; - - // skip to the start of the page - for ( ; i 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 TokenData getToken(String tokenID) { - - System.out.println("TokenService.getToken(\"" + tokenID + "\")"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - - return createTokenData(database.getRecord(tokenID)); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } - - @Override - public Response addToken(TokenData tokenData) { - - System.out.println("TokenService.addToken(\"" + tokenData.getID() + "\")"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - - database.addRecord(createTokenRecord(tokenData)); - tokenData = createTokenData(database.getRecord(tokenData.getID())); - - return Response - .created(tokenData.getLink().getHref()) - .entity(tokenData) - .type(MediaType.APPLICATION_XML) - .build(); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } - - @Override - public Response updateToken(String tokenID, TokenData tokenData) { - - System.out.println("TokenService.updateToken(\"" + tokenID + "\")"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - - TokenRecord tokenRecord = database.getRecord(tokenID); - tokenRecord.setUserID(tokenData.getUserID()); - database.updateRecord(tokenData.getID(), tokenRecord); - - tokenData = createTokenData(database.getRecord(tokenID)); - - return Response - .ok(tokenData) - .type(MediaType.APPLICATION_XML) - .build(); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } - - @Override - public Response modifyToken(String tokenID, TokenModifyRequest request) { - - System.out.println("TokenService.modifyToken(\"" + tokenID + "\", request"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - - TokenRecord tokenRecord = database.getRecord(tokenID); - // TODO: perform modification - - TokenData tokenData = createTokenData(tokenRecord); - - return Response - .ok(tokenData) - .type(MediaType.APPLICATION_XML) - .build(); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } - - @Override - public void removeToken(String tokenID) { - - System.out.println("TokenService.removeToken(\"" + tokenID + "\")"); - - try { - TPSSubsystem subsystem = TPSSubsystem.getInstance(); - TokenDatabase database = subsystem.getTokenDatabase(); - database.removeRecord(tokenID); - - } catch (Exception e) { - e.printStackTrace(); - throw new PKIException(e.getMessage()); - } - } -} -- cgit