diff options
Diffstat (limited to 'base/common/src')
10 files changed, 487 insertions, 1 deletions
diff --git a/base/common/src/com/netscape/certsrv/ca/CAClient.java b/base/common/src/com/netscape/certsrv/ca/CAClient.java index a58d0236d..e0bc6c9b3 100644 --- a/base/common/src/com/netscape/certsrv/ca/CAClient.java +++ b/base/common/src/com/netscape/certsrv/ca/CAClient.java @@ -37,6 +37,7 @@ import com.netscape.certsrv.profile.ProfileData; import com.netscape.certsrv.profile.ProfileDataInfos; import com.netscape.certsrv.profile.ProfileResource; import com.netscape.certsrv.request.RequestId; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.user.UserClient; public class CAClient extends SubsystemClient { @@ -53,6 +54,7 @@ public class CAClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new GroupClient(client, name)); + addClient(new SelfTestClient(client, name)); addClient(new UserClient(client, name)); certRequestClient = createProxy(CertRequestResource.class); diff --git a/base/common/src/com/netscape/certsrv/kra/KRAClient.java b/base/common/src/com/netscape/certsrv/kra/KRAClient.java index 3bebb150e..28991caf6 100644 --- a/base/common/src/com/netscape/certsrv/kra/KRAClient.java +++ b/base/common/src/com/netscape/certsrv/kra/KRAClient.java @@ -21,6 +21,7 @@ import com.netscape.certsrv.key.KeyRequestInfos; import com.netscape.certsrv.key.KeyRequestResource; import com.netscape.certsrv.key.KeyResource; import com.netscape.certsrv.request.RequestId; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.system.SystemCertResource; import com.netscape.certsrv.user.UserClient; import com.netscape.cmsutil.util.Utils; @@ -39,6 +40,7 @@ public class KRAClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new GroupClient(client, name)); + addClient(new SelfTestClient(client, name)); addClient(new UserClient(client, name)); systemCertClient = createProxy(SystemCertResource.class); diff --git a/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java index ed65e8b00..ab85bd200 100644 --- a/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java +++ b/base/common/src/com/netscape/certsrv/ocsp/OCSPClient.java @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.client.SubsystemClient; import com.netscape.certsrv.group.GroupClient; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.user.UserClient; public class OCSPClient extends SubsystemClient { @@ -33,6 +34,7 @@ public class OCSPClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new GroupClient(client, name)); + addClient(new SelfTestClient(client, name)); addClient(new UserClient(client, name)); } } diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java new file mode 100644 index 000000000..e9a081bb4 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java @@ -0,0 +1,52 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2013 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.selftests; + +import java.net.URISyntaxException; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Endi S. Dewata + */ +public class SelfTestClient extends Client { + + public SelfTestResource resource; + + public SelfTestClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "selftest"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(SelfTestResource.class); + } + + public SelfTestCollection findSelfTests(Integer start, Integer size) { + return resource.findSelfTests(start, size); + } + + public void executeSelfTests(String action) { + resource.executeSelfTests(action); + } + + public SelfTestData getSelfTest(String selfTestID) { + return resource.getSelfTest(selfTestID); + } +} diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestCollection.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestCollection.java new file mode 100644 index 000000000..946d2822d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestCollection.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.selftests; + +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="SelfTests") +public class SelfTestCollection extends DataCollection<SelfTestData> { + + @XmlElementRef + public Collection<SelfTestData> getEntries() { + return super.getEntries(); + } +} diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestData.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestData.java new file mode 100644 index 000000000..b10dc0a24 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestData.java @@ -0,0 +1,189 @@ +// --- 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.selftests; + +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="SelfTest") +public class SelfTestData { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(SelfTestData.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(SelfTestData.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + Boolean enabledAtStartup; + Boolean criticalAtStartup; + Boolean enabledOnDemand; + Boolean criticalOnDemand; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="EnabledAtStartup") + public Boolean isEnabledAtStartup() { + return enabledAtStartup; + } + + public void setEnabledAtStartup(Boolean enabledAtStartup) { + this.enabledAtStartup = enabledAtStartup; + } + + @XmlElement(name="CriticalAtStartup") + public Boolean isCriticalAtStartup() { + return criticalAtStartup; + } + + public void setCriticalAtStartup(Boolean criticalAtStartup) { + this.criticalAtStartup = criticalAtStartup; + } + + @XmlElement(name="EnabledOnDemand") + public Boolean isEnabledOnDemand() { + return enabledOnDemand; + } + + public void setEnabledOnDemand(Boolean enabledOnDemand) { + this.enabledOnDemand = enabledOnDemand; + } + + @XmlElement(name="CriticalOnDemand") + public Boolean isCriticalOnDemand() { + return criticalOnDemand; + } + + public void setCriticalOnDemand(Boolean criticalOnDemand) { + this.criticalOnDemand = criticalOnDemand; + } + + @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 + ((criticalOnDemand == null) ? 0 : criticalOnDemand.hashCode()); + result = prime * result + ((enabledOnDemand == null) ? 0 : enabledOnDemand.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.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; + SelfTestData other = (SelfTestData) obj; + if (criticalOnDemand == null) { + if (other.criticalOnDemand != null) + return false; + } else if (!criticalOnDemand.equals(other.criticalOnDemand)) + return false; + if (enabledOnDemand == null) { + if (other.enabledOnDemand != null) + return false; + } else if (!enabledOnDemand.equals(other.enabledOnDemand)) + return false; + 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; + 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 SelfTestData valueOf(String string) throws Exception { + try { + return (SelfTestData)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + SelfTestData before = new SelfTestData(); + before.setID("selftest1"); + before.setEnabledOnDemand(true); + before.setCriticalOnDemand(false); + + String string = before.toString(); + System.out.println(string); + + SelfTestData after = SelfTestData.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java new file mode 100644 index 000000000..7d847cae7 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.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 com.netscape.certsrv.selftests; + +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + + +/** + * @author Endi S. Dewata + */ +@Path("selftests") +public interface SelfTestResource { + + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public SelfTestCollection findSelfTests( + @QueryParam("start") Integer start, + @QueryParam("size") Integer size); + + @POST + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public void executeSelfTests(@QueryParam("action") String action); + + @GET + @Path("{selfTestID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public SelfTestData getSelfTest(@PathParam("selfTestID") String selfTestID); +} diff --git a/base/common/src/com/netscape/certsrv/tks/TKSClient.java b/base/common/src/com/netscape/certsrv/tks/TKSClient.java index a13089f86..a972241ce 100644 --- a/base/common/src/com/netscape/certsrv/tks/TKSClient.java +++ b/base/common/src/com/netscape/certsrv/tks/TKSClient.java @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.client.SubsystemClient; import com.netscape.certsrv.group.GroupClient; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.system.TPSConnectorClient; import com.netscape.certsrv.user.UserClient; @@ -34,7 +35,8 @@ public class TKSClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new GroupClient(client, name)); - addClient(new UserClient(client, name)); + addClient(new SelfTestClient(client, name)); addClient(new TPSConnectorClient(client, name)); + addClient(new UserClient(client, name)); } } diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java index fcd87f182..eeccdb018 100644 --- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java +++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java @@ -23,6 +23,7 @@ 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.selftests.SelfTestClient; import com.netscape.certsrv.tps.authenticator.AuthenticatorClient; import com.netscape.certsrv.tps.cert.TPSCertClient; import com.netscape.certsrv.tps.config.ConfigClient; @@ -49,6 +50,7 @@ public class TPSClient extends SubsystemClient { addClient(new ConnectionClient(client, name)); addClient(new GroupClient(client, name)); addClient(new ProfileMappingClient(client, name)); + addClient(new SelfTestClient(client, name)); addClient(new TokenClient(client, name)); addClient(new UserClient(client, name)); } diff --git a/base/common/src/com/netscape/cmscore/selftests/SelfTestService.java b/base/common/src/com/netscape/cmscore/selftests/SelfTestService.java new file mode 100644 index 000000000..da7708e49 --- /dev/null +++ b/base/common/src/com/netscape/cmscore/selftests/SelfTestService.java @@ -0,0 +1,148 @@ +// --- 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.cmscore.selftests; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.UriInfo; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.base.BadRequestException; +import com.netscape.certsrv.base.PKIException; +import com.netscape.certsrv.selftests.EMissingSelfTestException; +import com.netscape.certsrv.selftests.ISelfTestSubsystem; +import com.netscape.certsrv.selftests.SelfTestCollection; +import com.netscape.certsrv.selftests.SelfTestData; +import com.netscape.certsrv.selftests.SelfTestResource; +import com.netscape.cms.servlet.base.PKIService; + +/** + * @author Endi S. Dewata + */ +public class SelfTestService extends PKIService implements SelfTestResource { + + @Context + private UriInfo uriInfo; + + @Context + private HttpHeaders headers; + + @Context + private Request request; + + @Context + private HttpServletRequest servletRequest; + + public final static int DEFAULT_SIZE = 20; + + public SelfTestService() { + CMS.debug("SelfTestService.<init>()"); + } + + public SelfTestData createSelfTestData(ISelfTestSubsystem subsystem, String selfTestID) throws UnsupportedEncodingException, EMissingSelfTestException { + + SelfTestData selfTestData = new SelfTestData(); + selfTestData.setID(selfTestID); + selfTestData.setEnabledAtStartup(subsystem.isSelfTestEnabledAtStartup(selfTestID)); + + try { + selfTestData.setCriticalAtStartup(subsystem.isSelfTestCriticalAtStartup(selfTestID)); + } catch (EMissingSelfTestException e) { + // ignore + } + + selfTestData.setEnabledOnDemand(subsystem.isSelfTestEnabledOnDemand(selfTestID)); + + try { + selfTestData.setCriticalOnDemand(subsystem.isSelfTestCriticalOnDemand(selfTestID)); + } catch (EMissingSelfTestException e) { + // ignore + } + + selfTestID = URLEncoder.encode(selfTestID, "UTF-8"); + URI uri = uriInfo.getBaseUriBuilder().path(SelfTestResource.class).path("{selfTestID}").build(selfTestID); + selfTestData.setLink(new Link("self", uri)); + + return selfTestData; + } + + @Override + public SelfTestCollection findSelfTests(Integer start, Integer size) { + + CMS.debug("SelfTestService.findSelfTests()"); + + try { + SelfTestCollection response = new SelfTestCollection(); + + ISelfTestSubsystem subsystem = (ISelfTestSubsystem)CMS.getSubsystem(ISelfTestSubsystem.ID); + for (String name : subsystem.listSelfTestsEnabledOnDemand()) { + SelfTestData data = createSelfTestData(subsystem, name); + response.addEntry(data); + } + + return response; + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public SelfTestData getSelfTest(String selfTestID) { + + CMS.debug("SelfTestService.getSelfTest(\"" + selfTestID + "\")"); + + try { + ISelfTestSubsystem subsystem = (ISelfTestSubsystem)CMS.getSubsystem(ISelfTestSubsystem.ID); + return createSelfTestData(subsystem, selfTestID); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } + + @Override + public void executeSelfTests(String action) { + + CMS.debug("SelfTestService.executeSelfTests(\"" + action + "\")"); + + if (!"run".equals(action)) { + throw new BadRequestException("Invalid action: " + action); + } + + try { + ISelfTestSubsystem subsystem = (ISelfTestSubsystem)CMS.getSubsystem(ISelfTestSubsystem.ID); + subsystem.runSelfTestsOnDemand(); + + } catch (Exception e) { + e.printStackTrace(); + throw new PKIException(e.getMessage()); + } + } +} |