From 5da25881526f090354fa5c0c79278ff0596f7429 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Tue, 23 Oct 2012 18:05:50 -0500
Subject: [PATCH] Enabled account service for TKS and OCSP.

The REST account service has been added to TKS and OCSP to enable
authentication.

Ticket #375
---
 base/ocsp/shared/conf/acl.ldif                     |  3 ++
 .../shared/webapps/ocsp/WEB-INF/auth.properties    |  2 ++
 base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml      | 35 +++++++++++++++++++++
 .../src/com/netscape/ocsp/OCSPApplication.java     |  5 +++
 base/tks/shared/conf/acl.ldif                      |  3 ++
 .../tks/shared/webapps/tks/WEB-INF/auth.properties |  2 ++
 base/tks/shared/webapps/tks/WEB-INF/web.xml        | 36 +++++++++++++++++++++-
 base/tks/src/com/netscape/tks/TKSApplication.java  |  5 +++
 8 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/base/ocsp/shared/conf/acl.ldif b/base/ocsp/shared/conf/acl.ldif
index 94a102b48a451f9ca4104527e302d62a92f6da5f..b1dbc4c5bc3b4873260406539803494c1b0297c5 100644
--- a/base/ocsp/shared/conf/acl.ldif
+++ b/base/ocsp/shared/conf/acl.ldif
@@ -27,3 +27,6 @@ resourceACLS: certServer.ocsp.cas:list:allow (list) group="Online Certificate St
 resourceACLS: certServer.ocsp.certificate:validate:allow (validate) group="Online Certificate Status Manager Agents":Online Certificate Status Manager agents may validate certificate status
 resourceACLS: certServer.ocsp.group:read,modify:allow (modify,read) group="Administrators":Only administrators are allowed to read and modify groups
 resourceACLS: certServer.clone.configuration:read,modify:allow (modify,read) group="Enterprise CA Administrators" || group="Enterprise KRA Administrators" || group="Enterprise OCSP Administrators" || group="Enterprise TKS Administrators":Only Enterprise Administrators are allowed to clone the configuration.
+resourceACLS: certServer.ocsp.account:login,logout:allow (login,logout) user="anybody":Anybody can login and logout
+resourceACLS: certServer.ocsp.groups:execute:allow (execute) group="Administrators":Admins may execute group operations
+resourceACLS: certServer.ocsp.users:execute:allow (execute) group="Administrators":Admins may execute user operations
diff --git a/base/ocsp/shared/webapps/ocsp/WEB-INF/auth.properties b/base/ocsp/shared/webapps/ocsp/WEB-INF/auth.properties
index 3a85e209ff1cc68eca46964ab2e16ad6b6fa9628..8eda09bc3c24cec750cc3ae271ba4388639215f4 100644
--- a/base/ocsp/shared/webapps/ocsp/WEB-INF/auth.properties
+++ b/base/ocsp/shared/webapps/ocsp/WEB-INF/auth.properties
@@ -4,5 +4,7 @@
 # <Rest API URL> = <ACL Resource ID>,<ACL resource operation>
 # ex:      /kra/pki/key/retrieve = certServer.kra.pki.key.retrieve,execute
 
+/ocsp/rest/account/login = certServer.ocsp.account,login
+/ocsp/rest/account/logout = certServer.ocsp.account,logout
 /ocsp/rest/admin/users = certServer.ocsp.users,execute
 /ocsp/rest/admin/groups = certServer.ocsp.groups,execute
diff --git a/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml b/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
index 040e7f7ed1e64c25e55d41679243309cef3ddef5..1deadc9dcafcbaf9a1faab045a74ab4f9d50a967 100644
--- a/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
+++ b/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
@@ -587,5 +587,40 @@
    <session-config>
         <session-timeout>30</session-timeout>
    </session-config>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Account Services</web-resource-name>
+            <url-pattern>/rest/account/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>*</role-name>
+        </auth-constraint>
+        <user-data-constraint>
+            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Admin Services</web-resource-name>
+            <url-pattern>/rest/admin/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>*</role-name>
+        </auth-constraint>
+        <user-data-constraint>
+            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+
+    <login-config>
+        <realm-name>Online Certificate Status Protocol Manager</realm-name>
+    </login-config>
+
+    <security-role>
+        <role-name>*</role-name>
+    </security-role>
+
 </web-app>
 
diff --git a/base/ocsp/src/com/netscape/ocsp/OCSPApplication.java b/base/ocsp/src/com/netscape/ocsp/OCSPApplication.java
index 498aa63ab248c4813c43de42d1cfcbc068ae827b..e6816721cc017ebbfa90e11d662137299b2808ec 100644
--- a/base/ocsp/src/com/netscape/ocsp/OCSPApplication.java
+++ b/base/ocsp/src/com/netscape/ocsp/OCSPApplication.java
@@ -6,6 +6,7 @@ import java.util.Set;
 import javax.ws.rs.core.Application;
 
 import com.netscape.certsrv.base.PKIException;
+import com.netscape.cms.servlet.account.AccountService;
 import com.netscape.cms.servlet.admin.GroupMemberService;
 import com.netscape.cms.servlet.admin.GroupService;
 import com.netscape.cms.servlet.admin.SystemCertService;
