portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r692153 - 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 Thu, 04 Sep 2008 16:47:27 GMT
Author: ate
Date: Thu Sep  4 09:47:26 2008
New Revision: 692153

URL: http://svn.apache.org/viewvc?rev=692153&view=rev
Log:
further improvement of api and implementation of the BaseJetspeedPrincipalManager

Added:
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
  (with props)
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/JetspeedPrincipalAssociationHandler.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.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=692153&r1=692152&r2=692153&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
Thu Sep  4 09:47:26 2008
@@ -19,23 +19,28 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.jetspeed.security.DependentPrincipalException;
 import org.apache.jetspeed.security.JetspeedPermission;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalAssociationHandler;
-import org.apache.jetspeed.security.JetspeedPrincipalManager;
+import org.apache.jetspeed.security.JetspeedPrincipalAssociationReference;
 import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.PrincipalAlreadyExistsException;
+import org.apache.jetspeed.security.PrincipalAssociationRequiredException;
 import org.apache.jetspeed.security.PrincipalNotFoundException;
 import org.apache.jetspeed.security.PrincipalNotRemovableException;
+import org.apache.jetspeed.security.PrincipalUpdateException;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
+import org.apache.jetspeed.security.spi.JetspeedPrincipalManagerSPI;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalPermissionStorageManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager;
 
 /**
  * @version $Id$
  */
