You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by vk...@apache.org on 2008/10/07 13:47:00 UTC

svn commit: r702440 - in /portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security: mapping/ldap/dao/ mapping/ldap/dao/impl/ spi/impl/

Author: vkumar
Date: Tue Oct  7 04:46:59 2008
New Revision: 702440

URL: http://svn.apache.org/viewvc?rev=702440&view=rev
Log:
Checking final code for ldap replication

Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapStorageManager.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java?rev=702440&r1=702439&r2=702440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/DefaultLDAPEntityManager.java Tue Oct  7 04:46:59 2008
@@ -96,9 +96,28 @@
         }
     }
 
-    public void removeRelation(Entity entity, Entity relatedEntity, SecurityEntityRelationType relationType)
+    public void removeRelation(Entity entity, Entity relatedEntity, SecurityEntityRelationType relationType) throws SecurityException
     {
-        // TODO Auto-generated method stub
+        EntityRelationDAO relationDAO = entityRelationDAOs.get(relationType);
+        if (relationDAO != null)
+        {
+            EntityDAO sourceDAO;
+            EntityDAO targetDAO;
+            if (relationType.getFromEntityType().equals(entity.getType()))
+            {
+                sourceDAO = entityDAOs.get(entity.getType());
+                targetDAO = entityDAOs.get(relationType.getToEntityType());
+            }
+            else
+            {
+                targetDAO = entityDAOs.get(entity.getType());
+                sourceDAO = entityDAOs.get(relationType.getToEntityType());
+            }
+            if (relationDAO != null)
+            {
+                relationDAO.removeRelation(sourceDAO, targetDAO, entity, relatedEntity);
+            }
+        }
     }
 
     public Collection<Entity> getAllEntities(String entityType)

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java?rev=702440&r1=702439&r2=702440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/mapping/ldap/dao/impl/AttributeBasedRelationDAO.java Tue Oct  7 04:46:59 2008
@@ -17,12 +17,14 @@
 package org.apache.jetspeed.security.mapping.ldap.dao.impl;
 
 import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.mapping.ldap.dao.EntityDAO;
 import org.apache.jetspeed.security.mapping.model.Attribute;
 import org.apache.jetspeed.security.mapping.model.Entity;
+import org.springframework.ldap.core.DistinguishedName;
 import org.springframework.ldap.filter.EqualsFilter;
 import org.springframework.ldap.filter.Filter;
 
