geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r612602 - /geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/
Date Wed, 16 Jan 2008 22:45:25 GMT
Author: djencks
Date: Wed Jan 16 14:45:14 2008
New Revision: 612602

URL: http://svn.apache.org/viewvc?rev=612602&view=rev
Log:
GERONIMO-3752 Uncouple some jacc setup bits

Added:
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
  (with props)
Modified:
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPolicyConfigurationManager.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPrincipalRoleConfigurationManager.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfiguration.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactory.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleMapper.java

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPolicyConfigurationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPolicyConfigurationManager.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPolicyConfigurationManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPolicyConfigurationManager.java
Wed Jan 16 14:45:14 2008
@@ -152,7 +152,7 @@
         }
 
         if (principalRoleMapper != null) {
-            principalRoleMapper.uninstall();
+            principalRoleMapper.uninstall(contextIdToPolicyConfigurationMap.keySet());
         }
 
         for (PolicyConfiguration policyConfiguration : contextIdToPolicyConfigurationMap.values())
{

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPrincipalRoleConfigurationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPrincipalRoleConfigurationManager.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPrincipalRoleConfigurationManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/ApplicationPrincipalRoleConfigurationManager.java
Wed Jan 16 14:45:14 2008
@@ -16,56 +16,48 @@
  */
 package org.apache.geronimo.security.jacc;
 
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Policy;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import javax.security.auth.Subject;
-import javax.security.jacc.PolicyConfiguration;
-import javax.security.jacc.PolicyConfigurationFactory;
+
 import javax.security.jacc.PolicyContextException;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
-import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
-import org.apache.geronimo.security.ContextManager;
-import org.apache.geronimo.security.IdentificationPrincipal;
-import org.apache.geronimo.security.SubjectId;
 
 /**
  * @version $Rev$ $Date$
  */
 public class ApplicationPrincipalRoleConfigurationManager implements PrincipalRoleMapper
{
 
+    private static PrincipalRoleConfigurationFactory roleMapperFactory;
     private final Map principalRoleMap;
 
     public ApplicationPrincipalRoleConfigurationManager(Map principalRoleMap) throws PolicyContextException,
ClassNotFoundException {
         this.principalRoleMap = principalRoleMap;
     }
 
+    public static void setPrincipalRoleConfigurationFactory(PrincipalRoleConfigurationFactory
roleMapperFactory) {
+        if (ApplicationPrincipalRoleConfigurationManager.roleMapperFactory != null) {
+            throw new IllegalStateException("ApplicationPrincipalRoleConfigurationManager.roleMapperFactory
already set");
+        }
+        ApplicationPrincipalRoleConfigurationManager.roleMapperFactory = roleMapperFactory;
+    }
 
-    public void install(Set contextIds) throws PolicyContextException {
-        GeronimoPolicyConfigurationFactory roleMapperFactory = GeronimoPolicyConfigurationFactory.getSingleton();
+    public void install(Set<String> contextIds) throws PolicyContextException {
         if (roleMapperFactory == null) {
-            throw new IllegalStateException("Inconsistent security setup.  GeronimoPolicyConfigurationFactory
is not being used");
+            throw new IllegalStateException("Inconsistent security setup.  PrincipalRoleConfigurationFactory
is not set");
         }
 
-        for (Iterator iterator = contextIds.iterator(); iterator.hasNext();) {
-            String contextID = (String) iterator.next();
-
-            GeronimoPolicyConfiguration geronimoPolicyConfiguration = roleMapperFactory.getGeronimoPolicyConfiguration(contextID);
-            geronimoPolicyConfiguration.setPrincipalRoleMapping(principalRoleMap);
+        for (String contextID : contextIds) {
+            PrincipalRoleConfiguration principalRoleConfiguration = roleMapperFactory.getPrincipalRoleConfiguration(contextID);
+            principalRoleConfiguration.setPrincipalRoleMapping(principalRoleMap);
         }
 
     }
 
 
-    public void uninstall() throws PolicyContextException {
+    public void uninstall(Set<String> contextIds) throws PolicyContextException {
     }
 
 

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfiguration.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfiguration.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfiguration.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfiguration.java
Wed Jan 16 14:45:14 2008
@@ -28,11 +28,10 @@
  * @version $Rev$ $Date$
  */
 
-public interface GeronimoPolicyConfiguration extends PolicyConfiguration {
+public interface GeronimoPolicyConfiguration extends PolicyConfiguration, PrincipalRoleConfiguration
{
 
     boolean implies(ProtectionDomain domain, Permission permission);
 
     void open(boolean remove);
 
-    void setPrincipalRoleMapping(Map principalRoleMap) throws PolicyContextException;
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactory.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactory.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/GeronimoPolicyConfigurationFactory.java
Wed Jan 16 14:45:14 2008
@@ -31,11 +31,11 @@
 /**
  * @version $Rev$ $Date$
  */
-public class GeronimoPolicyConfigurationFactory extends PolicyConfigurationFactory {
+public class GeronimoPolicyConfigurationFactory extends PolicyConfigurationFactory implements
PrincipalRoleConfigurationFactory {
 
-    private final Log log = LogFactory.getLog(GeronimoPolicyConfigurationFactory.class);
+    private static final Log log = LogFactory.getLog(GeronimoPolicyConfigurationFactory.class);
     private static GeronimoPolicyConfigurationFactory singleton;
-    private Map configurations = new HashMap();
+    private Map<String, GeronimoPolicyConfiguration> configurations = new HashMap<String,
GeronimoPolicyConfiguration>();
 
     public GeronimoPolicyConfigurationFactory() {
         synchronized (GeronimoPolicyConfigurationFactory.class) {
@@ -44,6 +44,7 @@
                 throw new IllegalStateException("Singleton already assigned");
             }
             singleton = this;
+            ApplicationPrincipalRoleConfigurationManager.setPrincipalRoleConfigurationFactory(this);
         }
     }
 
@@ -57,7 +58,7 @@
     }
 
     public GeronimoPolicyConfiguration getGeronimoPolicyConfiguration(String contextID) throws
PolicyContextException {
-        GeronimoPolicyConfiguration configuration = (GeronimoPolicyConfiguration) configurations.get(contextID);
+        GeronimoPolicyConfiguration configuration = configurations.get(contextID);
 
         if (configuration == null) {
             throw new PolicyContextException("No policy configuration registered for contextID:
" + contextID);
@@ -68,7 +69,7 @@
     }
 
     public PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) throws
PolicyContextException {
-        GeronimoPolicyConfiguration configuration = (GeronimoPolicyConfiguration) configurations.get(contextID);
+        GeronimoPolicyConfiguration configuration = configurations.get(contextID);
 
         if (configuration == null) {
             configuration = new PolicyConfigurationGeneric(contextID);
@@ -90,5 +91,9 @@
 
     static GeronimoPolicyConfigurationFactory getSingleton() {
         return singleton;
+    }
+
+    public PrincipalRoleConfiguration getPrincipalRoleConfiguration(String contextID) throws
PolicyContextException {
+        return getGeronimoPolicyConfiguration(contextID);
     }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PolicyConfigurationGeneric.java
Wed Jan 16 14:45:14 2008
@@ -24,9 +24,8 @@
 import java.security.ProtectionDomain;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import javax.security.jacc.PolicyContextException;
 
@@ -41,12 +40,12 @@
 
     private final String contextID;
     private int state;
-    private final HashMap rolePermissionsMap = new HashMap();
-    private final HashMap principalRoleMapping = new HashMap();
+    private final HashMap<String, Permissions> rolePermissionsMap = new HashMap<String,
Permissions>();
+    private final HashMap<Principal, Set<String>> principalRoleMapping = new
HashMap<Principal, Set<String>>();
     private Permissions unchecked = null;
     private Permissions excluded = null;
 
-    private final HashMap principalPermissionsMap = new HashMap();
+    private final HashMap<Principal, Permissions> principalPermissionsMap = new HashMap<Principal,
Permissions>();
 
     PolicyConfigurationGeneric(String contextID) {
         this.contextID = contextID;
@@ -66,9 +65,7 @@
         Principal[] principals = domain.getPrincipals();
         if (principals.length == 0) return false;
 
-        for (int i = 0; i < principals.length; i++) {
-            Principal principal = principals[i];
-
+        for (Principal principal : principals) {
             Permissions permissions = (Permissions) principalPermissionsMap.get(principal);
 
             if (permissions != null && permissions.implies(permission)) return true;
@@ -94,7 +91,7 @@
     public void addToRole(String roleName, Permission permission) throws PolicyContextException
{
         if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
 
-        Permissions permissions = (Permissions) rolePermissionsMap.get(roleName);
+        Permissions permissions = rolePermissionsMap.get(roleName);
         if (permissions == null) {
             permissions = new Permissions();
             rolePermissionsMap.put(roleName, permissions);
@@ -165,21 +162,20 @@
     public void commit() throws PolicyContextException {
         if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
 
-        for (Iterator principalEntries = principalRoleMapping.entrySet().iterator(); principalEntries.hasNext();
) {
-            Map.Entry principalEntry = (Map.Entry) principalEntries.next();
-            Principal principal = (Principal) principalEntry.getKey();
-            Permissions principalPermissions = (Permissions) principalPermissionsMap.get(principal);
+        for (Map.Entry<Principal, Set<String>> principalEntry : principalRoleMapping.entrySet())
{
+            Principal principal = principalEntry.getKey();
+            Permissions principalPermissions = principalPermissionsMap.get(principal);
 
             if (principalPermissions == null) {
                 principalPermissions = new Permissions();
                 principalPermissionsMap.put(principal, principalPermissions);
             }
 
-            HashSet roleSet = (HashSet) principalEntry.getValue();
-            for (Iterator roles = roleSet.iterator(); roles.hasNext(); ) {
-                Permissions permissions = (Permissions) rolePermissionsMap.get(roles.next());
+            Set<String> roleSet = principalEntry.getValue();
+            for (String role : roleSet) {
+                Permissions permissions = rolePermissionsMap.get(role);
                 if (permissions == null) continue;
-                for (Enumeration rolePermissions = permissions.elements(); rolePermissions.hasMoreElements();
) {
+                for (Enumeration rolePermissions = permissions.elements(); rolePermissions.hasMoreElements();)
{
                     principalPermissions.add((Permission) rolePermissions.nextElement());
                 }
             }

Added: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java?rev=612602&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
Wed Jan 16 14:45:14 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.util.Map;
+
+import javax.security.jacc.PolicyContextException;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface PrincipalRoleConfiguration {
+    void setPrincipalRoleMapping(Map principalRoleMap) throws PolicyContextException;
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java?rev=612602&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
Wed Jan 16 14:45:14 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.PolicyContextException;
+
+/**
+ * An implementation of this interface, when instantiated, must register with the static
+ * ApplicationPrincipalRoleConfigurationManager.setPrincipalRoleConfigurationFactory
+ * method.
+ *
+ * @version $Rev:$ $Date:$
+ */
+public interface PrincipalRoleConfigurationFactory {
+
+    PrincipalRoleConfiguration getPrincipalRoleConfiguration(String contextID) throws PolicyContextException;
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleConfigurationFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleMapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleMapper.java?rev=612602&r1=612601&r2=612602&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleMapper.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/jacc/PrincipalRoleMapper.java
Wed Jan 16 14:45:14 2008
@@ -22,7 +22,7 @@
 /**
  */
 public interface PrincipalRoleMapper {
-    void install(Set contextIds) throws PolicyContextException;
+    void install(Set<String> contextIds) throws PolicyContextException;
 
-    void uninstall() throws PolicyContextException;
+    void uninstall(Set<String> contextIds) throws PolicyContextException;
 }



Mime
View raw message