geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r111422 - in geronimo/trunk/modules/security/src: java/org/apache/geronimo/security/jacc test/org/apache/geronimo/security/jacc
Date Thu, 09 Dec 2004 19:54:49 GMT
Author: djencks
Date: Thu Dec  9 11:54:48 2004
New Revision: 111422

URL: http://svn.apache.org/viewcvs?view=rev&rev=111422
Log:
test and doc for a couple of recent bug fixes GERONIMO-515, 516
Added:
   geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/jacc/
   geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactoryTest.java
Modified:
   geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java

Modified: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java?view=diff&rev=111422&p1=geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java&r1=111421&p2=geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java&r2=111422
==============================================================================
--- geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
(original)
+++ geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
Thu Dec  9 11:54:48 2004
@@ -37,9 +37,9 @@
  * @version $Rev$ $Date$
  */
 public class PolicyConfigurationGeneric implements GeronimoPolicyConfiguration {
-    private final static int OPEN = 1;
-    private final static int IN_SERVICE = 2;
-    private final static int DELETED = 3;
+    final static int OPEN = 1;
+    final static int IN_SERVICE = 2;
+    final static int DELETED = 3;
 
     private final String contextID;
     private int state;
@@ -222,6 +222,9 @@
 
     //TODO I have no idea what side effects this might have, but it's needed in some form
from GeronimoPolicyConfigurationFactory.
     //see JACC spec 1.0 section 3.1.1.1 discussion of in service and deleted.
+    //spec p. 31 3.1.7 on the effects of remove:
+    //If the getPolicyConfiguration method  is used, the value true should be passed as the
second
+    //  argument to cause the  corresponding policy statements to be deleted from the context.
     public void open(boolean remove) {
         if (remove) {
             rolePermissionsMap.clear();
@@ -231,5 +234,9 @@
             principalPermissionsMap.clear();
         }
         state = OPEN;
+    }
+
+    int getState() {
+        return state;
     }
 }

Added: geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactoryTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactoryTest.java?view=auto&rev=111422
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactoryTest.java
Thu Dec  9 11:54:48 2004
@@ -0,0 +1,87 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.security.jacc;
+
+import javax.security.jacc.PolicyConfiguration;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class GeronimoPolicyConfigurationFactoryTest extends TestCase {
+
+    private static final String CONTEXT_ID = "testContextID";
+    private GeronimoPolicyConfigurationFactory policyConfigurationFactory = new GeronimoPolicyConfigurationFactory();
+
+
+    /**
+     * 3.1.1.1 specifies that policyConfigurationFactory.getPolicyConfiguration always returns
an open PolicyConfiguration
+     * @throws Exception
+     */
+    public void testPolicyConfigurationOpen() throws Exception {
+        testPolicyConfigurationOpen(false);
+        testPolicyConfigurationOpen(true);
+        testPolicyConfigurationOpen(false);
+    }
+
+    private void testPolicyConfigurationOpen(boolean remove) throws Exception {
+        PolicyConfigurationGeneric policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
remove);
+        assertEquals(PolicyConfigurationGeneric.OPEN, policyConfiguration.getState());
+        policyConfiguration.commit();
+        assertEquals(PolicyConfigurationGeneric.IN_SERVICE, policyConfiguration.getState());
+        policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
remove);
+        assertEquals(PolicyConfigurationGeneric.OPEN, policyConfiguration.getState());
+        policyConfiguration.delete();
+        assertEquals(PolicyConfigurationGeneric.DELETED, policyConfiguration.getState());
+        policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
remove);
+        assertEquals(PolicyConfigurationGeneric.OPEN, policyConfiguration.getState());
+        policyConfiguration = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
remove);
+        assertEquals(PolicyConfigurationGeneric.OPEN, policyConfiguration.getState());
+    }
+
+    /**
+     * spec p. 71:
+     * For a given value of policy context identifier, this method must always return the
same instance of PolicyConfiguration and there must be at
+     *  most one actual instance of a PolicyConfiguration with a given policy context identifier
(during a process context).
+     *   
+     * @throws Exception
+     */
+    public void testSamePolicyConfigurationInstance() throws Exception {
+        PolicyConfigurationGeneric policyConfiguration1 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
false);
+        PolicyConfigurationGeneric policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
false);
+        assertSame(policyConfiguration1, policyConfiguration2);
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
false);
+        assertSame(policyConfiguration1, policyConfiguration2);
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
true);
+        assertSame(policyConfiguration1, policyConfiguration2);
+        policyConfiguration2.commit();
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
false);
+        assertSame(policyConfiguration1, policyConfiguration2);
+        policyConfiguration2.commit();
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
true);
+        assertSame(policyConfiguration1, policyConfiguration2);
+
+        policyConfiguration2.delete();
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
false);
+        assertSame(policyConfiguration1, policyConfiguration2);
+        policyConfiguration2.delete();
+        policyConfiguration2 = (PolicyConfigurationGeneric) policyConfigurationFactory.getPolicyConfiguration(CONTEXT_ID,
true);
+        assertSame(policyConfiguration1, policyConfiguration2);
+
+    }
+}

Mime
View raw message