From f9b214d2c0b17d36acd71a036405ea338b1c833e Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Tue, 27 Aug 2013 14:38:07 -0400
Subject: [PATCH] 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
---
 .../src/com/netscape/certsrv/tps/TPSClient.java    |   2 +
 .../tps/authenticator/AuthenticatorClient.java     |  76 ++++++
 .../tps/authenticator/AuthenticatorCollection.java |  38 +++
 .../tps/authenticator/AuthenticatorData.java       | 169 +++++++++++++
 .../tps/authenticator/AuthenticatorInfo.java       | 152 ++++++++++++
 .../authenticator/AuthenticatorModification.java   | 169 +++++++++++++
 .../tps/authenticator/AuthenticatorResource.java   |  80 +++++++
 .../src/com/netscape/cmstools/cli/TPSCLI.java      |   2 +
 .../tps/authenticator/AuthenticatorAddCLI.java     | 107 +++++++++
 .../tps/authenticator/AuthenticatorCLI.java        | 108 +++++++++
 .../tps/authenticator/AuthenticatorFindCLI.java    |  94 ++++++++
 .../tps/authenticator/AuthenticatorModifyCLI.java  | 107 +++++++++
 .../tps/authenticator/AuthenticatorRemoveCLI.java  |  53 +++++
 .../tps/authenticator/AuthenticatorShowCLI.java    |  87 +++++++
 .../org/dogtagpki/server/tps/TPSApplication.java   |   4 +
 .../src/org/dogtagpki/server/tps/TPSSubsystem.java |   6 +
 .../tps/authenticator/AuthenticatorDatabase.java   |  60 +++++
 .../tps/authenticator/AuthenticatorRecord.java     |  91 +++++++
 .../tps/authenticator/AuthenticatorService.java    | 264 +++++++++++++++++++++
 19 files changed, 1669 insertions(+)
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorCollection.java
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorData.java
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorInfo.java
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorModification.java
 create mode 100644 base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
 create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorDatabase.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorRecord.java
 create mode 100644 base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java

diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 00da49b20f9b0412985564f79d08a6136a4593e6..8381b1ac2454e779d33b582d5755e7c60630b67c 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 0000000000000000000000000000000000000000..82a76cc16e639787e76d5f8f2af1a009636f56ea
--- /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 0000000000000000000000000000000000000000..e1978c8d39d238ac628ba98e8b7a8f501a5d0f18
--- /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 0000000000000000000000000000000000000000..609d241325cb13c90767c81afe5a68603d1da041
--- /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 0000000000000000000000000000000000000000..55ce9b4f38fc5160d2a88ae0ef6fabf53a49cdef
--- /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 0000000000000000000000000000000000000000..fb78415e369fcc86c7ed32df09fa8967653c591f
--- /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 0000000000000000000000000000000000000000..3a99a01d129e45fb73cd42df26ab3dd385ed37a6
--- /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);
+}
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 7a14b59f64e2d7b0f5d8a8a79d583f7be6ae685a..8adf09edea0a3dbb9bc2f8a005f5cddb5e241994 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
@@ -22,6 +22,7 @@ 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.tps.authenticator.AuthenticatorCLI;
 import com.netscape.cmstools.tps.cert.TPSCertCLI;
 import com.netscape.cmstools.tps.connection.ConnectionCLI;
 import com.netscape.cmstools.tps.token.TokenCLI;
