Author: fmartelli Date: Fri May 31 14:46:14 2013 New Revision: 1488258 URL: http://svn.apache.org/r1488258 Log: [SYNCOPE-383] Pwd won't be mandatory anymore during user update (removed test for issue 147). Pwd existence will be checked during provisioning and may be considered like a generic propagation error.
Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java?rev=1488258&r1=1488257&r2=1488258&view=diff ============================================================================== --- syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java (original) +++ syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/UserDataBinder.java Fri May 31 14:46:14 2013 @@ -244,17 +244,12 @@ public class UserDataBinder extends Abst SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST); - // when requesting to add user to new resources, either directly or - // through role subscription, password is mandatory (issue 147) - // first, let's take current resources into account Set<String> currentResources = user.getResourceNames(); // password if (StringUtils.isNotBlank(userMod.getPassword())) { setPassword(user, userMod.getPassword(), scce); - user.setChangePwdDate(new Date()); - propByRes.addAll(ResourceOperation.UPDATE, currentResources); } @@ -365,28 +360,6 @@ public class UserDataBinder extends Abst } } - // now, let's see if there are new resource subscriptions without providing password - if (StringUtils.isBlank(userMod.getPassword())) { - Set<String> updatedResources = user.getResourceNames(); - updatedResources.removeAll(currentResources); - - for (String resourceName : updatedResources) { - final ExternalResource resource = resourceDAO.find(resourceName); - - if (!user.canDecodePassword() && resource != null && !resource.isRandomPwdIfNotProvided() - && resource.getUmapping() != null && !MappingUtil.getMatchingMappingItems( - resource.getUmapping().getItems(), "password", IntMappingType.Password).isEmpty()) { - - SyncopeClientException sce = - new SyncopeClientException(SyncopeClientExceptionType.RequiredValuesMissing); - sce.addElement("Password cannot be empty when subscribing to new resources"); - scce.addException(sce); - - throw scce; - } - } - } - propByRes.addAll(ResourceOperation.DELETE, toBeDeprovisioned); propByRes.addAll(ResourceOperation.UPDATE, toBeProvisioned); Modified: syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1488258&r1=1488257&r2=1488258&view=diff ============================================================================== --- syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original) +++ syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Fri May 31 14:46:14 2013 @@ -317,35 +317,6 @@ public class UserTestITCase extends Abst } @Test - public void issue147() { - // 1. create an user without role nor resources - UserTO userTO = getUniqueSampleTO("1...@t.com"); - - userTO = createUser(userTO); - assertNotNull(userTO); - assertTrue(userTO.getResources().isEmpty()); - - // 2. try to update by adding a resource, but no password: must fail - UserMod userMod = new UserMod(); - userMod.setId(userTO.getId()); - userMod.addResourceToBeAdded("ws-target-resource-2"); - - SyncopeClientException sce = null; - try { - userService.update(userMod.getId(), userMod); - } catch (SyncopeClientCompositeErrorException scce) { - sce = scce.getException(SyncopeClientExceptionType.RequiredValuesMissing); - } - assertNotNull(sce); - - // 3. provide password: now update must work - userMod.setPassword("newPassword"); - userTO = userService.update(userMod.getId(), userMod); - assertNotNull(userTO); - assertEquals(1, userTO.getResources().size()); - } - - @Test public void createUserWithDbPropagation() { UserTO userTO = getUniqueSampleTO("y...@yyy.yyy"); userTO.addResource(RESOURCE_NAME_TESTDB); @@ -2219,13 +2190,42 @@ public class UserTestITCase extends Abst assertNotNull(scce.getException(SyncopeClientExceptionType.NotFound)); } } - - @Test + + @Test public void issueSYNCOPE373() { UserTO userTO = userService.readSelf(); assertEquals(ADMIN_UNAME, userTO.getUsername()); } + @Test + public void issueSYNCOPE383() { + // 1. create user on testdb and testdb2 + UserTO userTO = getUniqueSampleTO("syncope...@apache.org"); + userTO.getResources().clear(); + userTO = createUser(userTO); + assertNotNull(userTO); + + // 2. assign resource without specifying a new pwd and check propagation failure + UserMod userMod = new UserMod(); + userMod.setId(userTO.getId()); + userMod.addResourceToBeAdded(RESOURCE_NAME_TESTDB); + userTO = userService.update(userMod.getId(), userMod); + assertEquals(RESOURCE_NAME_TESTDB, userTO.getResources().iterator().next()); + assertFalse(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful()); + + // 3. request to change password only on testdb + userMod = new UserMod(); + userMod.setId(userTO.getId()); + userMod.setPassword(getUUIDString()); + PropagationRequestTO pwdPropRequest = new PropagationRequestTO(); + pwdPropRequest.addResource(RESOURCE_NAME_TESTDB); + userMod.setPwdPropRequest(pwdPropRequest); + + userTO = userService.update(userMod.getId(), userMod); + assertEquals(RESOURCE_NAME_TESTDB, userTO.getResources().iterator().next()); + assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful()); + } + private boolean getBooleanAttribute(ConnObjectTO connObjectTO, String attrName) { return Boolean.parseBoolean(getStringAttribute(connObjectTO, attrName)); }