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 10:41:20 UTC

svn commit: r1623333 - in /syncope/branches/1_1_X/core/src: main/java/org/apache/syncope/core/persistence/beans/role/ main/java/org/apache/syncope/core/rest/data/ test/java/org/apache/syncope/core/persistence/dao/ test/java/org/apache/syncope/core/rest/

Author: mdisabatino
Date: Mon Sep  8 08:41:20 2014
New Revision: 1623333

URL: http://svn.apache.org/r1623333
Log:
[SYNCOPE-543]

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

Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java?rev=1623333&r1=1623332&r2=1623333&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java (original)
+++ syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/persistence/beans/role/SyncopeRole.java Mon Sep  8 08:41:20 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;
@@ -334,28 +333,24 @@ public class SyncopeRole extends Abstrac
      *
      * @return a list of inherited and only inherited attributes.
      */
-    @SuppressWarnings("unchecked")
-    public List<RAttr> findInheritedAttributes() {
+    @SuppressWarnings({ "unchecked" })
+    public List<RAttr> findLastInheritedAncestorAttributes() {
         final Map<RSchema, RAttr> result = new HashMap<RSchema, RAttr>();
 
+        if (!isInheritAttributes()) {
+            return attributes;
+        }
         if (isInheritAttributes() && getParent() != null) {
             final Map<AbstractSchema, AbstractAttr> attrMap = getAttrMap();
 
-            // Add attributes not specialized
-            for (RAttr attr : (Collection<RAttr>) getParent().getAttributes()) {
-                if (!attrMap.containsKey(attr.getSchema())) {
-                    result.put((RSchema) attr.getSchema(), attr);
-                }
-            }
-
-            // Add attributes not specialized and not already added
-            for (RAttr attr : getParent().findInheritedAttributes()) {
-                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());
     }
 
@@ -374,28 +369,23 @@ public class SyncopeRole extends Abstrac
      * @return a list of inherited and only inherited attributes.
      */
     @SuppressWarnings("unchecked")
-    public List<RDerAttr> findInheritedDerivedAttributes() {
+    public List<RDerAttr> findLastInheritedAncestorDerivedAttributes() {
         final Map<RDerSchema, RDerAttr> result = new HashMap<RDerSchema, RDerAttr>();
 
+        if (!isInheritDerivedAttributes()) {
+            return derivedAttributes;
+        }
         if (isInheritDerivedAttributes() && getParent() != null) {
             final Map<AbstractDerSchema, AbstractDerAttr> attrMap = getDerAttrMap();
 
-            // Add attributes not specialized
-            for (RDerAttr attr : (Collection<RDerAttr>) getParent().getDerivedAttributes()) {
-                if (!attrMap.containsKey(attr.getDerivedSchema())) {
-                    result.put((RDerSchema) attr.getDerivedSchema(), attr);
-                }
-            }
-
-            // Add attributes not specialized and not already added
-            for (RDerAttr attr : getParent().findInheritedDerivedAttributes()) {
-                if (!attrMap.containsKey(attr.getDerivedSchema())
-                        && !result.containsKey((RDerSchema) attr.getDerivedSchema())) {
-                    result.put((RDerSchema) attr.getDerivedSchema(), attr);
+            // Add inherit derived attributes
+            for (RDerAttr attr : getParent().findLastInheritedAncestorDerivedAttributes()) {
+                if (attrMap.containsKey(attr.getDerivedSchema())) {
+                    result.remove((RDerSchema) attr.getDerivedSchema());
                 }
+                result.put((RDerSchema) attr.getDerivedSchema(), attr);
             }
         }
-
         return new ArrayList<RDerAttr>(result.values());
     }
 
@@ -414,28 +404,24 @@ public class SyncopeRole extends Abstrac
      * @return a list of inherited and only inherited attributes.
      */
     @SuppressWarnings("unchecked")
-    public List<RVirAttr> findInheritedVirtualAttributes() {
+    public List<RVirAttr> findLastInheritedAncestorVirtualAttributes() {
         final Map<RVirSchema, RVirAttr> result = new HashMap<RVirSchema, RVirAttr>();
 
+        if (!isInheritVirtualAttributes()) {
+            return virtualAttributes;
+        }
+
         if (isInheritVirtualAttributes() && getParent() != null) {
             final Map<AbstractVirSchema, AbstractVirAttr> attrMap = getVirAttrMap();
 
-            // Add attributes not specialized
-            for (RVirAttr attr : (Collection<RVirAttr>) getParent().getVirtualAttributes()) {
-                if (!attrMap.containsKey(attr.getVirtualSchema())) {
-                    result.put((RVirSchema) attr.getVirtualSchema(), attr);
-                }
-            }
-
-            // Add attributes not specialized and not already added
-            for (RVirAttr attr : getParent().findInheritedVirtualAttributes()) {
-                if (!attrMap.containsKey(attr.getVirtualSchema())
-                        && !result.containsKey((RVirSchema) attr.getVirtualSchema())) {
-                    result.put((RVirSchema) attr.getVirtualSchema(), attr);
+            // Add inherit virtual attributes
+            for (RVirAttr attr : getParent().findLastInheritedAncestorVirtualAttributes()) {
+                if (attrMap.containsKey(attr.getVirtualSchema())) {
+                    result.remove((RVirSchema) attr.getVirtualSchema());
                 }
+                result.put((RVirSchema) attr.getVirtualSchema(), attr);
             }
         }
-
         return new ArrayList<RVirAttr>(result.values());
     }
 

Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java?rev=1623333&r1=1623332&r2=1623333&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java (original)
+++ syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java Mon Sep  8 08:41:20 2014
@@ -313,15 +313,15 @@ public class RoleDataBinder extends Abst
 
         // -------------------------
         // Retrieve all [derived/virtual] attributes (inherited and not)
-        // -------------------------
-        final List<RAttr> allAttributes = role.findInheritedAttributes();
-        allAttributes.addAll((List<RAttr>) role.getAttributes());
+        // -------------------------        
+        final List<RAttr> allAttributes = role.findLastInheritedAncestorAttributes();
+        //allAttributes.addAll((List<RAttr>) role.getAttributes());
 
-        final List<RDerAttr> allDerAttributes = role.findInheritedDerivedAttributes();
-        allDerAttributes.addAll((List<RDerAttr>) role.getDerivedAttributes());
+        final List<RDerAttr> allDerAttributes = role.findLastInheritedAncestorDerivedAttributes();
+        //allDerAttributes.addAll((List<RDerAttr>) role.getDerivedAttributes());
 
-        final List<RVirAttr> allVirAttributes = role.findInheritedVirtualAttributes();
-        allVirAttributes.addAll((List<RVirAttr>) role.getVirtualAttributes());
+        final List<RVirAttr> allVirAttributes = role.findLastInheritedAncestorVirtualAttributes();
+        //allVirAttributes.addAll((List<RVirAttr>) role.getVirtualAttributes());
         // -------------------------
 
         fillTO(roleTO, allAttributes, allDerAttributes, allVirAttributes, role.getResources());

Modified: syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java?rev=1623333&r1=1623332&r2=1623333&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java (original)
+++ syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/persistence/dao/RoleTest.java Mon Sep  8 08:41:20 2014
@@ -63,21 +63,21 @@ public class RoleTest extends AbstractDA
     public void inheritedAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedAttributes().size());
+        assertEquals(1, director.findLastInheritedAncestorAttributes().size());
     }
 
     @Test
     public void inheritedDerivedAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedDerivedAttributes().size());
+        assertEquals(1, director.findLastInheritedAncestorDerivedAttributes().size());
     }
 
     @Test
     public void inheritedVirtualAttributes() {
         SyncopeRole director = roleDAO.find(7L);
 
-        assertEquals(1, director.findInheritedVirtualAttributes().size());
+        assertEquals(1, director.findLastInheritedAncestorVirtualAttributes().size());
     }
 
     @Test

Modified: syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1623333&r1=1623332&r2=1623333&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Mon Sep  8 08:41:20 2014
@@ -432,4 +432,65 @@ public class RoleTestITCase extends Abst
         assertNull(getLdapRemoteObject(parentRemoteObject.getAttributeMap().get(Name.NAME).getValues().get(0)));
         assertNull(getLdapRemoteObject(childRemoteObject.getAttributeMap().get(Name.NAME).getValues().get(0)));
     }
+
+    @Test
+    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.addAttribute(attributeTO("icon", "ancestorIcon"));
+        ancestor = createRole(roleService, ancestor);
+        assertEquals("ancestorIcon", ancestor.getAttributeMap().get("icon").getValues().get(0));
+
+        // 2. create parent role
+        RoleTO parent = buildBasicRoleTO(parentName);
+        parent.setParent(ancestor.getId());
+        parent.addAttribute(attributeTO("icon", "parentIcon"));
+        parent = createRole(roleService, parent);
+        assertEquals("parentIcon", parent.getAttributeMap().get("icon").getValues().get(0));
+
+        // 3. create child role
+        RoleTO child = buildBasicRoleTO(childName);
+        child.setParent(parent.getId());
+        child.addAttribute(attributeTO("icon", "childIcon"));
+        child = createRole(roleService, child);
+        assertEquals("childIcon", child.getAttributeMap().get("icon").getValues().get(0));
+
+        final RoleMod roleChildMod = new RoleMod();
+        roleChildMod.setId(child.getId());
+        roleChildMod.setInheritAttributes(Boolean.TRUE);
+        roleService.update(roleChildMod.getId(), roleChildMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttributeMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getAttributeMap().get("icon").getValues().get(0));
+
+        final RoleMod roleParentMod = new RoleMod();
+        roleParentMod.setId(parent.getId());
+        roleParentMod.setInheritAttributes(Boolean.TRUE);
+        roleService.update(roleParentMod.getId(), roleParentMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttributeMap().get("icon").getValues());
+        assertEquals("ancestorIcon", child.getAttributeMap().get("icon").getValues().get(0));
+
+        parent = roleService.read(parent.getId());
+        assertNotNull(parent);
+        assertNotNull(parent.getAttributeMap().get("icon").getValues());
+        assertEquals("ancestorIcon", parent.getAttributeMap().get("icon").getValues().get(0));
+
+        roleParentMod.setInheritAttributes(Boolean.FALSE);
+        roleService.update(roleParentMod.getId(), roleParentMod);
+
+        child = roleService.read(child.getId());
+        assertNotNull(child);
+        assertNotNull(child.getAttributeMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getAttributeMap().get("icon").getValues().get(0));
+    }
 }