@@ -19,6 +20,10 @@ public class OCSPApplication extends Application {
     private Set<Class<?>> classes = new HashSet<Class<?>>();
 
     public OCSPApplication() {
+
+        // account
+        classes.add(AccountService.class);
+
         // installer
         classes.add(SystemConfigService.class);
 
diff --git a/base/tks/shared/conf/acl.ldif b/base/tks/shared/conf/acl.ldif
index b38b5963fb2ed7a33e9379f40fac12cb14ae09a1..bed8ba7cb179ca4b26e8e561a98c37049972196e 100644
--- a/base/tks/shared/conf/acl.ldif
+++ b/base/tks/shared/conf/acl.ldif
@@ -28,3 +28,6 @@ resourceACLS: certServer.tks.randomdata:execute:allow (execute) group="Token Key
 resourceACLS: certServer.tks.registerUser:read,modify:allow (modify,read) group="Enterprise CA Administrators" || group="Enterprise KRA Administrators" || group="Enterprise OCSP Administrators" || group="Enterprise TKS Administrators" || group="Enterprise TPS Administrators":Only Enterprise Administrators are allowed to register a new agent
 resourceACLS: certServer.tks.importTransportCert:read,modify:allow (modify,read) group="Enterprise CA Administrators" || group="Enterprise KRA Administrators" || group="Enterprise OCSP Administrators" || group="Enterprise TKS Administrators" || group="Enterprise TPS Administrators":Only Enterprise Administrators are allowed to import transport certificate
 resourceACLS: certServer.clone.configuration:read,modify:allow (modify,read) group="Enterprise CA Administrators" || group="Enterprise KRA Administrators" || group="Enterprise OCSP Administrators" || group="Enterprise TKS Administrators":Only Enterprise Administrators are allowed to clone the configuration.
+resourceACLS: certServer.tks.account:login,logout:allow (login,logout) user="anybody":Anybody can login and logout
+resourceACLS: certServer.tks.groups:execute:allow (execute) group="Administrators":Admins may execute group operations
+resourceACLS: certServer.tks.users:execute:allow (execute) group="Administrators":Admins may execute user operations
diff --git a/base/tks/shared/webapps/tks/WEB-INF/auth.properties b/base/tks/shared/webapps/tks/WEB-INF/auth.properties
index 29dc9f3fca4551e18ebb3ef2e42482a8f5fb7379..90897683e701cece4d25a294d4986ce768fc1aae 100644
--- a/base/tks/shared/webapps/tks/WEB-INF/auth.properties
+++ b/base/tks/shared/webapps/tks/WEB-INF/auth.properties
@@ -4,5 +4,7 @@
 # <Rest API URL> = <ACL Resource ID>,<ACL resource operation>
 # ex:      /kra/pki/key/retrieve = certServer.kra.pki.key.retrieve,execute
 
+/tks/rest/account/login = certServer.tks.account,login
+/tks/rest/account/logout = certServer.tks.account,logout
 /tks/rest/admin/users = certServer.tks.users,execute
 /tks/rest/admin/groups = certServer.tks.groups,execute
diff --git a/base/tks/shared/webapps/tks/WEB-INF/web.xml b/base/tks/shared/webapps/tks/WEB-INF/web.xml
index a06b2f213f840e0cf49658333cd3112ff8b1918e..b1958c0334af5c6cf5cd6ffa935056bd277a04d0 100644
--- a/base/tks/shared/webapps/tks/WEB-INF/web.xml
+++ b/base/tks/shared/webapps/tks/WEB-INF/web.xml
@@ -417,5 +417,39 @@
    <session-config>
         <session-timeout>30</session-timeout>
    </session-config>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Account Services</web-resource-name>
+            <url-pattern>/rest/account/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>*</role-name>
+        </auth-constraint>
+        <user-data-constraint>
+            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Admin Services</web-resource-name>
+            <url-pattern>/rest/admin/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>*</role-name>
+        </auth-constraint>
+        <user-data-constraint>
+            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
+        </user-data-constraint>
+    </security-constraint>
+
+    <login-config>
+        <realm-name>Token Key Service</realm-name>
+    </login-config>
+
+    <security-role>
+        <role-name>*</role-name>
+    </security-role>
+
 </web-app>
-
diff --git a/base/tks/src/com/netscape/tks/TKSApplication.java b/base/tks/src/com/netscape/tks/TKSApplication.java
index a3d43f6611f8cf1e608b4870ff470ddcdb4597bf..5493bb4da0ffe6c6ba8159bcb1a3efb9da6b2079 100644
--- a/base/tks/src/com/netscape/tks/TKSApplication.java
+++ b/base/tks/src/com/netscape/tks/TKSApplication.java
@@ -6,6 +6,7 @@ import java.util.Set;
 import javax.ws.rs.core.Application;
 
 import com.netscape.certsrv.base.PKIException;
+import com.netscape.cms.servlet.account.AccountService;
 import com.netscape.cms.servlet.admin.GroupMemberService;
 import com.netscape.cms.servlet.admin.GroupService;
 import com.netscape.cms.servlet.admin.SystemCertService;
@@ -19,6 +20,10 @@ public class TKSApplication extends Application {
     private Set<Class<?>> classes = new HashSet<Class<?>>();
 
     public TKSApplication() {
+
+        // account
+        classes.add(AccountService.class);
+
         // installer
         classes.add(SystemConfigService.class);
 
-- 
1.7.11.4

