You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by md...@apache.org on 2014/09/08 12:59:22 UTC

svn commit: r1623357 - in /syncope/branches/1_2_X: ./ core/src/main/java/org/apache/syncope/core/persistence/beans/role/ core/src/main/java/org/apache/syncope/core/rest/data/ core/src/test/java/org/apache/syncope/core/persistence/dao/ core/src/test/jav...

Author: mdisabatino
Date: Mon Sep  8 10:59:22 2014
New Revision: 1623357

URL: http://svn.apache.org/r1623357
Log:
[SYNCOPE-543] Merge from 1_1_X

Modified:
    syncope/branches/1_2_X/   (props changed)
    syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java
    syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
    syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java
    syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java

Propchange: syncope/branches/1_2_X/
------------------------------------------------------------------------------
  Merged /syncope/branches/1_1_X:r1623311-1623344

Modified: syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java?rev=1623357&r1=1623356&r2=1623357&view=diff
==============================================================================
--- syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java (original)
+++ syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java Mon Sep  8 10:59:22 2014
@@ -19,7 +19,6 @@
 package org.apache.syncope.core.persistence.beans.role;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -448,27 +447,23 @@ public class SyncopeRole extends Abstrac
      * @return a list of inherited and only inherited attributes.
      */
     @SuppressWarnings("unchecked")
-    public List<RAttr> findInheritedAttrs() {
+    public List<RAttr> findLastInheritedAncestorAttributes() {
         final Map<RSchema, RAttr> result = new HashMap<RSchema, RAttr>();
 
+        if (!isInheritAttrs()) {
+            return attrs;
+        }
         if (isInheritAttrs() && getParent() != null) {
             final Map<AbstractNormalSchema, AbstractAttr> attrMap = getAttrMap();
 
-            // Add attributes not specialized
-            for (RAttr attr : (Collection<RAttr>) getParent().getAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema())) {
-                    result.put((RSchema) attr.getSchema(), attr);
-                }
-            }
-
-            // Add attributes not specialized and not already added
-            for (RAttr attr : getParent().findInheritedAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema()) && !result.containsKey((RSchema) attr.getSchema())) {
-                    result.put((RSchema) attr.getSchema(), attr);
+            // Add inherit attributes
+            for (RAttr attr : getParent().findLastInheritedAncestorAttributes()) {
+                if (attrMap.containsKey(attr.getSchema())) {
+                    result.remove((RSchema) attr.getSchema());
                 }
+                result.put((RSchema) attr.getSchema(), attr);
             }
         }
-
         return new ArrayList<RAttr>(result.values());
     }
 
@@ -487,29 +482,23 @@ public class SyncopeRole extends Abstrac
      * @return a list of inherited and only inherited attributes.
      */
     @SuppressWarnings("unchecked")
-    public List<RDerAttr> findInheritedDerAttrs() {
+    public List<RDerAttr> findLastInheritedAncestorDerivedAttributes() {
         final Map<RDerSchema, RDerAttr> result = new HashMap<RDerSchema, RDerAttr>();
 
+        if (!isInheritDerAttrs()) {
+            return derAttrs;
+        }
         if (isInheritDerAttrs() && getParent() != null) {
-            final Map<AbstractDerSchema, AbstractDerAttr> attrMap = getDerAttrMap();
-
-            // Add attributes not specialized
-            for (RDerAttr attr : (Collection<RDerAttr>) getParent().getDerAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema())) {
-                    result.put((RDerSchema) attr.getSchema(), attr);
-                }
-            }
+            final Map<AbstractDerSchema, AbstractDerAttr> attrDerMap = getDerAttrMap();
 
-            // Add attributes not specialized and not already added
-            for (RDerAttr attr : getParent().findInheritedDerAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema())
-                        && !result.containsKey((RDerSchema) attr.getSchema())) {
-
-                    result.put((RDerSchema) attr.getSchema(), attr);
+            // Add inherit derived attributes
+            for (RDerAttr attr : getParent().findLastInheritedAncestorDerivedAttributes()) {
+                if (attrDerMap.containsKey(attr.getSchema())) {
+                    result.remove((RDerSchema) attr.getSchema());
                 }
+                result.put((RDerSchema) attr.getSchema(), attr);
             }
         }