-public abstract class BaseJetspeedPrincipalManager implements JetspeedPrincipalManager
+public abstract class BaseJetspeedPrincipalManager implements JetspeedPrincipalManagerSPI
 {
     private static class AssociationHandlerKey
     {
@@ -71,18 +76,30 @@
 
     private JetspeedPrincipalType principalType;
     private Map<AssociationHandlerKey, JetspeedPrincipalAssociationHandler> assHandlers
= new HashMap<AssociationHandlerKey, JetspeedPrincipalAssociationHandler>();
-    private JetspeedPrincipalAccessManager jetspeedPrincipalAccessManager;
-    private JetspeedPrincipalStorageManager jetspeedPrincipalStorageManager;
-    private JetspeedPrincipalPermissionStorageManager jetspeedPrincipalPermissionStorageManager;
-
-    public BaseJetspeedPrincipalManager(
-                                        JetspeedPrincipalType principalType,
-                                        JetspeedPrincipalStorageManager jetspeedPrincipalStorageManager,
-                                        JetspeedPrincipalPermissionStorageManager jetspeedPrincipalPermissionStorageManager)
+    private JetspeedPrincipalAccessManager jpam;
+    private JetspeedPrincipalStorageManager jpsm;
+    private JetspeedPrincipalPermissionStorageManager jppsm;
+
+    public BaseJetspeedPrincipalManager(JetspeedPrincipalType principalType, JetspeedPrincipalAccessManager
jpam,
+                                        JetspeedPrincipalStorageManager jpsm,
+                                        JetspeedPrincipalPermissionStorageManager jppsm)
     {
         this.principalType = principalType;
-        this.jetspeedPrincipalStorageManager = jetspeedPrincipalStorageManager;
-        this.jetspeedPrincipalPermissionStorageManager = jetspeedPrincipalPermissionStorageManager;
+        this.jpam = jpam;
+        this.jpsm = jpsm;
+        this.jppsm = jppsm;
+    }
+    
+    protected void validatePrincipal(JetspeedPrincipal principal)
+    {
+        if (!principal.getType().getName().equals(principalType.getName()))
+        {
+            throw new IllegalArgumentException("Principal is not of type "+principalType.getName());
+        }
+        if (principal.isTransient())
+        {
+            throw new IllegalArgumentException("Principal is transient");
+        }
     }
 
     public JetspeedPrincipalType getPrincipalType()
@@ -90,91 +107,126 @@
         return principalType;
     }
 
-    public void addAssociationHandler(JetspeedPrincipalAssociationHandler jpah)
+    public boolean principalExists(String name)
+    {
+        return jpam.principalExists(name, principalType);
+    }
+
+    public JetspeedPrincipal getPrincipal(String name)
+    {
+        return jpam.getPrincipal(name, principalType);
+    }
+
+    public List<String> getPrincipalNames(String nameFilter)
     {
-	    if (jpah.getAssociationType().getFromPrincipalType().getName().equals(principalType.getName())
||
-	                    jpah.getAssociationType().getToPrincipalType().getName().equals(principalType.getName()))
-	    {
-	        AssociationHandlerKey key = new AssociationHandlerKey(jpah);
-	        if (assHandlers.containsKey(key))
-	        {
-	            throw new IllegalStateException("An AssociationHandler for "+jpah.getAssociationType().getAssociationName()+"
already defined");
-	        }
-	        assHandlers.put(key, jpah);	        
-	    }
-	    else
-	    {
-	        throw new IllegalArgumentException("AssociationHandler is not handling a "+principalType.getName()+
" JetspeedPrincipal");
-	    }
-	}
+        return jpam.getPrincipalNames(nameFilter, principalType);
+    }
 
-    public void setAccessManager(JetspeedPrincipalAccessManager pam)
+    public List<JetspeedPrincipal> getPrincipals(String nameFilter)
+    {
+        return jpam.getPrincipals(nameFilter, principalType);
+    }
+
+    public void removePrincipal(String name) throws PrincipalNotFoundException, PrincipalNotRemovableException,
+                                            DependentPrincipalException
     {
-        this.jetspeedPrincipalAccessManager = pam;
+        JetspeedPrincipal principal = jpam.getPrincipal(name, principalType);
+        if (principal == null)
+            throw new PrincipalNotFoundException();
+        jpsm.removePrincipal(principal);
     }
 
     public List<JetspeedPrincipal> getAssociatedFrom(String principalName, String associationName)
     {
-        return jetspeedPrincipalAccessManager.getAssociatedFrom(principalName, getPrincipalType(),
associationName);
+        return jpam.getAssociatedFrom(principalName, principalType, associationName);
     }
 
     public List<String> getAssociatedNamesFrom(String principalName, String associationName)
     {
-        return jetspeedPrincipalAccessManager
-                                             .getAssociatedNamesFrom(principalName, getPrincipalType(),
associationName);
+        return jpam.getAssociatedNamesFrom(principalName, principalType, associationName);
     }
 
     public List<String> getAssociatedNamesTo(String principalName, String associationName)
     {
-        return jetspeedPrincipalAccessManager.getAssociatedNamesTo(principalName, getPrincipalType(),
associationName);
+        return jpam.getAssociatedNamesTo(principalName, principalType, associationName);
     }
 
     public List<JetspeedPrincipal> getAssociatedTo(String principalName, String associationName)
     {
-        return jetspeedPrincipalAccessManager.getAssociatedTo(principalName, getPrincipalType(),
associationName);
+        return jpam.getAssociatedTo(principalName, principalType, associationName);
     }
 
-    public JetspeedPrincipal getPrincipal(String name)
+    //
+    // JetspeedPrincipalManagerSPI interface implementation
+    //
+    public void addAssociationHandler(JetspeedPrincipalAssociationHandler jpah)
     {
-        return jetspeedPrincipalAccessManager.getPrincipal(name, getPrincipalType());
+        if (jpah.getAssociationType().getFromPrincipalType().getName().equals(principalType.getName())
||
+            jpah.getAssociationType().getToPrincipalType().getName().equals(principalType.getName()))
+        {
+            AssociationHandlerKey key = new AssociationHandlerKey(jpah);
+            if (assHandlers.containsKey(key))
+            {
+                throw new IllegalStateException("An AssociationHandler for " +
+                                                jpah.getAssociationType().getAssociationName()
+ " already defined");
+            }
+            assHandlers.put(key, jpah);
+        }
+        else
+        {
+            throw new IllegalArgumentException("AssociationHandler is not handling a " +
principalType.getName() +
+                                               " JetspeedPrincipal");
+        }
     }
 
-    public List<String> getPrincipalNames(String nameFilter)
+    //
+    // JetspeedPrincipalStorageManager interface implementation
+    //
+    public boolean isMapped()
     {
-        return jetspeedPrincipalAccessManager.getPrincipalNames(nameFilter, getPrincipalType());
+        return jpsm.isMapped();
     }
 
-    public List<JetspeedPrincipal> getPrincipals(String nameFilter)
+    public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference>
associations)
+                                                                                        
                         throws PrincipalAlreadyExistsException,
+                                                                                        
                         PrincipalAssociationRequiredException
     {
-        return jetspeedPrincipalAccessManager.getPrincipals(nameFilter, getPrincipalType());
+        validatePrincipal(principal);
+        jpsm.addPrincipal(principal, associations);
     }
 
