Author: andreapatricelli
Date: Mon Jun 16 09:38:40 2014
New Revision: 1602829

URL: http://svn.apache.org/r1602829
Log:
[SYNCOPE-501] merge from branch 1_1_X

Modified:
    syncope/trunk/   (props changed)
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirAttrTestITCase.java

Propchange: syncope/trunk/
------------------------------------------------------------------------------
  Merged /syncope/branches/1_1_X:r1600938-1602077

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java?rev=1602829&r1=1602828&r2=1602829&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
 Mon Jun 16 09:38:40 2014
@@ -22,6 +22,7 @@ import java.lang.reflect.Method;
 import java.security.AccessControlException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +47,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.dao.RoleDAO;
 import org.apache.syncope.core.persistence.dao.UserDAO;
 import org.apache.syncope.core.persistence.dao.search.OrderByClause;
+import org.apache.syncope.core.propagation.PropagationByResource;
 import org.apache.syncope.core.propagation.PropagationException;
 import org.apache.syncope.core.propagation.PropagationReporter;
 import org.apache.syncope.core.propagation.PropagationTaskExecutor;
@@ -257,11 +259,18 @@ public class UserController extends Abst
         List<PropagationTask> tasks = 
propagationManager.getUserUpdateTaskIds(updated);
         if (tasks.isEmpty()) {
             // SYNCOPE-459: take care of user virtual attributes ...
-            binder.forceVirtualAttributes(
+            final PropagationByResource propByResVirAttr = 
binder.forceVirtualAttributes(
                     updated.getResult().getKey().getId(),
                     actual.getVirAttrsToRemove(),
                     actual.getVirAttrsToUpdate());
-        } else {
+            // SYNCOPE-501: update only virtual attributes (if any of them 
changed), password propagation is 
+            // not required
+            tasks.addAll(propByResVirAttr.isEmpty() ? 
Collections.<PropagationTask>emptyList()
+                    : propagationManager.
+                    getUserUpdateTaskIds(updated, false, null));
+        }
+
+        if (!tasks.isEmpty()) {
             try {
                 taskExecutor.execute(tasks, propagationReporter);
             } catch (PropagationException e) {

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java?rev=1602829&r1=1602828&r2=1602829&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java
 Mon Jun 16 09:38:40 2014
@@ -106,7 +106,7 @@ public class UserDataBinder extends Abst
 
         return user;
     }
-    
+
     @Transactional(readOnly = true)
     public Set<String> getResourceNamesForUserId(final Long userId) {
         return getUserFromId(userId).getResourceNames();
@@ -416,7 +416,7 @@ public class UserDataBinder extends Abst
 
             // SYNCOPE-458 retrieve also membership virtual attributes
             connObjectUtil.retrieveVirAttrValues(membership, 
AttributableUtil.getInstance(AttributableType.MEMBERSHIP));
-            
+
             fillTO(membershipTO,
                     membership.getAttrs(), membership.getDerAttrs(), 
membership.getVirAttrs(),
                     membership.getResources());
@@ -443,14 +443,14 @@ public class UserDataBinder extends Abst
      * To be used in case of no propagation task defined.
      *
      * @param id attributable id
-     * @param vAttrsToBeRemoved virtual attribute to be removed.
-     * @param vAttrsToBeUpdated virtyal attribute to be updated.
+     * @param vAttrsToBeRemoved virtual attributes to be removed.
+     * @param vAttrsToBeUpdated virtual attributes to be updated.
      */
-    public void forceVirtualAttributes(
+    public PropagationByResource forceVirtualAttributes(
             final Long id, final Set<String> vAttrsToBeRemoved, final 
Set<AttributeMod> vAttrsToBeUpdated) {
         final SyncopeUser syncopeUser = getUserFromId(id);
 
-        fillVirtual(
+        return fillVirtual(
                 syncopeUser,
                 vAttrsToBeRemoved,
                 vAttrsToBeUpdated,

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=1602829&r1=1602828&r2=1602829&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
 Mon Jun 16 09:38:40 2014
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Collections;
 import org.apache.commons.lang3.SerializationUtils;
 import java.util.Map;
 import org.apache.syncope.common.mod.AttributeMod;
@@ -721,4 +722,51 @@ public class VirAttrTestITCase extends A
         resourceService.update(RESOURCE_NAME_DBVIRATTR, resourceDBVirAttr);
         // -------------------------------------------
     }
+
+    @Test
+    public void issueSYNCOPE501() {
+        // PHASE 1: update only user virtual attributes
+
+        // 1. create user and propagate him on resource-db-virattr
+        UserTO userTO = getUniqueSampleTO("[email protected]");
+        userTO.getResources().clear();
+        userTO.getMemberships().clear();
+        userTO.getVirAttrs().clear();
+
+        userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
+
+        // virtualdata is mapped with username
+        final AttributeTO virtualData = attributeTO("virtualdata", 
"[email protected]");
+        userTO.getVirAttrs().add(virtualData);
+
+        userTO = createUser(userTO);
+
+        assertNotNull(userTO.getVirAttrMap().get("virtualdata"));
+        assertEquals("[email protected]", 
userTO.getVirAttrMap().get("virtualdata").getValues().get(0));
+
+        // 2. update virtual attribute
+        UserMod userMod = new UserMod();
+        userMod.setId(userTO.getId());
+
+        final StatusMod statusMod = new StatusMod();
+        statusMod.getResourceNames().addAll(Collections.<String>emptySet());
+        statusMod.setOnSyncope(Boolean.FALSE);
+
+        userMod.setPwdPropRequest(statusMod);
+        // change virtual attribute value
+        final AttributeMod virtualDataMod = new AttributeMod();
+        virtualDataMod.setSchema("virtualdata");
+        
virtualDataMod.getValuesToBeAdded().add("[email protected]");
+        virtualDataMod.getValuesToBeRemoved().add("[email protected]");
+        userMod.getVirAttrsToUpdate().add(virtualDataMod);
+        userMod.getVirAttrsToRemove().add("virtualdata");
+
+        userTO = updateUser(userMod);
+        assertNotNull(userTO);
+
+        // 3. check that user virtual attribute has really been updated 
+        
assertFalse(userTO.getVirAttrMap().get("virtualdata").getValues().isEmpty());
+        assertEquals("[email protected]", 
userTO.getVirAttrMap().get("virtualdata").getValues().
+                get(0));
+    }
 }


Reply via email to