-
         return new ArrayList<RDerAttr>(result.values());
     }
 
@@ -528,29 +517,24 @@ public class SyncopeRole extends Abstrac
      * @return a list of inherited and only inherited attributes.
      */
     @SuppressWarnings("unchecked")
-    public List<RVirAttr> findInheritedVirAttrs() {
+    public List<RVirAttr> findLastInheritedAncestorVirtualAttributes() {
         final Map<RVirSchema, RVirAttr> result = new HashMap<RVirSchema, RVirAttr>();
 
-        if (isInheritVirAttrs() && getParent() != null) {
-            final Map<AbstractVirSchema, AbstractVirAttr> attrMap = getVirAttrMap();
-
-            // Add attributes not specialized
-            for (RVirAttr attr : (Collection<RVirAttr>) getParent().getVirAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema())) {
-                    result.put((RVirSchema) attr.getSchema(), attr);
-                }
-            }
+        if (!isInheritVirAttrs()) {
+            return virAttrs;
+        }
 
-            // Add attributes not specialized and not already added
-            for (RVirAttr attr : getParent().findInheritedVirAttrs()) {
-                if (!attrMap.containsKey(attr.getSchema())
-                        && !result.containsKey((RVirSchema) attr.getSchema())) {
+        if (isInheritVirAttrs() && getParent() != null) {
+            final Map<AbstractVirSchema, AbstractVirAttr> attrVirMap = getVirAttrMap();
 
-                    result.put((RVirSchema) attr.getSchema(), attr);
+            // Add inherit virtual attributes
+            for (RVirAttr attr : getParent().findLastInheritedAncestorVirtualAttributes()) {
+                if (attrVirMap.containsKey(attr.getSchema())) {
+                    result.remove((RVirSchema) attr.getSchema());
                 }
+                result.put((RVirSchema) attr.getSchema(), attr);
             }
         }
-
         return new ArrayList<RVirAttr>(result.values());
     }
 

Modified: syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java?rev=1623357&r1=1623356&r2=1623357&view=diff
==============================================================================
--- syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java (original)
+++ syncope/branches/1_2_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java Mon Sep  8 10:59:22 2014
@@ -397,15 +397,12 @@ public class RoleDataBinder extends Abst
 
         // -------------------------
         // Retrieve all [derived/virtual] attributes (inherited and not)
-        // -------------------------
-        final List<RAttr> allAttributes = role.findInheritedAttrs();
-        allAttributes.addAll((List<RAttr>) role.getAttrs());
+        // -------------------------        
+        final List<RAttr> allAttributes = role.findLastInheritedAncestorAttributes();
 
-        final List<RDerAttr> allDerAttributes = role.findInheritedDerAttrs();
-        allDerAttributes.addAll((List<RDerAttr>) role.getDerAttrs());
+        final List<RDerAttr> allDerAttributes = role.findLastInheritedAncestorDerivedAttributes();
 
-        final List<RVirAttr> allVirAttributes = role.findInheritedVirAttrs();
-        allVirAttributes.addAll((List<RVirAttr>) role.getVirAttrs());
+        final List<RVirAttr> allVirAttributes = role.findLastInheritedAncestorVirtualAttributes();
         // -------------------------
 
         fillTO(roleTO, allAttributes, allDerAttributes, allVirAttributes, role.getResources());

Modified: syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java?rev=1623357&r1=1623356&r2=1623357&view=diff
==============================================================================
--- syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java (original)
+++ syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java Mon Sep  8 10:59:22 2014
@@ -63,21 +63,21 @@ public class RoleTest extends AbstractDA
     public void inheritedAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedAttrs().size());
+        assertEquals(1, director.findLastInheritedAncestorAttributes().size());
     }
 
     @Test
     public void inheritedDerivedAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedDerAttrs().size());
