portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vku...@apache.org
Subject svn commit: r729307 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/ jetspeed-api/src/main/java/org/apache/jetspeed/security/ jetspeed-portal-resources/src/main/resources/assembly/
Date Wed, 24 Dec 2008 13:03:13 GMT
Author: vkumar
Date: Wed Dec 24 05:03:12 2008
New Revision: 729307

URL: http://svn.apache.org/viewvc?rev=729307&view=rev
Log:
Adding event listener implementation for Principal managers.
It delegate events to listeners on following events

    1) New principal
    2) Updating
    3) Removing principal
    4) Adding association
    5) Removing association
    
This will also full-fill requirements for Jira issue 443

Added:
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java
  (with props)
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java?rev=729307&r1=729306&r2=729307&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipalManager.java
Wed Dec 24 05:03:12 2008
@@ -20,6 +20,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -31,6 +32,7 @@
 import org.apache.jetspeed.security.JetspeedPrincipalManager;
 import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
 import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.PrincipalManagerEventListener;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
 import org.apache.jetspeed.security.spi.JetspeedPrincipalAssociationHandler;
@@ -88,6 +90,7 @@
     private JetspeedPrincipalStorageManager jpsm;
     //added for removing circular dependciese
     protected static JetspeedPrincipalManagerProvider jpmp;
+    private List<PrincipalManagerEventListener> listeners = new LinkedList();
     
     public BaseJetspeedPrincipalManager(JetspeedPrincipalType principalType, JetspeedPrincipalAccessManager
jpam,
                                         JetspeedPrincipalStorageManager jpsm)
@@ -307,6 +310,7 @@
                 }
             }
         }
+        notifyNewPrincipal(principal);
     }
 
     public void removePrincipal(JetspeedPrincipal principal) throws SecurityException
@@ -324,8 +328,9 @@
             }
         }
         jpsm.removePrincipal(principal);
-    }
-
+        notifyRemovedPrincipal(principal);
+    }     
+    
     public void updatePrincipal(JetspeedPrincipal principal) throws SecurityException
     {
         validatePrincipal(principal);
@@ -334,8 +339,37 @@
             throw new SecurityException(SecurityException.PRINCIPAL_IS_READ_ONLY.createScoped(principal.getType().getName(),
principal.getName()));
         }
         jpsm.updatePrincipal(principal);
+        notifyUpdatedPrincipal(principal);
+    }
+
+    /**
+     * addListener - add principal manager event listener
+     *
+     * @param listener principal manager event listener
+     */
+    public void setListener(PrincipalManagerEventListener listener)
+    {
+        // add listener to listeners list
+        synchronized (listeners)
+        {
+            listeners.add(listener);
+        }
     }
 
+    /**
+     * removeListener - remove principal manager event listener
+     *
+     * @param listener principal manager event listener
+     */
+    public void removeListener(PrincipalManagerEventListener listener)
+    {
+        // remove listener from listeners list
+        synchronized (listeners)
+        {  
+        	listeners.remove(listener);
+        }
+    }
+    
     //
     // JetspeedPrincipalAssociationHandler interface invocations
     //
@@ -367,6 +401,7 @@
             to = pto;
         }
         jpah.add(from, to);
+        notifyAddedAssociation(from,to, associationName);
     }
     
     public void transferAssociationFrom(JetspeedPrincipal from, JetspeedPrincipal to, JetspeedPrincipal
target,
@@ -416,11 +451,106 @@
                 to = pto;
             }
             jpah.remove(from, to);
+            notifyRemovedAssociation(from,to, associationName);
         }
     }
     
     protected boolean isSynchronizing(){
         return SynchronizationStateAccess.isSynchronizing();
     }
