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/14 10:38:34 UTC

svn commit: r1550915 - in /syncope/trunk: ./ common/src/main/java/org/apache/syncope/common/util/ core/src/main/java/org/apache/syncope/core/rest/controller/ core/src/main/java/org/apache/syncope/core/rest/data/ core/src/test/java/org/apache/syncope/co...

Author: fmartelli
Date: Sat Dec 14 09:38:34 2013
New Revision: 1550915

URL: http://svn.apache.org/r1550915
Log:
SYNCOPE-459 merged from the branch 1.1.X

Modified:
    syncope/trunk/   (props changed)
    syncope/trunk/common/src/main/java/org/apache/syncope/common/util/AttributableOperations.java
    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/AbstractAttributableDataBinder.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.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:r1550729-1550905

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/util/AttributableOperations.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/util/AttributableOperations.java?rev=1550915&r1=1550914&r2=1550915&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/util/AttributableOperations.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/util/AttributableOperations.java Sat Dec 14 09:38:34 2013
@@ -74,7 +74,18 @@ public final class AttributableOperation
                     ? new HashSet<String>(originalAttrs.get(entry.getKey()).getValues())
                     : Collections.<String>emptySet();
 
-            if (!updatedValues.equals(originalValues)) {
+            if (!originalAttrs.containsKey(entry.getKey())) {
+                // SYNCOPE-459: take care of user virtual attributes without any value
+                updatedValues.remove("");
+                mod.getValuesToBeAdded().addAll(new ArrayList<String>(updatedValues));
+
+                if (virtuals) {
+                    result.getVirAttrsToUpdate().add(mod);
+                } else {
+                    result.getAttrsToUpdate().add(mod);
+                }
+
+            } else if (!updatedValues.equals(originalValues)) {
                 // avoid unwanted inputs
                 updatedValues.remove("");
                 if (!entry.getValue().isReadonly()) {

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=1550915&r1=1550914&r2=1550915&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 Sat Dec 14 09:38:34 2013
@@ -256,11 +256,21 @@ public class UserController extends Abst
 
         PropagationReporter propagationReporter = ApplicationContextProvider.getApplicationContext().
                 getBean(PropagationReporter.class);
-        try {
-            taskExecutor.execute(tasks, propagationReporter);
-        } catch (PropagationException e) {
-            LOG.error("Error propagation primary resource", e);
-            propagationReporter.onPrimaryResourceFailure(tasks);
+
+        if (tasks.isEmpty()) {
+            // SYNCOPE-459: take care of user virtual attributes ...
+            binder.forceVirtualAttributes(
+                    updated.getResult().getKey().getId(),
+                    actual.getVirAttrsToRemove(),
+                    actual.getVirAttrsToUpdate());
+
+        } else {
+            try {
+                taskExecutor.execute(tasks, propagationReporter);
+            } catch (PropagationException e) {
+                LOG.error("Error propagation primary resource", e);
+                propagationReporter.onPrimaryResourceFailure(tasks);
+            }
         }
 
         final UserTO updatedTO = binder.getUserTO(updated.getResult().getKey().getId());

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java?rev=1550915&r1=1550914&r2=1550915&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/AbstractAttributableDataBinder.java Sat Dec 14 09:38:34 2013
@@ -191,7 +191,7 @@ public abstract class AbstractAttributab
                 LOG.debug("Ignoring invalid virtual schema {}", virSchemaName);
             }
         }
-        
+
         return virtualSchema;
     }
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java?rev=1550915&r1=1550914&r2=1550915&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java Sat Dec 14 09:38:34 2013
@@ -66,7 +66,7 @@ import org.springframework.stereotype.Co
 import org.springframework.transaction.annotation.Transactional;
 
 @Component
-@Transactional(rollbackFor = {Throwable.class})
+@Transactional(rollbackFor = { Throwable.class })
 public class RoleDataBinder extends AbstractAttributableDataBinder {
 
     @Autowired

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=1550915&r1=1550914&r2=1550915&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 Sat Dec 14 09:38:34 2013
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.Set;
 import javax.annotation.Resource;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.MembershipMod;
 import org.apache.syncope.common.mod.UserMod;
 import org.apache.syncope.common.to.MembershipTO;
@@ -61,7 +62,7 @@ import org.springframework.stereotype.Co
 import org.springframework.transaction.annotation.Transactional;
 
 @Component
-@Transactional(rollbackFor = {Throwable.class})
+@Transactional(rollbackFor = { Throwable.class })
 public class UserDataBinder extends AbstractAttributableDataBinder {
 
     private static final String[] IGNORE_USER_PROPERTIES = {
@@ -430,4 +431,24 @@ public class UserDataBinder extends Abst
     public UserTO getUserTO(final Long userId) {
         return getUserTO(getUserFromId(userId));
     }
+
+    /**
+     * SYNCOPE-459: force virtual attribute changes.
+     * <br />
+     * 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.
+     */
+    public void forceVirtualAttributes(
+            final Long id, final Set<String> vAttrsToBeRemoved, final Set<AttributeMod> vAttrsToBeUpdated) {
+        final SyncopeUser syncopeUser = getUserFromId(id);
+
+        fillVirtual(
+                syncopeUser,
+                vAttrsToBeRemoved,
+                vAttrsToBeUpdated,
+                AttributableUtil.getInstance(syncopeUser));
+    }
 }

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=1550915&r1=1550914&r2=1550915&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 Sat Dec 14 09:38:34 2013
@@ -527,4 +527,32 @@ public class VirAttrTestITCase extends A
         roleService.delete(roleTO.getId());
         // -------------------------------------------
     }
+
+    @Test
+    public void issueSYNCOPE459() {
+        UserTO userTO = getUniqueSampleTO("syncope459@apache.org");
+        userTO.getResources().clear();
+        userTO.getMemberships().clear();
+        userTO.getVirAttrs().clear();
+
+        final AttributeTO virtualReadOnly = attributeTO("virtualReadOnly", "");
+        virtualReadOnly.getValues().clear();
+
+        userTO.getVirAttrs().add(virtualReadOnly);
+
+        userTO = createUser(userTO);
+
+        assertNotNull(userTO.getVirAttrMap().get("virtualReadOnly"));
+
+        UserMod userMod = new UserMod();
+        userMod.setId(userTO.getId());
+
+        AttributeMod virtualdata = new AttributeMod();
+        virtualdata.setSchema("virtualdata");
+
+        userMod.getVirAttrsToUpdate().add(virtualdata);
+
+        userTO = updateUser(userMod);
+        assertNotNull(userTO.getVirAttrMap().get("virtualdata"));
+    }
 }