+        assertEquals(1, director.findLastInheritedAncestorDerivedAttributes().size());
     }
 
     @Test
     public void inheritedVirtualAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedVirAttrs().size());
+        assertEquals(1, director.findLastInheritedAncestorVirtualAttributes().size());
     }
 
     @Test

Modified: syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1623357&r1=1623356&r2=1623357&view=diff
==============================================================================
--- syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/branches/1_2_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Mon Sep  8 10:59:22 2014
@@ -28,29 +28,23 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.io.InputStream;
 import java.security.AccessControlException;
-import java.util.Collection;
 import java.util.List;
 import javax.ws.rs.core.Response;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.SyncopeClient;
 import org.apache.syncope.common.SyncopeClientException;
-import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.ReferenceMod;
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.reqres.BulkActionResult;
 import org.apache.syncope.common.reqres.PagedResult;
 import org.apache.syncope.common.services.RoleService;
 import org.apache.syncope.common.to.ConnObjectTO;
-import org.apache.syncope.common.to.MappingItemTO;
-import org.apache.syncope.common.to.MappingTO;
-import org.apache.syncope.common.to.ResourceTO;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.to.SchemaTO;
 import org.apache.syncope.common.to.UserTO;
 import org.apache.syncope.common.types.AttributableType;
 import org.apache.syncope.common.types.ClientExceptionType;
-import org.apache.syncope.common.types.MappingPurpose;
 import org.apache.syncope.common.types.Preference;
 import org.apache.syncope.common.types.RESTHeaders;
 import org.apache.syncope.common.types.ResourceAssociationActionType;
@@ -738,81 +732,66 @@ public class RoleTestITCase extends Abst
     }
 
     @Test
