You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2013/12/03 17:17:16 UTC

svn commit: r1547457 - in /syncope/trunk/core/src: main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java main/java/org/apache/syncope/core/util/MappingUtil.java test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java

Author: fmartelli
Date: Tue Dec  3 16:17:16 2013
New Revision: 1547457

URL: http://svn.apache.org/r1547457
Log:
Merge from 1.1.X

Modified:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java?rev=1547457&r1=1547456&r2=1547457&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/PropagationManager.java Tue Dec  3 16:17:16 2013
@@ -144,7 +144,7 @@ public class PropagationManager {
         if (vAttrs != null && !vAttrs.isEmpty()) {
             userDataBinder.fillVirtual(user, vAttrs, AttributableUtil.getInstance(AttributableType.USER));
         }
-        return getCreateTaskIds(user, password, vAttrs,
+        return getCreateTaskIds(user, password,
                 wfResult.getResult().getValue(), wfResult.getPropByRes(), noPropResourceNames);
     }
 
@@ -182,12 +182,12 @@ public class PropagationManager {
         if (vAttrs != null && !vAttrs.isEmpty()) {
             roleDataBinder.fillVirtual(role, vAttrs, AttributableUtil.getInstance(AttributableType.ROLE));
         }
-        
-        return getCreateTaskIds(role, null, vAttrs, null, wfResult.getPropByRes(), noPropResourceNames);
+
+        return getCreateTaskIds(role, null, null, wfResult.getPropByRes(), noPropResourceNames);
     }
 
     protected List<PropagationTask> getCreateTaskIds(final AbstractAttributable attributable,
-            final String password, final Collection<AttributeTO> vAttrs, final Boolean enable,
+            final String password, final Boolean enable,
             final PropagationByResource propByRes, final Set<String> noPropResourceNames) {
 
         if (propByRes == null || propByRes.isEmpty()) {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java?rev=1547457&r1=1547456&r2=1547457&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java Tue Dec  3 16:17:16 2013
@@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUt
 import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.types.IntMappingType;
 import org.apache.syncope.common.types.AttributeSchemaType;
+import org.apache.syncope.core.connid.ConnObjectUtil;
 import org.apache.syncope.core.connid.PasswordGenerator;
 import org.apache.syncope.core.persistence.beans.AbstractAttr;
 import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
@@ -135,6 +136,9 @@ public final class MappingUtil {
 
         final List<AbstractAttributable> attributables = new ArrayList<AbstractAttributable>();
 
+        final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
+        final ConnObjectUtil connObjectUtil = context.getBean(ConnObjectUtil.class);
+
         switch (mapItem.getIntMappingType().getAttributableType()) {
             case USER:
                 if (subject instanceof SyncopeUser) {
@@ -144,7 +148,10 @@ public final class MappingUtil {
 
             case ROLE:
                 if (subject instanceof SyncopeUser) {
-                    attributables.addAll(((SyncopeUser) subject).getRoles());
+                    for (SyncopeRole role : ((SyncopeUser) subject).getRoles()) {
+                        connObjectUtil.retrieveVirAttrValues(role, AttributableUtil.getInstance(role));
+                        attributables.add(role);
+                    }
                 }
                 if (subject instanceof SyncopeRole) {
                     attributables.add(subject);
@@ -160,14 +167,14 @@ public final class MappingUtil {
             default:
         }
 
-        List<AbstractAttrValue> values = MappingUtil.getIntValues(resource, mapItem, attributables,
-                vAttrsToBeRemoved, vAttrsToBeUpdated);
+        List<AbstractAttrValue> values = getIntValues(
+                resource, mapItem, attributables, vAttrsToBeRemoved, vAttrsToBeUpdated);
 
         AbstractNormalSchema schema = null;
         boolean readOnlyVirSchema = false;
         AttributeSchemaType schemaType;
         final Map.Entry<String, Attribute> result;
-        final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
+
         switch (mapItem.getIntMappingType()) {
             case UserSchema:
             case RoleSchema:

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java?rev=1547457&r1=1547456&r2=1547457&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java Tue Dec  3 16:17:16 2013
@@ -25,9 +25,11 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.lang3.SerializationUtils;
+import java.util.Map;
 import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.StatusMod;
 import org.apache.syncope.common.mod.UserMod;
+import org.apache.syncope.common.services.ResourceService;
 import org.apache.syncope.common.to.AttributeTO;
 import org.apache.syncope.common.to.ConnInstanceTO;
 import org.apache.syncope.common.to.ConnObjectTO;
@@ -35,6 +37,7 @@ import org.apache.syncope.common.to.Mapp
 import org.apache.syncope.common.to.MappingTO;
 import org.apache.syncope.common.to.MembershipTO;
 import org.apache.syncope.common.to.ResourceTO;
+import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.to.UserTO;
 import org.apache.syncope.common.types.AttributableType;
 import org.apache.syncope.common.types.ConnConfProperty;
@@ -432,4 +435,98 @@ public class VirAttrTestITCase extends A
         //Finding no values because the virtual attribute is readonly 
         assertTrue(userTO.getVirAttrMap().get("virtualReadOnly").getValues().isEmpty());
     }
+
+    @Test
+    public void issueSYNCOPE453() {
+        final String resourceName = "issueSYNCOPE453-Res-" + getUUIDString();
+        final String roleName = "issueSYNCOPE453-Role-" + getUUIDString();
+
+        // -------------------------------------------
+        // Create a resource ad-hoc
+        // -------------------------------------------
+        final ResourceTO resourceTO = new ResourceTO();
+
+        resourceTO.setName(resourceName);
+        resourceTO.setConnectorId(107L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntAttrName("aLong");
+        item.setIntMappingType(IntMappingType.UserSchema);
+        item.setPurpose(MappingPurpose.PROPAGATION);
+        item.setAccountid(true);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("USERNAME");
+        item.setIntAttrName("username");
+        item.setIntMappingType(IntMappingType.Username);
+        item.setPurpose(MappingPurpose.PROPAGATION);
+        mapping.getItems().add(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("EMAIL");
+        item.setIntAttrName("rvirtualdata");
+        item.setIntMappingType(IntMappingType.RoleVirtualSchema);
+        item.setPurpose(MappingPurpose.PROPAGATION);
+        mapping.getItems().add(item);
+
+        resourceTO.setUmapping(mapping);
+        assertNotNull(getObject(
+                resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
+        // -------------------------------------------
+
+        // -------------------------------------------
+        // Create a role ad-hoc
+        // -------------------------------------------
+        RoleTO roleTO = new RoleTO();
+        roleTO.setName(roleName);
+        roleTO.setParent(8L);
+        roleTO.getRVirAttrTemplates().add("rvirtualdata");
+        roleTO.getVirAttrs().add(attributeTO("rvirtualdata", "ml@role.it"));
+        roleTO.getResources().add(RESOURCE_NAME_LDAP);
+        roleTO = createRole(roleTO);
+        assertEquals(1, roleTO.getVirAttrs().size());
+        assertEquals("ml@role.it", roleTO.getVirAttrs().get(0).getValues().get(0));
+        // -------------------------------------------
+
+        // -------------------------------------------
+        // Create new user
+        // -------------------------------------------
+        UserTO userTO = getUniqueSampleTO("syncope453@syncope.apache.org");
+        userTO.getAttrs().add(attributeTO("aLong", "123"));
+        userTO.getResources().clear();
+        userTO.getResources().add(resourceName);
+        userTO.getVirAttrs().clear();
+        userTO.getDerAttrs().clear();
+        userTO.getMemberships().clear();
+
+        final MembershipTO membership = new MembershipTO();
+        membership.setRoleId(roleTO.getId());
+        membership.getVirAttrs().add(attributeTO("mvirtualdata", "mvirtualvalue"));
+        userTO.getMemberships().add(membership);
+
+        userTO = createUser(userTO);
+        assertEquals(2, userTO.getPropagationStatusTOs().size());
+        assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());
+        assertTrue(userTO.getPropagationStatusTOs().get(1).getStatus().isSuccessful());
+
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+
+        final Map<String, Object> actuals = jdbcTemplate.queryForMap(
+                "SELECT id, surname, email FROM testsync WHERE id=?",
+                new Object[] {Integer.parseInt(userTO.getAttrMap().get("aLong").getValues().get(0))});
+
+        assertEquals(userTO.getAttrMap().get("aLong").getValues().get(0), actuals.get("id").toString());
+        assertEquals("ml@role.it", actuals.get("email"));
+        // -------------------------------------------
+
+        // -------------------------------------------
+        // Delete resource and role ad-hoc
+        // -------------------------------------------
+        resourceService.delete(resourceName);
+        roleService.delete(roleTO.getId());
+        // -------------------------------------------
+    }
 }