portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r692440 - in /portals/jetspeed-2/portal/branches/security-refactoring: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/ jetspeed-api/src/main/java/org/apache/jetspeed/security/ jetspeed-api/src/main/java/org/apa...
Date Fri, 05 Sep 2008 13:38:36 GMT
Author: ate
Date: Fri Sep  5 06:38:34 2008
New Revision: 692440

URL: http://svn.apache.org/viewvc?rev=692440&view=rev
Log:
Implementation of required associations on creation of a principal 

Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationType.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalStorageManager.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java?rev=692440&r1=692439&r2=692440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
Fri Sep  5 06:38:34 2008
@@ -27,6 +27,7 @@
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationHandler;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationReference;
+import org.apache.jetspeed.security.JetspeedPrincipalAssociationType;
 import org.apache.jetspeed.security.JetspeedPrincipalType;
 import org.apache.jetspeed.security.PrincipalAlreadyExistsException;
 import org.apache.jetspeed.security.PrincipalAssociationNotAllowedException;
@@ -78,6 +79,7 @@
 
     private JetspeedPrincipalType principalType;
     private Map<AssociationHandlerKey, JetspeedPrincipalAssociationHandler> assHandlers
= new HashMap<AssociationHandlerKey, JetspeedPrincipalAssociationHandler>();
+    private Map<AssociationHandlerKey, JetspeedPrincipalAssociationType> reqAssociations
= new HashMap<AssociationHandlerKey, JetspeedPrincipalAssociationType>();
     private JetspeedPrincipalAccessManager jpam;
     private JetspeedPrincipalStorageManager jpsm;
     private JetspeedPrincipalPermissionStorageManager jppsm;
@@ -198,6 +200,10 @@
                                                 jpah.getAssociationType().getAssociationName()
+ " already defined");
             }
             assHandlers.put(key, jpah);
+            if (jpah.getAssociationType().isRequired())
+            {
+                reqAssociations.put(key,jpah.getAssociationType());
+            }
         }
         else
         {
@@ -215,10 +221,40 @@
     }
 
     public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference>
associations)
-                                                                                        
                         throws PrincipalAlreadyExistsException,
-                                                                                        
                         PrincipalAssociationRequiredException
+        throws PrincipalAssociationNotAllowedException, PrincipalAlreadyExistsException,
PrincipalAssociationRequiredException
     {
         validatePrincipal(principal);
+        
+        if (associations != null)
+        {
+            AssociationHandlerKey key = null;
+            Map<AssociationHandlerKey, JetspeedPrincipalAssociationType> reqAss = new
HashMap<AssociationHandlerKey, JetspeedPrincipalAssociationType>(reqAssociations);
+            for (JetspeedPrincipalAssociationReference ref : associations)
+            {
+                if (ref.ref.isTransient())
+                {
+                    throw new IllegalArgumentException("Associated principal of type "+ref.ref.getType().getName()
+" is transient");
+                }
+                if (ref.type == JetspeedPrincipalAssociationReference.Type.FROM)
+                {
+                    key = new AssociationHandlerKey(ref.associationName, ref.ref.getType().getName(),
principalType.getName());
+                }
+                else
+                {
+                    key = new AssociationHandlerKey(ref.associationName, ref.ref.getType().getName(),
principalType.getName());
+                }
+                if (!assHandlers.containsKey(key))
+                {
+                    throw new PrincipalAssociationNotAllowedException();
+                }
+                reqAss.remove(key);
+            }
+            if (!reqAss.isEmpty())
+            {
+                // TODO: proper named message or better replace with SecurityException(KeyedMessage)
+                throw new PrincipalAssociationRequiredException();
+            }
+        }
         jpsm.addPrincipal(principal, associations);
     }
 
@@ -256,7 +292,7 @@
         validatePrincipal(principal);
         jppsm.revokePermission(principal, permission);
     }
-    
+
     //
     // JetspeedPrincipalAssociationHandler interface invocations
     //
@@ -283,5 +319,4 @@
             jpah.remove(from, to);
         }
     }
-    
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationType.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationType.java?rev=692440&r1=692439&r2=692440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationType.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationType.java
Fri Sep  5 06:38:34 2008
@@ -30,5 +30,5 @@
 
     JetspeedPrincipalType getToPrincipalType();
 
-    boolean isReadonlyMapping(); // mapped associations cannot be added or removed other
then by removal of the Principal(s) itself
+    boolean isRequired(); // associations cannot be added or removed other then by removal
of the Principal(s) itself
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalStorageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalStorageManager.java?rev=692440&r1=692439&r2=692440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalStorageManager.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalStorageManager.java
Fri Sep  5 06:38:34 2008
@@ -22,6 +22,7 @@
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationReference;
 import org.apache.jetspeed.security.PrincipalAlreadyExistsException;
+import org.apache.jetspeed.security.PrincipalAssociationNotAllowedException;
 import org.apache.jetspeed.security.PrincipalNotFoundException;
 import org.apache.jetspeed.security.PrincipalNotRemovableException;
 import org.apache.jetspeed.security.PrincipalUpdateException;
@@ -35,7 +36,7 @@
     boolean isMapped();
     
     void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference>
associations)
-        throws PrincipalAlreadyExistsException, PrincipalAssociationRequiredException;
+        throws PrincipalAssociationNotAllowedException, PrincipalAlreadyExistsException,
PrincipalAssociationRequiredException;
 
     void updatePrincipal(JetspeedPrincipal principal) throws PrincipalUpdateException, PrincipalNotFoundException;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message