-
+    /**
+     * notifyNewPrincipal - notify principal manager event listeners of
+     *                 new principal event
+     *
+     * @param principal New principal
+     */
+    public void notifyNewPrincipal(JetspeedPrincipal principal) throws SecurityException
+    {
+        // copy listeners list to reduce synchronization deadlock
+        List<PrincipalManagerEventListener> listenersList = null;
+        synchronized (listeners)
+        {
+            listenersList = new ArrayList(listeners);
+        }
+        for(PrincipalManagerEventListener listener : listenersList)
+        {
+                listener.newPrincipal(principal);
+        }
+    }
+
+    /**
+     * notifyUpdatedPrincipal - notify page manager event listeners of
+     *                         updated node event
+     *
+     * @param node updated managed node if known
+     */
+    public void notifyUpdatedPrincipal(JetspeedPrincipal principal) throws SecurityException
+    {
+	   List<PrincipalManagerEventListener> listenersList = null;
+       synchronized (listeners)
+       {
+           listenersList = new ArrayList(listeners);
+       }
+       for(PrincipalManagerEventListener listener : listenersList)
+       {
+               listener.updatePrincipal(principal);
+       }
+    }
+
+    /**
+     * notifyRemovedPrincipal - notify principal manager event listeners of
+     *                          removed principal event
+     *
+     * @param principal removed managed principal if known
+     */
+    public void notifyRemovedPrincipal(JetspeedPrincipal principal)
+    {
+ 	   List<PrincipalManagerEventListener> listenersList = null;
+       synchronized (listeners)
+       {
+           listenersList = new ArrayList(listeners);
+       }
+       for(PrincipalManagerEventListener listener : listenersList)
+       {
+               listener.removePrincipal(principal);
+       }
+    }
+
+    /**
+     * notifyAddedAssociation - notify principal manager event listeners of
+     *                          addedd association event
+     *
+     * @param principal removed managed principal if known
+     */
+    public void notifyAddedAssociation(JetspeedPrincipal fromPrincipal,JetspeedPrincipal
toPrincipal, String associationName)
+    {
+ 	   List<PrincipalManagerEventListener> listenersList = null;
+       synchronized (listeners)
+       {
+           listenersList = new ArrayList(listeners);
+       }
+       for(PrincipalManagerEventListener listener : listenersList)
+       {
+               listener.associationAdded(fromPrincipal,toPrincipal, associationName);
+       }
+    }
+
+    /**
+     * notifyRemovedAssociation - notify principal manager event listeners of
+     *                          removed association event
+     *
+     * @param principal removed managed principal if known
+     */
+    public void notifyRemovedAssociation(JetspeedPrincipal fromPrincipal,JetspeedPrincipal
toPrincipal, String associationName)
+    {
+ 	   List<PrincipalManagerEventListener> listenersList = null;
+       synchronized (listeners)
+       {
+           listenersList = new ArrayList(listeners);
+       }
+       for(PrincipalManagerEventListener listener : listenersList)
+       {
+               listener.associationRemoved(fromPrincipal,toPrincipal, associationName);
+       }
+    }
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java?rev=729307&r1=729306&r2=729307&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
Wed Dec 24 05:03:12 2008
@@ -146,4 +146,8 @@
     
     void removeAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName)
         throws SecurityException;
+    
+    void setListener(PrincipalManagerEventListener listener);
+    
+    void removeListener(PrincipalManagerEventListener listener);
 }