@@ -121,8 +123,8 @@
 
     private void internalAddRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity) throws SecurityException
     {
-        fromEntity =  fromEntityDAO.getEntity(fromEntity.getId());
-        toEntity =  toEntityDAO.getEntity(toEntity.getId());
+        fromEntity = fromEntityDAO.getEntity(fromEntity.getId());
+        toEntity = toEntityDAO.getEntity(toEntity.getId());
         String attrValue = null;
         if (attributeContainsInternalId)
         {
@@ -151,6 +153,8 @@
 
     private void internalRemoveRelation(EntityDAO fromEntityDAO, EntityDAO toEntityDAO, Entity fromEntity, Entity toEntity) throws SecurityException
     {
+        fromEntity = fromEntityDAO.getEntity(fromEntity.getId());
+        toEntity = toEntityDAO.getEntity(toEntity.getId());
         String attrValue = null;
         if (attributeContainsInternalId)
         {
@@ -168,7 +172,27 @@
         Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute);
         if (relationAttribute.getDefinition().isMultiValue())
         {
-            relationAttribute.getValues().remove(attrValue);
+            DistinguishedName attrib = new DistinguishedName(attrValue);
+            if (attributeContainsInternalId)
+            {
+                boolean found = false;
+                String attribValue = null;
+                Iterator<String> iterator = relationAttribute.getValues().iterator();
+                while(iterator.hasNext() && !found)
+                {
+                    attribValue = iterator.next();
+                    DistinguishedName ldapAttr = new DistinguishedName(attribValue);
+                    if (ldapAttr.equals(attrib))
+                    {
+                        relationAttribute.getValues().remove(attribValue);
+                        found = true; 
+                    }
+                }
+            }
+            else
+            {
+                relationAttribute.getValues().remove(attrValue);
+            }
         }
         else
         {
@@ -176,6 +200,7 @@
         }
         fromEntityDAO.updateInternalAttributes(fromEntity);
     }
+
     public void addRelation(EntityDAO sourceDao, EntityDAO targetDao, Entity sourceEntity, Entity targetEntity) throws SecurityException
     {
         if (useFromEntityAttribute)
@@ -192,11 +217,11 @@
     {
         if (useFromEntityAttribute)
         {
-            internalRemoveRelation(targetDao, sourceDao, targetEntity, sourceEntity);
+            internalRemoveRelation(sourceDao, targetDao, sourceEntity, targetEntity);
         }
         else
         {
-            internalRemoveRelation(sourceDao, targetDao, sourceEntity, targetEntity);
+            internalRemoveRelation(targetDao, sourceDao, targetEntity, sourceEntity);
         }
     }
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java?rev=702440&r1=702439&r2=702440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapAssociationStorageManager.java Tue Oct  7 04:46:59 2008
@@ -37,7 +37,8 @@
     /**
      * @param ldapEntityManager
      */
-    public JetspeedPrincipalLdapAssociationStorageManager(JetspeedPrincipalAssociationStorageManager databaseStorageMngr,SecurityEntityManager ldapEntityManager)
+    public JetspeedPrincipalLdapAssociationStorageManager(JetspeedPrincipalAssociationStorageManager databaseStorageMngr,
+                                                          SecurityEntityManager ldapEntityManager)
     {
         this.ldapEntityManager = ldapEntityManager;
         this.databaseStorageManager = databaseStorageMngr;
@@ -45,23 +46,29 @@
 
     public void addAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName) throws SecurityException
     {
-        EntityFactory entityFactory = ldapEntityManager.getEntityFactory(from.getType().getName());
-        EntityFactory relatedFactory = ldapEntityManager.getEntityFactory(to.getType().getName());
-        Entity fromEntity = entityFactory.createEntity(from);
-        Entity toEntity = relatedFactory.createEntity(to);
-        SecurityEntityRelationType relationType = new SecurityEntityRelationTypeImpl(associationName, fromEntity.getType(), toEntity.getType());
-        ldapEntityManager.addRelation(fromEntity, toEntity, relationType);
+        if (!SynchronizationStateAccess.isSynchronizing())
+        {
+            EntityFactory entityFactory = ldapEntityManager.getEntityFactory(from.getType().getName());
+            EntityFactory relatedFactory = ldapEntityManager.getEntityFactory(to.getType().getName());
+            Entity fromEntity = entityFactory.createEntity(from);
+            Entity toEntity = relatedFactory.createEntity(to);
+            SecurityEntityRelationType relationType = new SecurityEntityRelationTypeImpl(associationName, fromEntity.getType(), toEntity.getType());
+            ldapEntityManager.addRelation(fromEntity, toEntity, relationType);
+        }
         databaseStorageManager.addAssociation(from, to, associationName);
     }
 
     public void removeAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName) throws SecurityException
     {
-        EntityFactory entityFactory = ldapEntityManager.getEntityFactory(from.getType().getName());
-        EntityFactory relatedFactory = ldapEntityManager.getEntityFactory(to.getType().getName());
-        Entity fromEntity = entityFactory.createEntity(from);
-        Entity toEntity = relatedFactory.createEntity(to);
-        SecurityEntityRelationType relationType = new SecurityEntityRelationTypeImpl(associationName, fromEntity.getType(), toEntity.getType());
-        ldapEntityManager.removeRelation(fromEntity, toEntity, relationType);
-        databaseStorageManager.removeAssociation(from, to, associationName);
+        if (!SynchronizationStateAccess.isSynchronizing())
+        {
+            EntityFactory entityFactory = ldapEntityManager.getEntityFactory(from.getType().getName());
+            EntityFactory relatedFactory = ldapEntityManager.getEntityFactory(to.getType().getName());
+            Entity fromEntity = entityFactory.createEntity(from);
+            Entity toEntity = relatedFactory.createEntity(to);
+            SecurityEntityRelationType relationType = new SecurityEntityRelationTypeImpl(associationName, fromEntity.getType(), toEntity.getType());
+            ldapEntityManager.removeRelation(fromEntity, toEntity, relationType);
+            databaseStorageManager.removeAssociation(from, to, associationName);
+        }
     }
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapStorageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapStorageManager.java?rev=702440&r1=702439&r2=702440&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapStorageManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedPrincipalLdapStorageManager.java Tue Oct  7 04:46:59 2008
@@ -33,17 +33,20 @@
 {
     private SecurityEntityManager ldapEntityManager;
     private JetspeedPrincipalStorageManager delegateJpsm;
-        
-    public JetspeedPrincipalLdapStorageManager(JetspeedPrincipalStorageManager databaseStorage,SecurityEntityManager ldapEntityManager)
+
+    public JetspeedPrincipalLdapStorageManager(JetspeedPrincipalStorageManager databaseStorage, SecurityEntityManager ldapEntityManager)
     {
         this.delegateJpsm = databaseStorage;
         this.ldapEntityManager = ldapEntityManager;
     }
 
     public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference> associations) throws SecurityException
-    {        
+    {
         EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName());
-        ldapEntityManager.addEntity(entityFactory.createEntity(principal));
+        if (!SynchronizationStateAccess.isSynchronizing())
+        {
+            ldapEntityManager.addEntity(entityFactory.createEntity(principal));
+        }
         delegateJpsm.addPrincipal(principal, associations);
     }
 
@@ -55,14 +58,20 @@
     public void removePrincipal(JetspeedPrincipal principal) throws SecurityException
     {
         EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName());
-        ldapEntityManager.removeEntity(entityFactory.createEntity(principal));
+        if (!SynchronizationStateAccess.isSynchronizing())
+        {
+            ldapEntityManager.removeEntity(entityFactory.createEntity(principal));
+        }
         delegateJpsm.removePrincipal(principal);
     }
 
     public void updatePrincipal(JetspeedPrincipal principal) throws SecurityException
     {
         EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName());
-        ldapEntityManager.updateEntity(entityFactory.createEntity(principal));
+        if (!SynchronizationStateAccess.isSynchronizing())
+        {
+            ldapEntityManager.updateEntity(entityFactory.createEntity(principal));
+        }
         delegateJpsm.updatePrincipal(principal);
     }
 }



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