-    public void issueSYNCOPE493() {
-        // 1.  create role and check that title is propagated on resource with mapping for title set to BOTH
-        RoleTO roleTO = buildBasicRoleTO("issueSYNCOPE493-Role");
-        roleTO.getResources().add(RESOURCE_NAME_LDAP);
-        roleTO.getRAttrTemplates().add("title");
-        roleTO.getAttrs().add(attributeTO("title", "TITLE"));
-
-        roleTO = createRole(roleTO);
-        assertTrue(roleTO.getResources().contains(RESOURCE_NAME_LDAP));
-
-        ConnObjectTO actual = resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE,
-                roleTO.getId());
-        assertNotNull(actual);
-
-        // check if mapping attribute with purpose BOTH has really been propagated
-        assertNotNull(actual.getAttrMap().get("description"));
-        assertEquals("TITLE", actual.getAttrMap().get("description").getValues().get(0));
-
-        // 2.  update resource LDAP
-        ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
-        assertNotNull(ldap);
-
-        MappingTO ldapNewRMapping = ldap.getRmapping();
-        // change purpose from BOTH to NONE
-        for (MappingItemTO itemTO : ldapNewRMapping.getItems()) {
-            if ("title".equals(itemTO.getIntAttrName())) {
-                itemTO.setPurpose(MappingPurpose.NONE);
-            }
-        }
-
-        ldap.setRmapping(ldapNewRMapping);
-        ldap.setUmapping(ldap.getUmapping());
-
-        resourceService.update(RESOURCE_NAME_LDAP, ldap);
-        ResourceTO newLdap = resourceService.read(ldap.getName());
-        assertNotNull(newLdap);
+    public void issueSYNCOPE543() {
+        final String ancestorName = "issueSYNCOPE543-ARole";
+        final String parentName = "issueSYNCOPE543-PRole";
+        final String childName = "issueSYNCOPE543-CRole";
+
+        // 1. create ancestor role
+        RoleTO ancestor = buildBasicRoleTO(ancestorName);
+        ancestor.setParent(0L);
+        ancestor.getRAttrTemplates().add("icon");
+        ancestor.getAttrs().add(attributeTO("icon", "ancestorIcon"));
+        ancestor = createRole(ancestor);
+        assertEquals("ancestorIcon", ancestor.getAttrMap().get("icon").getValues().get(0));
 
-        // check for existence
-        Collection<MappingItemTO> mapItems = newLdap.getRmapping().getItems();
-        assertNotNull(mapItems);
-        assertEquals(4, mapItems.size());
-
-        // 3.  update role and check that title han not been propagated, external attribute description must not be present
-        // in role mapping
-        RoleMod roleMod = new RoleMod();
-        roleMod.setId(roleTO.getId());
-
-        AttributeMod attr = attributeMod("title", "TITLENEW");
-        attr.getValuesToBeRemoved().add("TITLE");
-        roleMod.getAttrsToUpdate().add(attr);
-        roleTO = updateRole(roleMod);
-        assertNotNull(roleTO);
-        assertEquals(1, roleTO.getPropagationStatusTOs().size());
-        assertTrue(roleTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());
-        // check update on Syncope
-        assertEquals("TITLENEW", roleTO.getAttrMap().get("title").getValues().get(0));
-
-        final ConnObjectTO newRole = resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE,
-                roleTO.getId());
-
-        // due to NONE mapping for attribute title external attribute description must not be present
-        assertNull(newRole.getAttrMap().get("description"));
-
-        // 4.  restore resource LDAP mapping
-        ldapNewRMapping = newLdap.getRmapping();
-        // restore purpose from NONE to BOTH
-        for (MappingItemTO itemTO : ldapNewRMapping.getItems()) {
-            if ("title".equals(itemTO.getIntAttrName())) {
-                itemTO.setPurpose(MappingPurpose.BOTH);
-            }
-        }
+        // 2. create parent role
+        RoleTO parent = buildBasicRoleTO(parentName);
+        parent.setParent(ancestor.getId());
+        parent.getRAttrTemplates().add("icon");
+        parent.getAttrs().add(attributeTO("icon", "parentIcon"));
+        parent = createRole(parent);
+        assertEquals("parentIcon", parent.getAttrMap().get("icon").getValues().get(0));
 
-        newLdap.setRmapping(ldapNewRMapping);
-        newLdap.setUmapping(newLdap.getUmapping());
+        // 3. create child role
+        RoleTO child = buildBasicRoleTO(childName);
+        child.setParent(parent.getId());
+        child.getRAttrTemplates().add("icon");
+        child.getAttrs().add(attributeTO("icon", "childIcon"));
+        child = createRole(child);
+        assertEquals("childIcon", child.getAttrMap().get("icon").getValues().get(0));
 
-        resourceService.update(RESOURCE_NAME_LDAP, newLdap);
+        final RoleMod roleChildMod = new RoleMod();
+        roleChildMod.setId(child.getId());
+        roleChildMod.setInheritAttributes(Boolean.TRUE);
+        updateRole(roleChildMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttrMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getAttrMap().get("icon").getValues().get(0));
+
+        final RoleMod roleParentMod = new RoleMod();
+        roleParentMod.setId(parent.getId());
+        roleParentMod.setInheritAttributes(Boolean.TRUE);
+        updateRole(roleParentMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttrMap().get("icon").getValues());
+        assertEquals("ancestorIcon", child.getAttrMap().get("icon").getValues().get(0));
+
+        parent = roleService.read(parent.getId());
+        assertNotNull(parent);
+        assertNotNull(parent.getAttrMap().get("icon").getValues());
+        assertEquals("ancestorIcon", parent.getAttrMap().get("icon").getValues().get(0));
+
+        roleParentMod.setInheritAttributes(Boolean.FALSE);
+        updateRole(roleParentMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttrMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getAttrMap().get("icon").getValues().get(0));
     }
 }