@@ -38,6 +39,7 @@ public class TPSCLI extends SubsystemCLI {
         super("tps", "TPS management commands", mainCLI);
 
         addModule(new ActivityCLI(this));
+        addModule(new AuthenticatorCLI(this));
         addModule(new ConnectionCLI(this));
         addModule(new GroupCLI(this));
         addModule(new TokenCLI(this));
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..836f8bd858cbc4d4d47b0bed14ef79d25005f85b
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
@@ -0,0 +1,107 @@
+// --- 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.authenticator;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorAddCLI extends CLI {
+
+    public AuthenticatorCLI authenticatorCLI;
+
+    public AuthenticatorAddCLI(AuthenticatorCLI authenticatorCLI) {
+        super("add", "Add authenticator", authenticatorCLI);
+        this.authenticatorCLI = authenticatorCLI;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(getFullName() + " <Authenticator ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "status", true, "Status: ENABLED, DISABLED.");
+        option.setArgName("status");
+        option.setRequired(true);
+        options.addOption(option);
+
+        option = new Option(null, "contents", true, "Input file containing authenticator attributes.");
+        option.setArgName("file");
+        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 authenticatorID = cmdArgs[0];
+        String status = cmd.getOptionValue("status");
+        String contents = cmd.getOptionValue("contents");
+
+        AuthenticatorData authenticatorData = new AuthenticatorData();
+        authenticatorData.setID(authenticatorID);
+        authenticatorData.setStatus(status);
+
+        if (contents != null) {
+            try (BufferedReader in = new BufferedReader(new FileReader(contents));
+                StringWriter sw = new StringWriter();
+                PrintWriter out = new PrintWriter(sw, true)) {
+
+                String line;
+                while ((line = in.readLine()) != null) {
+                    out.println(line);
+                }
+
+                authenticatorData.setContents(sw.toString());
+            }
+        }
+
+        authenticatorData = authenticatorCLI.authenticatorClient.addAuthenticator(authenticatorData);
+
+        MainCLI.printMessage("Added authenticator \"" + authenticatorID + "\"");
+
+        AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..198982a0623ca1ed3fa9eb0b34cc556a3458f91c
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java
@@ -0,0 +1,108 @@
+// --- 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.authenticator;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Arrays;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorClient;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorInfo;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorCLI extends CLI {
+
+    public AuthenticatorClient authenticatorClient;
+
+    public AuthenticatorCLI(CLI parent) {
+        super("authenticator", "Authenticator management commands", parent);
+
+        addModule(new AuthenticatorAddCLI(this));
+        addModule(new AuthenticatorFindCLI(this));
+        addModule(new AuthenticatorModifyCLI(this));
+        addModule(new AuthenticatorRemoveCLI(this));
+        addModule(new AuthenticatorShowCLI(this));
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        client = parent.getClient();
+        authenticatorClient = (AuthenticatorClient)parent.getClient("authenticator");
+
+        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 printAuthenticatorInfo(AuthenticatorInfo authenticatorInfo) {
+        System.out.println("  Authenticator ID: " + authenticatorInfo.getID());
+        if (authenticatorInfo.getStatus() != null) System.out.println("  Status: " + authenticatorInfo.getStatus());
+
+        Link link = authenticatorInfo.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
+        }
+    }
+
+    public static void printAuthenticatorData(AuthenticatorData authenticatorData) throws IOException {
+        System.out.println("  Authenticator ID: " + authenticatorData.getID());
+        if (authenticatorData.getStatus() != null) System.out.println("  Status: " + authenticatorData.getStatus());
+
+        System.out.println("  Contents:");
+        String contents = authenticatorData.getContents();
+        if (contents != null) {
+            BufferedReader in = new BufferedReader(new StringReader(contents));
+            String line;
+            while ((line = in.readLine()) != null) {
+                System.out.println("    " + line);
+            }
+        }
+
+        Link link = authenticatorData.getLink();
+        if (verbose && link != null) {
+            System.out.println("  Link: " + link.getHref());
+        }
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..34c291fd1247a49688750594751ecff8aafd57ca
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.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.authenticator;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorCollection;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorInfo;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorFindCLI extends CLI {
+
+    public AuthenticatorCLI authenticatorCLI;
+
+    public AuthenticatorFindCLI(AuthenticatorCLI tokenCLI) {
+        super("find", "Find authenticators", tokenCLI);
+        this.authenticatorCLI = 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);
+
+        AuthenticatorCollection result = authenticatorCLI.authenticatorClient.findAuthenticators(start, size);
+        Collection<AuthenticatorInfo> authenticators = result.getEntries();
+
+        MainCLI.printMessage(authenticators.size() + " authenticator(s) matched");
+
+        boolean first = true;
+
+        for (AuthenticatorInfo authenticatorInfo : authenticators) {
+
+            if (first) {
+                first = false;
+            } else {
+                System.out.println();
+            }
+
+            AuthenticatorCLI.printAuthenticatorInfo(authenticatorInfo);
+        }
+
+        MainCLI.printMessage("Number of entries returned " + authenticators.size());
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5fc01e07b1e3057dbf575be867884f9b395eecc
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
@@ -0,0 +1,107 @@
+// --- 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.authenticator;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorModification;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorModifyCLI extends CLI {
+
+    public AuthenticatorCLI authenticatorCLI;
+
+    public AuthenticatorModifyCLI(AuthenticatorCLI authenticatorCLI) {
+        super("mod", "Modify authenticator", authenticatorCLI);
+        this.authenticatorCLI = authenticatorCLI;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(getFullName() + " <Authenticator ID> [OPTIONS...]", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "status", true, "Status: ENABLED, DISABLED.");
+        option.setArgName("status");
+        options.addOption(option);
+
+        option = new Option(null, "contents", true, "Input file containing authenticator attributes.");
+        option.setArgName("file");
+        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 authenticatorID = cmdArgs[0];
+        String status = cmd.getOptionValue("status");
+        String contents = cmd.getOptionValue("contents");
+
+        AuthenticatorModification authenticatorModification = new AuthenticatorModification();
+        authenticatorModification.setID(authenticatorID);
+        authenticatorModification.setStatus(status);
+
+        if (contents != null) {
+            // load contents from file
+            StringWriter sw = new StringWriter();
+            try (BufferedReader in = new BufferedReader(new FileReader(contents));
+                PrintWriter out = new PrintWriter(sw, true)) {
+
+                String line;
+                while ((line = in.readLine()) != null) {
+                    out.println(line);
+                }
+
+                authenticatorModification.setContents(sw.toString());
+            }
+        }
+
+        AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.modifyAuthenticator(authenticatorID, authenticatorModification);
+
+        MainCLI.printMessage("Modified authenticator \"" + authenticatorID + "\"");
+
+        AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..6d565bc9614a6293ab4a226070ff82e7fd876314
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.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.authenticator;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorRemoveCLI extends CLI {
+
+    public AuthenticatorCLI authenticatorCLI;
+
+    public AuthenticatorRemoveCLI(AuthenticatorCLI authenticatorCLI) {
+        super("del", "Remove authenticator", authenticatorCLI);
+        this.authenticatorCLI = authenticatorCLI;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(getFullName() + " <Authenticator ID>", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        if (args.length != 1) {
+            printHelp();
+            System.exit(1);
+        }
+
+        String authenticatorID = args[0];
+
+        authenticatorCLI.authenticatorClient.removeAuthenticator(authenticatorID);
+
+        MainCLI.printMessage("Deleted authenticator \"" + authenticatorID + "\"");
+    }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
new file mode 100644
index 0000000000000000000000000000000000000000..d4549aa0fada578f1b87c8536ba0cfcd3a90297c
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
@@ -0,0 +1,87 @@
+// --- 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.authenticator;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorShowCLI extends CLI {
+
+    public AuthenticatorCLI authenticatorCLI;
+
+    public AuthenticatorShowCLI(AuthenticatorCLI authenticatorCLI) {
+        super("show", "Show authenticator", authenticatorCLI);
+        this.authenticatorCLI = authenticatorCLI;
+    }
+
+    public void printHelp() {
+        formatter.printHelp(getFullName() + " <Authenticator ID>", options);
+    }
+
+    public void execute(String[] args) throws Exception {
+
+        Option option = new Option(null, "contents", true, "Output file to store authenticator attributes.");
+        option.setArgName("file");
+        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 authenticatorID = args[0];
+        String file = cmd.getOptionValue("contents");
+
+        AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.getAuthenticator(authenticatorID);
+
+        MainCLI.printMessage("Authenticator \"" + authenticatorID + "\"");
+        AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+
+        if (file != null) {
+            // store contents to file
+            PrintWriter out = new PrintWriter(new FileWriter(file));
+            String contents = authenticatorData.getContents();
+            if (contents != null) out.print(contents);
+            out.close();
+        }
+    }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java
index a7722720af2edafd748255ba57067451d6f9de0d..ff66e6b75f0bc49f8b8591596ebcaeda54731ac5 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSApplication.java
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import javax.ws.rs.core.Application;
 
+import org.dogtagpki.server.tps.authenticator.AuthenticatorService;
 import org.dogtagpki.server.tps.cert.TPSCertService;
 import org.dogtagpki.server.tps.connection.ConnectionService;
 import org.dogtagpki.server.tps.logging.ActivityService;
@@ -68,6 +69,9 @@ public class TPSApplication extends Application {
         // activities
         classes.add(ActivityService.class);
 
+        // authenticators
+        classes.add(AuthenticatorService.class);
+
         // connections
         classes.add(ConnectionService.class);
 
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
index 13b90fe05dc61bf8beb8a9cac2bfafd0bd49b572..8814014dacb07e7b2a0bac9a5609850e4f8cb1ba 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/TPSSubsystem.java
@@ -17,6 +17,7 @@
 // --- END COPYRIGHT BLOCK ---
 package org.dogtagpki.server.tps;
 
+import org.dogtagpki.server.tps.authenticator.AuthenticatorDatabase;
 import org.dogtagpki.server.tps.cert.TPSCertDatabase;
 import org.dogtagpki.server.tps.connection.ConnectionDatabase;
 import org.dogtagpki.server.tps.logging.ActivityDatabase;
@@ -50,6 +51,7 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
     public IConfigStore config;
 
     public ActivityDatabase activityDatabase = new ActivityDatabase();
+    public AuthenticatorDatabase authenticatorDatabase = new AuthenticatorDatabase();
     public ConnectionDatabase connectionDatabase = new ConnectionDatabase();
     public TPSCertDatabase certDatabase = new TPSCertDatabase();
     public TokenDatabase tokenDatabase = new TokenDatabase();
@@ -123,6 +125,10 @@ public class TPSSubsystem implements IAuthority, ISubsystem {
         return activityDatabase;
     }
 
+    public AuthenticatorDatabase getAuthenticatorDatabase() {
+        return authenticatorDatabase;
+    }
+
     public ConnectionDatabase getConnectionDatabase() {
         return connectionDatabase;
     }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorDatabase.java
new file mode 100644
index 0000000000000000000000000000000000000000..42fe9aae4ee382a34baf7c933cb852dda4d218e0
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorDatabase.java
@@ -0,0 +1,60 @@
+// --- 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.authenticator;
+
+import com.netscape.cmscore.dbs.Database;
+
+/**
+ * This class implements in-memory connection database. In the future this
+ * will be replaced with LDAP database.
+ *
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorDatabase extends Database<AuthenticatorRecord> {
+
+    public AuthenticatorDatabase() {
+        super("Authenticator");
+
+        // add sample records
+        try {
+            AuthenticatorRecord record1 = new AuthenticatorRecord();
+            record1.setID("authenticator1");
+            record1.setStatus("ENABLED");
+            record1.setContents("name=authenticator1\nparam=value");
+            addRecord(record1);
+
+            AuthenticatorRecord record2 = new AuthenticatorRecord();
+            record2.setID("authenticator2");
+            record2.setStatus("DISABLED");
+            record2.setContents("name=authenticator2\nparam=value");
+            addRecord(record2);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void addRecord(AuthenticatorRecord authenticatorRecord) throws Exception {
+        addRecord(authenticatorRecord.getID(), authenticatorRecord);
+    }
+
+    public void updateRecord(AuthenticatorRecord authenticatorRecord) throws Exception {
+        updateRecord(authenticatorRecord.getID(), authenticatorRecord);
+    }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorRecord.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorRecord.java
new file mode 100644
index 0000000000000000000000000000000000000000..46fa438763a2729255930dc20e2e223532f1927b
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorRecord.java
@@ -0,0 +1,91 @@
+// --- 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.authenticator;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorRecord {
+
+    String id;
+    String status;
+    String contents;
+
+    public String getID() {
+        return id;
+    }
+
+    public void setID(String id) {
+        this.id = id;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getContents() {
+        return contents;
+    }
+
+    public void setContents(String contents) {
+        this.contents = contents;
+    }
+
+    @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 + ((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;
+        AuthenticatorRecord other = (AuthenticatorRecord) 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 (status == null) {
+            if (other.status != null)
+                return false;
+        } else if (!status.equals(other.status))
+            return false;
+        return true;
+    }
+}
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
new file mode 100644
index 0000000000000000000000000000000000000000..dfe042b6641db160f72df72d4be70398034ddc41
--- /dev/null
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/authenticator/AuthenticatorService.java
@@ -0,0 +1,264 @@
+// --- 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.authenticator;
+
+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.apps.CMS;
+import com.netscape.certsrv.base.PKIException;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorCollection;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorInfo;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorModification;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorResource;
+import com.netscape.cms.servlet.base.PKIService;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorService extends PKIService implements AuthenticatorResource {
+
+    public final static int DEFAULT_SIZE = 20;
+
+    public AuthenticatorService() {
+        CMS.debug("AuthenticatorService.<init>()");
+    }
+
+    public AuthenticatorInfo createAuthenticatorInfo(AuthenticatorRecord authenticatorRecord) {
+
+        AuthenticatorInfo authenticatorInfo = new AuthenticatorInfo();
+        authenticatorInfo.setID(authenticatorRecord.getID());
+        authenticatorInfo.setStatus(authenticatorRecord.getStatus());
+
+        String authenticatorID = authenticatorRecord.getID();
+        try {
+            authenticatorID = URLEncoder.encode(authenticatorID, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+
+        URI uri = uriInfo.getBaseUriBuilder().path(AuthenticatorResource.class).path("{authenticatorID}").build(authenticatorID);
+        authenticatorInfo.setLink(new Link("self", uri));
+
+        return authenticatorInfo;
+    }
+
+    public AuthenticatorData createAuthenticatorData(AuthenticatorRecord authenticatorRecord) {
+
+        AuthenticatorData authenticatorData = new AuthenticatorData();
+        authenticatorData.setID(authenticatorRecord.getID());
+        authenticatorData.setStatus(authenticatorRecord.getStatus());
+        authenticatorData.setContents(authenticatorRecord.getContents());
+
+        String authenticatorID = authenticatorRecord.getID();
+        try {
+            authenticatorID = URLEncoder.encode(authenticatorID, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+
+        URI uri = uriInfo.getBaseUriBuilder().path(AuthenticatorResource.class).path("{authenticatorID}").build(authenticatorID);
+        authenticatorData.setLink(new Link("self", uri));
+
+        return authenticatorData;
+    }
+
+    public AuthenticatorRecord createAuthenticatorRecord(AuthenticatorData authenticatorData) {
+
+        AuthenticatorRecord authenticatorRecord = new AuthenticatorRecord();
+        authenticatorRecord.setID(authenticatorData.getID());
+        authenticatorRecord.setStatus(authenticatorData.getStatus());
+        authenticatorRecord.setContents(authenticatorData.getContents());
+
+        return authenticatorRecord;
+    }
+
+    @Override
+    public AuthenticatorCollection findAuthenticators(Integer start, Integer size) {
+
+        CMS.debug("AuthenticatorService.findAuthenticators()");
+
+        try {
+            start = start == null ? 0 : start;
+            size = size == null ? DEFAULT_SIZE : size;
+
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+
+            Iterator<AuthenticatorRecord> authenticators = database.getRecords().iterator();
+
+            AuthenticatorCollection response = new AuthenticatorCollection();
+
+            int i = 0;
+
+            // skip to the start of the page
+            for ( ; i<start && authenticators.hasNext(); i++) authenticators.next();
+
+            // return entries up to the page size
+            for ( ; i<start+size && authenticators.hasNext(); i++) {
+                response.addEntry(createAuthenticatorInfo(authenticators.next()));
+            }
+
+            // count the total entries
+            for ( ; authenticators.hasNext(); i++) authenticators.next();
+
+            if (start > 0) {
+                URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start-size, 0)).build();
+                response.addLink(new Link("prev", uri));
+            }
+
+            if (start+size < i) {
+                URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start+size).build();
+                response.addLink(new Link("next", uri));
+            }
+
+            return response;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+
+    @Override
+    public AuthenticatorData getAuthenticator(String authenticatorID) {
+
+        CMS.debug("AuthenticatorService.getAuthenticator(\"" + authenticatorID + "\")");
+
+        try {
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+
+            return createAuthenticatorData(database.getRecord(authenticatorID));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+
+    @Override
+    public Response addAuthenticator(AuthenticatorData authenticatorData) {
+
+        CMS.debug("AuthenticatorService.addAuthenticator(\"" + authenticatorData.getID() + "\")");
+
+        try {
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+
+            database.addRecord(createAuthenticatorRecord(authenticatorData));
+            authenticatorData = createAuthenticatorData(database.getRecord(authenticatorData.getID()));
+
+            return Response
+                    .created(authenticatorData.getLink().getHref())
+                    .entity(authenticatorData)
+                    .type(MediaType.APPLICATION_XML)
+                    .build();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+
+    @Override
+    public Response updateAuthenticator(String authenticatorID, AuthenticatorData authenticatorData) {
+
+        CMS.debug("AuthenticatorService.updateAuthenticator(\"" + authenticatorID + "\")");
+
+        try {
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+
+            database.updateRecord(createAuthenticatorRecord(authenticatorData));
+            authenticatorData = createAuthenticatorData(database.getRecord(authenticatorID));
+
+            return Response
+                    .ok(authenticatorData)
+                    .type(MediaType.APPLICATION_XML)
+                    .build();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+
+    @Override
+    public Response modifyAuthenticator(String authenticatorID, AuthenticatorModification request) {
+
+        CMS.debug("AuthenticatorService.modifyAuthenticator(\"" + authenticatorID + "\", request");
+
+        try {
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+
+            AuthenticatorRecord authenticatorRecord = database.getRecord(authenticatorID);
+
+            String status = request.getStatus();
+            if (status != null) {
+                authenticatorRecord.setStatus(status);
+            }
+
+            String contents = request.getContents();
+            if (contents != null) {
+                authenticatorRecord.setContents(contents);
+            }
+
+            database.updateRecord(authenticatorRecord);
+            AuthenticatorData authenticatorData = createAuthenticatorData(database.getRecord(authenticatorID));
+
+            return Response
+                    .ok(authenticatorData)
+                    .type(MediaType.APPLICATION_XML)
+                    .build();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void removeAuthenticator(String authenticatorID) {
+
+        CMS.debug("AuthenticatorService.removeAuthenticator(\"" + authenticatorID + "\")");
+
+        try {
+            TPSSubsystem subsystem = TPSSubsystem.getInstance();
+            AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
+            database.removeRecord(authenticatorID);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new PKIException(e.getMessage());
+        }
+    }
+}
-- 
1.8.1.4

