You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2013/01/29 11:37:56 UTC

svn commit: r1439821 - in /syncope/trunk/core/src: main/java/org/apache/syncope/core/rest/controller/UserController.java test/java/org/apache/syncope/core/rest/UserTestITCase.java

Author: ilgrosso
Date: Tue Jan 29 10:37:55 2013
New Revision: 1439821

URL: http://svn.apache.org/viewvc?rev=1439821&view=rev
Log:
[SYNCOPE-122] Making the whole process more robust

Modified:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

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=1439821&r1=1439820&r2=1439821&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 Tue Jan 29 10:37:55 2013
@@ -139,7 +139,7 @@ public class UserController {
     public ModelAndView count() {
         return new ModelAndView().addObject(countInternal());
     }
-    
+
     @Transactional(readOnly = true, rollbackFor = {Throwable.class})
     public int countInternal() {
         Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
@@ -285,7 +285,7 @@ public class UserController {
         response.setStatus(HttpServletResponse.SC_CREATED);
         return savedTO;
     }
-    
+
     public UserTO createInternal(final UserTO userTO) {
         LOG.debug("User create called with {}", userTO);
 
@@ -337,35 +337,39 @@ public class UserController {
         WorkflowResult<Map.Entry<Long, Boolean>> updated = uwfAdapter.update(userMod);
 
         // 2. propagate password update only to requested resources
-        List<PropagationTask> tasks;
+        List<PropagationTask> tasks = new ArrayList<PropagationTask>();
         if (userMod.getPwdPropRequest() == null) {
             // 2a. no specific password propagation request: generate propagation tasks for any resource associated
             tasks = propagationManager.getUserUpdateTaskIds(updated, changedPwd,
                     userMod.getVirtualAttributesToBeRemoved(), userMod.getVirtualAttributesToBeUpdated());
         } else {
-            // 2b. generate the propagation task list in two phases: first the ones containing password, 
+            // 2b. generate the propagation task list in two phases: first the ones containing password,
             // the the rest (with no password)
             final PropagationByResource origPropByRes = new PropagationByResource();
             origPropByRes.merge(updated.getPropByRes());
-            SyncopeUser user = dataBinder.getUserFromId(updated.getResult().getKey());
-            origPropByRes.addAll(ResourceOperation.UPDATE, user.getResourceNames());
-            origPropByRes.purge();
 
+            Set<String> pwdResourceNames = userMod.getPwdPropRequest().getResources();
+            SyncopeUser user = dataBinder.getUserFromId(updated.getResult().getKey());
+            pwdResourceNames.retainAll(user.getResourceNames());
             final PropagationByResource pwdPropByRes = new PropagationByResource();
-            pwdPropByRes.merge(origPropByRes);
-            pwdPropByRes.retainAll(userMod.getPwdPropRequest().getResources());
+            pwdPropByRes.addAll(ResourceOperation.UPDATE, pwdResourceNames);
             updated.setPropByRes(pwdPropByRes);
 
-            tasks = propagationManager.getUserUpdateTaskIds(updated, changedPwd,
-                    userMod.getVirtualAttributesToBeRemoved(), userMod.getVirtualAttributesToBeUpdated());
+            if (!pwdPropByRes.isEmpty()) {
+                tasks.addAll(propagationManager.getUserUpdateTaskIds(updated, changedPwd,
+                        userMod.getVirtualAttributesToBeRemoved(), userMod.getVirtualAttributesToBeUpdated()));
+            }
 
             final PropagationByResource nonPwdPropByRes = new PropagationByResource();
             nonPwdPropByRes.merge(origPropByRes);
-            nonPwdPropByRes.removeAll(userMod.getPwdPropRequest().getResources());
+            nonPwdPropByRes.removeAll(pwdResourceNames);
+            nonPwdPropByRes.purge();
             updated.setPropByRes(nonPwdPropByRes);
 
-            tasks.addAll(propagationManager.getUserUpdateTaskIds(updated, null,
-                    userMod.getVirtualAttributesToBeRemoved(), userMod.getVirtualAttributesToBeUpdated()));
+            if (!nonPwdPropByRes.isEmpty()) {
+                tasks.addAll(propagationManager.getUserUpdateTaskIds(updated, null,
+                        userMod.getVirtualAttributesToBeRemoved(), userMod.getVirtualAttributesToBeUpdated()));
+            }
 
             updated.setPropByRes(origPropByRes);
         }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1439821&r1=1439820&r2=1439821&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Tue Jan 29 10:37:55 2013
@@ -1916,10 +1916,15 @@ public class UserTestITCase extends Abst
 
         userTO = userService.update(userMod.getId(), userMod);
 
-        // 3a. verify that password hasn't changed on Syncope
+        // 3a. Chech that only a single propagation took place
+        assertNotNull(userTO.getPropagationStatusTOs());
+        assertEquals(1, userTO.getPropagationStatusTOs().size());
+        assertEquals("resource-testdb", userTO.getPropagationStatusTOs().iterator().next().getResource());
+        
+        // 3b. verify that password hasn't changed on Syncope
         assertEquals(pwdOnSyncope, userTO.getPassword());
 
-        // 3b. verify that password *has* changed on testdb
+        // 3c. verify that password *has* changed on testdb
         userOnDb = resourceService.getConnector("resource-testdb", AttributableType.USER, userTO.getUsername());
         final AttributeTO pwdOnTestDbAttrAfter = userOnDb.getAttributeMap().get(OperationalAttributes.PASSWORD_NAME);
         assertNotNull(pwdOnTestDbAttrAfter);
@@ -1927,7 +1932,7 @@ public class UserTestITCase extends Abst
         assertFalse(pwdOnTestDbAttrAfter.getValues().isEmpty());
         assertNotEquals(pwdOnTestDb, pwdOnTestDbAttrAfter.getValues().iterator().next());
 
-        // 3c. verify that password hasn't changed on testdb2
+        // 3d. verify that password hasn't changed on testdb2
         userOnDb2 = resourceService.getConnector("resource-testdb2", AttributableType.USER, userTO.getUsername());
         final AttributeTO pwdOnTestDb2AttrAfter = userOnDb2.getAttributeMap().get(OperationalAttributes.PASSWORD_NAME);
         assertNotNull(pwdOnTestDb2AttrAfter);