diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2017-02-15 17:51:28 +0100 |
|---|---|---|
| committer | Endi S. Dewata <edewata@redhat.com> | 2017-02-24 00:20:06 +0100 |
| commit | 2d2f2232219c30c14c247a393f02414dc56c4111 (patch) | |
| tree | 2433b92403d61162a961fd8b7d347dbb4313c445 /base/common/src/org | |
| parent | 8bd37a1ff3fd14248e65b86ed35f5f6d12e4468f (diff) | |
| download | pki-2d2f2232219c30c14c247a393f02414dc56c4111.tar.gz pki-2d2f2232219c30c14c247a393f02414dc56c4111.tar.xz pki-2d2f2232219c30c14c247a393f02414dc56c4111.zip | |
Added InfoService and LoginService.
New REST services classes have been added to PKIApplication.
The InfoService provides general information about the server
including version number and access banner. The LoginService
provides a way to notify the server that the banner has been
displayed on the client, which in that case the InfoService
will no longer return the banner again in the same session.
https://fedorahosted.org/pki/ticket/2582
Diffstat (limited to 'base/common/src/org')
| -rw-r--r-- | base/common/src/org/dogtagpki/common/Info.java | 138 | ||||
| -rw-r--r-- | base/common/src/org/dogtagpki/common/InfoClient.java | 48 | ||||
| -rw-r--r-- | base/common/src/org/dogtagpki/common/InfoResource.java | 36 | ||||
| -rw-r--r-- | base/common/src/org/dogtagpki/common/LoginClient.java | 48 | ||||
| -rw-r--r-- | base/common/src/org/dogtagpki/common/LoginResource.java | 36 |
5 files changed, 306 insertions, 0 deletions
diff --git a/base/common/src/org/dogtagpki/common/Info.java b/base/common/src/org/dogtagpki/common/Info.java new file mode 100644 index 000000000..0a216f434 --- /dev/null +++ b/base/common/src/org/dogtagpki/common/Info.java @@ -0,0 +1,138 @@ +// --- 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) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +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.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.netscape.certsrv.base.ResourceMessage; + +/** + * @author Endi S. Dewata + */ +@XmlRootElement(name="Info") +public class Info extends ResourceMessage { + + private static Logger logger = LoggerFactory.getLogger(Info.class); + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(Info.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(Info.class).createUnmarshaller(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + String version; + String banner; + + @XmlElement(name="Version") + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @XmlElement(name="Banner") + public String getBanner() { + return banner; + } + + public void setBanner(String banner) { + this.banner = banner; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((banner == null) ? 0 : banner.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Info other = (Info) obj; + if (banner == null) { + if (other.banner != null) + return false; + } else if (!banner.equals(other.banner)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static Info valueOf(String string) throws Exception { + return (Info)unmarshaller.unmarshal(new StringReader(string)); + } + + public static void main(String args[]) throws Exception { + + Info before = new Info(); + before.setVersion("10.4.0"); + before.setBanner( + "WARNING!\n" + + "Access to this service is restricted to those individuals with " + + "specific permissions."); + + String string = before.toString(); + System.out.println(string); + + Info after = Info.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/org/dogtagpki/common/InfoClient.java b/base/common/src/org/dogtagpki/common/InfoClient.java new file mode 100644 index 000000000..9feddb7a6 --- /dev/null +++ b/base/common/src/org/dogtagpki/common/InfoClient.java @@ -0,0 +1,48 @@ +//--- 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) 2017 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import java.net.URISyntaxException; + +import javax.ws.rs.core.Response; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Endi S. Dewata + */ +public class InfoClient extends Client { + + public InfoResource resource; + + public InfoClient(PKIClient client) throws URISyntaxException { + super(client, "pki", "info"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(InfoResource.class); + } + + public Info getInfo() throws Exception { + Response response = resource.getInfo(); + return client.getEntity(response, Info.class); + } +} diff --git a/base/common/src/org/dogtagpki/common/InfoResource.java b/base/common/src/org/dogtagpki/common/InfoResource.java new file mode 100644 index 000000000..2861a6ad1 --- /dev/null +++ b/base/common/src/org/dogtagpki/common/InfoResource.java @@ -0,0 +1,36 @@ +// --- 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) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + +/** + * @author Endi S. Dewata + */ +@Path("info") +public interface InfoResource { + + @GET + @ClientResponseType(entityType=Info.class) + public Response getInfo() throws Exception; +} diff --git a/base/common/src/org/dogtagpki/common/LoginClient.java b/base/common/src/org/dogtagpki/common/LoginClient.java new file mode 100644 index 000000000..575915ec8 --- /dev/null +++ b/base/common/src/org/dogtagpki/common/LoginClient.java @@ -0,0 +1,48 @@ +//--- 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) 2017 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import java.net.URISyntaxException; + +import javax.ws.rs.core.Response; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** + * @author Endi S. Dewata + */ +public class LoginClient extends Client { + + public LoginResource resource; + + public LoginClient(PKIClient client) throws URISyntaxException { + super(client, "pki", "login"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(LoginResource.class); + } + + public void login() throws Exception { + Response response = resource.login(); + client.getEntity(response, Void.class); + } +} diff --git a/base/common/src/org/dogtagpki/common/LoginResource.java b/base/common/src/org/dogtagpki/common/LoginResource.java new file mode 100644 index 000000000..57936eb1c --- /dev/null +++ b/base/common/src/org/dogtagpki/common/LoginResource.java @@ -0,0 +1,36 @@ +// --- 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) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package org.dogtagpki.common; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + +/** + * @author Endi S. Dewata + */ +@Path("login") +public interface LoginResource { + + @POST + @ClientResponseType(entityType=Void.class) + public Response login() throws Exception; +} |