-    public boolean principalExists(String name)
+    public void removePrincipal(JetspeedPrincipal principal) throws PrincipalNotFoundException,
+                                                            PrincipalNotRemovableException,
DependentPrincipalException
     {
-        return false;
+        validatePrincipal(principal);
+        jpsm.removePrincipal(principal);
     }
 
-    public void grantPermission(JetspeedPrincipal principal, JetspeedPermission permission)
+    public void updatePrincipal(JetspeedPrincipal principal) throws PrincipalUpdateException,
+                                                            PrincipalNotFoundException
     {
-        jetspeedPrincipalPermissionStorageManager.grantPermission(principal, permission);
+        validatePrincipal(principal);
+        jpsm.updatePrincipal(principal);
     }
 
-    public void revokeAll(JetspeedPrincipal principal)
+    //
+    // JetspeedPrincipalPermissionStorageManager interface implementation
+    //
+    public void grantPermission(JetspeedPrincipal principal, JetspeedPermission permission)
     {
-        jetspeedPrincipalPermissionStorageManager.revokeAll(principal);
+        validatePrincipal(principal);
+        jppsm.grantPermission(principal, permission);
     }
 
-    public void revokePermission(JetspeedPrincipal principal, JetspeedPermission permission)
+    public void revokeAll(JetspeedPrincipal principal)
     {
-        jetspeedPrincipalPermissionStorageManager.revokePermission(principal, permission);
+        jppsm.revokeAll(principal);
+        validatePrincipal(principal);
     }
 
-    public void removePrincipal(String name) throws PrincipalNotFoundException, PrincipalNotRemovableException,
-                                            DependentPrincipalException
+    public void revokePermission(JetspeedPrincipal principal, JetspeedPermission permission)
     {
-        JetspeedPrincipal principal = jetspeedPrincipalAccessManager.getPrincipal(name, getPrincipalType());
-        if (principal == null)
-            throw new PrincipalNotFoundException();
-        jetspeedPrincipalStorageManager.removePrincipal(principal);
+        validatePrincipal(principal);
+        jppsm.revokePermission(principal, permission);
     }
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationHandler.java?rev=692153&r1=692152&r2=692153&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationHandler.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalAssociationHandler.java
Thu Sep  4 09:47:26 2008
@@ -16,8 +16,6 @@
  */
 package org.apache.jetspeed.security;
 
-import org.apache.jetspeed.security.spi.JetspeedPrincipalAssociationStorageManager;
-
 /**
  * @version $Id$
  */
@@ -25,12 +23,6 @@
 {
     JetspeedPrincipalAssociationType getAssociationType();
 
-    void setManagerFrom(JetspeedPrincipalManager pm);
-
-    void setManagerTo(JetspeedPrincipalManager pm);
-
-    void setStorageManager(JetspeedPrincipalAssociationStorageManager sm);
-
     void add(JetspeedPrincipal from, JetspeedPrincipal to) throws PrincipalNotFoundException,
PrincipalAssociationNotAllowedException;
 
     void remove(JetspeedPrincipal from, JetspeedPrincipal to) throws PrincipalNotFoundException,
PrincipalAssociationRequiredException;

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java?rev=692153&r1=692152&r2=692153&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
Thu Sep  4 09:47:26 2008
@@ -18,7 +18,6 @@
 
 import java.util.List;
 
-import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalPermissionStorageManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager;
 
@@ -29,11 +28,7 @@
 {
     JetspeedPrincipalType getPrincipalType();
 
-    void setAccessManager(JetspeedPrincipalAccessManager pm);
-
-    void addAssociationHandler(JetspeedPrincipalAssociationHandler ah);
-
-    boolean principalExists(String name);
+     boolean principalExists(String name);
 
     JetspeedPrincipal getPrincipal(String name);
 

Added: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java?rev=692153&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
Thu Sep  4 09:47:26 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.jetspeed.security.spi;
+
+import org.apache.jetspeed.security.JetspeedPrincipalAssociationHandler;
+import org.apache.jetspeed.security.JetspeedPrincipalManager;
+
+/**
+ * @version $Id$
+ *
+ */
+public interface JetspeedPrincipalManagerSPI extends JetspeedPrincipalManager
+{
+    void addAssociationHandler(JetspeedPrincipalAssociationHandler ah);
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/JetspeedPrincipalManagerSPI.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
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