Added: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java?rev=729307&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java
Wed Dec 24 05:03:12 2008
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:vkumar@apache.org">Vivek Kumar</a>
+ * @version $Id:
+ * 
+ * PrincipalManagerEventAdapter will allow to extends it self and over-ride desired methods
+ * to have custom operation on the events
+ */
+public class PrincipalManagerEventAdapter implements PrincipalManagerEventListener {
+
+	public void associationAdded(JetspeedPrincipal fromPrincipal,
+			JetspeedPrincipal toPrincipal, String associationName) {
+		//Do nothing
+	}
+
+	public void associationRemoved(JetspeedPrincipal fromPrincipal,
+			JetspeedPrincipal toPrincipal, String associationName) {
+		//Do nothing		
+	}
+
+	public void newPrincipal(JetspeedPrincipal principal) {
+		//Do nothing		
+	}
+
+	public void removePrincipal(JetspeedPrincipal principal) {
+		//Do nothing
+	}
+
+	public void updatePrincipal(JetspeedPrincipal principal) {
+		//Do nothing
+	}
+
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java?rev=729307&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java
Wed Dec 24 05:03:12 2008
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+
+/**
+ * @author <a href="mailto:vkumar@apache.org">Vivek Kumar</a>
+ * @version $Id:
+ */
+public interface PrincipalManagerEventListener {
+
+    /**
+     * newPrincipal  - invoked when new principal is
+     *                 created by the principal manager
+     *
+     * @param principal new managed JetspeedPrincipal 
+     */
+    void newPrincipal(JetspeedPrincipal principal);
+
+    /**
+     * updatePrincipal  - invoked when an principal is
+     *                    updated by the principal manager
+     *
+     * @param principal new managed JetspeedPrincipal 
+     */
+    void updatePrincipal(JetspeedPrincipal principal);
+    
+    /**
+     * removePrincipal - invoked when an principal is
+     *                   removed by the principal manager
+     *
+     * @param principal new managed JetspeedPrincipal 
+     */
+    void removePrincipal(JetspeedPrincipal principal);
+        
+    /**
+     * associationAdded - invoked when an association is added 
+     * 					  on principal                  
+     *
+     * @param principal new managed JetspeedPrincipal 
+     * @param associationName Name of association which is added to principal
+     */
+    void associationAdded(JetspeedPrincipal fromPrincipal,JetspeedPrincipal toPrincipal,String
associationName);
+    
+    /**
+     * associationRemoved - invoked when an association is added 
+     * 					  on principal                  
+     *
+     * @param principal new managed JetspeedPrincipal 
+     * @param associationName Name of association which is removed to principal
+     */
+    void associationRemoved(JetspeedPrincipal fromPrincipal,JetspeedPrincipal toPrincipal,String
associationName);
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/security/PrincipalManagerEventListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml?rev=729307&r1=729306&r2=729307&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
Wed Dec 24 05:03:12 2008
@@ -138,6 +138,9 @@
     <constructor-arg index="3" ref="org.apache.jetspeed.security.spi.JetspeedSecurityPersistenceManager"
/>
     <constructor-arg index="4" ref="org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager"
/>
     <constructor-arg index="5" ref="org.apache.jetspeed.security.spi.UserPasswordCredentialManager"
/>
+    <property name="listener">
+      <ref bean="org.apache.jetspeed.security.PrincipalManagerEventAdapter" />
+    </property>    
   </bean>
 
   <!-- Security: Group Manager -->
@@ -171,6 +174,9 @@
     <constructor-arg index="2" ref="org.apache.jetspeed.security.JetspeedPrincipalType.role"
/>
     <constructor-arg index="3" ref="org.apache.jetspeed.security.spi.JetspeedSecurityPersistenceManager"
/>
     <constructor-arg index="4" ref="org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager"
/>
+    <property name="listener">
+      <ref bean="org.apache.jetspeed.security.PrincipalManagerEventAdapter" />
+    </property>    
   </bean>
 
   <!-- Security: Role Manager -->
@@ -204,6 +210,9 @@
     <constructor-arg index="2" ref="org.apache.jetspeed.security.JetspeedPrincipalType.group"
/>
     <constructor-arg index="3" ref="org.apache.jetspeed.security.spi.JetspeedSecurityPersistenceManager"
/>
     <constructor-arg index="4" ref="org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager"
/>
+    <property name="listener">
+      <ref bean="org.apache.jetspeed.security.PrincipalManagerEventAdapter" />
+    </property>    
   </bean>
 
   <!-- Security: Permission Manager -->
@@ -392,4 +401,7 @@
       </list>
     </constructor-arg>
   </bean>
+  <bean id="org.apache.jetspeed.security.PrincipalManagerEventAdapter" class="org.apache.jetspeed.security.PrincipalManagerEventAdapter"
>
+    <meta key="j2:cat" value="default" />
+  </bean>  
 </beans>
\ No newline at end of file



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