diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-08-27 14:38:07 -0400 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2013-09-01 01:05:03 -0500 |
commit | 3be4905f70b05050b53995524c91ccb7a390e1e6 (patch) | |
tree | 58ee82727de131fed3187d61b092a9de07663f55 /base/common/src/com/netscape/certsrv/tps | |
parent | 15e029e97aea4a23f065e6bc7fbfa16cdae8c02d (diff) | |
download | pki-3be4905f70b05050b53995524c91ccb7a390e1e6.tar.gz pki-3be4905f70b05050b53995524c91ccb7a390e1e6.tar.xz pki-3be4905f70b05050b53995524c91ccb7a390e1e6.zip |
Added TPS authenticator resource.
A skeleton for TPS authenticator services and the clients have been added.
The service implementation will be added later.
Ticket #652
Diffstat (limited to 'base/common/src/com/netscape/certsrv/tps')
7 files changed, 686 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java index 00da49b20..8381b1ac2 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.tps.authenticator.AuthenticatorClient; import com.netscape.certsrv.tps.cert.TPSCertClient; import com.netscape.certsrv.tps.connection.ConnectionClient; import com.netscape.certsrv.tps.token.TokenClient; @@ -40,6 +41,7 @@ public class TPSClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new ActivityClient(client, name)); + addClient(new AuthenticatorClient(client, name)); addClient(new ConnectionClient(client, name)); addClient(new GroupClient(client, name)); addClient(new TokenClient(client, name)); diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java new file mode 100644 index 000000000..82a76cc16 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.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 com.netscape.certsrv.tps.authenticator; + +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 AuthenticatorClient extends Client { + + public AuthenticatorResource resource; + + public AuthenticatorClient(PKIClient client) throws URISyntaxException { + this(client, client.getSubsystem()); + } + + public AuthenticatorClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "authenticator"); + init(); + } + + public void init() throws URISyntaxException { + resource = createProxy(AuthenticatorResource.class); + } + + public AuthenticatorCollection findAuthenticators(Integer start, Integer size) { + return resource.findAuthenticators(start, size); + } + + public AuthenticatorData getAuthenticator(String authenticatorID) { + return resource.getAuthenticator(authenticatorID); + } + + public AuthenticatorData addAuthenticator(AuthenticatorData authenticatorData) { + @SuppressWarnings("unchecked") + ClientResponse<AuthenticatorData> response = (ClientResponse<AuthenticatorData>)resource.addAuthenticator(authenticatorData); + return client.getEntity(response); + } + + public AuthenticatorData updateAuthenticator(String authenticatorID, AuthenticatorData authenticatorData) { + @SuppressWarnings("unchecked") + ClientResponse<AuthenticatorData> response = (ClientResponse<AuthenticatorData>)resource.updateAuthenticator(authenticatorID, authenticatorData); + return client.getEntity(response); + } + + public AuthenticatorData modifyAuthenticator(String authenticatorID, AuthenticatorModification authenticatorModification) { + @SuppressWarnings("unchecked") + ClientResponse<AuthenticatorData> response = (ClientResponse<AuthenticatorData>)resource.modifyAuthenticator(authenticatorID, authenticatorModification); + return client.getEntity(response); + } + + public void removeAuthenticator(String authenticatorID) { + resource.removeAuthenticator(authenticatorID); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorCollection.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorCollection.java new file mode 100644 index 000000000..e1978c8d3 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorCollection.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.authenticator; + +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="Authenticators") +public class AuthenticatorCollection extends DataCollection<AuthenticatorInfo> { + + @XmlElementRef + public Collection<AuthenticatorInfo> getEntries() { + return super.getEntries(); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java new file mode 100644 index 000000000..609d24132 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java @@ -0,0 +1,169 @@ +// --- 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.authenticator; + +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="Authenticator") +public class AuthenticatorData { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(AuthenticatorData.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(AuthenticatorData.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + String contents; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Contents") + public String getContents() { + return contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + @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 + ((contents == null) ? 0 : contents.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((status == null) ? 0 : status.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; + AuthenticatorData other = (AuthenticatorData) obj; + if (contents == null) { + if (other.contents != null) + return false; + } else if (!contents.equals(other.contents)) + 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; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + 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 AuthenticatorData valueOf(String string) throws Exception { + try { + return (AuthenticatorData)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + AuthenticatorData before = new AuthenticatorData(); + before.setID("authenticator1"); + before.setStatus("ENABLED"); + before.setContents("name=authenticator1\nparam=value"); + + String string = before.toString(); + System.out.println(string); + + AuthenticatorData after = AuthenticatorData.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorInfo.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorInfo.java new file mode 100644 index 000000000..55ce9b4f3 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorInfo.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.authenticator; + +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="Authenticator") +public class AuthenticatorInfo { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(AuthenticatorInfo.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(AuthenticatorInfo.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @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 + ((status == null) ? 0 : status.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; + AuthenticatorInfo other = (AuthenticatorInfo) 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 (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + 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 AuthenticatorInfo valueOf(String string) throws Exception { + try { + return (AuthenticatorInfo)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + AuthenticatorInfo before = new AuthenticatorInfo(); + before.setID("authenticator1"); + before.setStatus("ENABLED"); + + String string = before.toString(); + System.out.println(string); + + AuthenticatorInfo after = AuthenticatorInfo.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorModification.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorModification.java new file mode 100644 index 000000000..fb78415e3 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorModification.java @@ -0,0 +1,169 @@ +// --- 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.authenticator; + +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="AuthenticatorModifyRequest") +public class AuthenticatorModification { + + public static Marshaller marshaller; + public static Unmarshaller unmarshaller; + + static { + try { + marshaller = JAXBContext.newInstance(AuthenticatorModification.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + unmarshaller = JAXBContext.newInstance(AuthenticatorModification.class).createUnmarshaller(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String id; + String status; + String contents; + + Link link; + + @XmlAttribute(name="id") + public String getID() { + return id; + } + + public void setID(String id) { + this.id = id; + } + + @XmlElement(name="Status") + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @XmlElement(name="Contents") + public String getContents() { + return contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + @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 + ((contents == null) ? 0 : contents.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((link == null) ? 0 : link.hashCode()); + result = prime * result + ((status == null) ? 0 : status.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; + AuthenticatorModification other = (AuthenticatorModification) obj; + if (contents == null) { + if (other.contents != null) + return false; + } else if (!contents.equals(other.contents)) + 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; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + 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 AuthenticatorModification valueOf(String string) throws Exception { + try { + return (AuthenticatorModification)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + public static void main(String args[]) throws Exception { + + AuthenticatorModification before = new AuthenticatorModification(); + before.setID("authenticator1"); + before.setStatus("ENABLED"); + before.setContents("name=authenticator1\nparam=value"); + + String string = before.toString(); + System.out.println(string); + + AuthenticatorModification after = AuthenticatorModification.valueOf(string); + System.out.println(before.equals(after)); + } +} diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java new file mode 100644 index 000000000..3a99a01d1 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.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.authenticator; + +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("authenticators") +public interface AuthenticatorResource { + + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public AuthenticatorCollection findAuthenticators( + @QueryParam("start") Integer start, + @QueryParam("size") Integer size); + + @GET + @Path("{authenticatorID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public AuthenticatorData getAuthenticator(@PathParam("authenticatorID") String authenticatorID); + + @POST + @ClientResponseType(entityType=AuthenticatorData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response addAuthenticator(AuthenticatorData authenticatorData); + + @PUT + @Path("{authenticatorID}") + @ClientResponseType(entityType=AuthenticatorData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response updateAuthenticator( + @PathParam("authenticatorID") String authenticatorID, + AuthenticatorData authenticatorData); + + @POST + @Path("{authenticatorID}") + @ClientResponseType(entityType=AuthenticatorData.class) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response modifyAuthenticator( + @PathParam("authenticatorID") String authenticatorID, + AuthenticatorModification request); + + @DELETE + @Path("{authenticatorID}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public void removeAuthenticator(@PathParam("authenticatorID") String authenticatorID); +} |