Search in sources :

Example 81 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE454.

@Test
public void issueSYNCOPE454() throws NamingException {
    // 1. create user with LDAP resource (with 'Generate password if missing' enabled)
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope454@syncope.apache.org");
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // 2. read resource configuration for LDAP binding
    ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
    // 3. try (and succeed) to perform simple LDAP binding with provided password ('password123')
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "password123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
    // 4. update user without any password change request
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
    userService.update(userPatch);
    // 5. try (and succeed again) to perform simple LDAP binding: password has not changed
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "password123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 82 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE402.

@Test
public void issueSYNCOPE402() {
    // 1. create an user with strict mandatory attributes only
    UserTO userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    String userId = getUUIDString() + "syncope402@syncope.apache.org";
    userTO.setUsername(userId);
    userTO.setPassword("password123");
    userTO.getPlainAttrs().add(attrTO("userId", userId));
    userTO.getPlainAttrs().add(attrTO("fullname", userId));
    userTO.getPlainAttrs().add(attrTO("surname", userId));
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertTrue(userTO.getResources().isEmpty());
    // 2. update assigning a resource NOT forcing mandatory constraints
    // AND priority: must fail with PropagationException
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123").build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS1).build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_TESTDB).build());
    ProvisioningResult<UserTO> result = updateUser(userPatch);
    PropagationStatus ws1PropagationStatus = result.getPropagationStatuses().stream().filter(propStatus -> RESOURCE_NAME_WS1.equals(propStatus.getResource())).findFirst().orElse(null);
    assertNotNull(ws1PropagationStatus);
    assertEquals(RESOURCE_NAME_WS1, ws1PropagationStatus.getResource());
    assertNotNull(ws1PropagationStatus.getFailureReason());
    assertEquals(PropagationTaskExecStatus.FAILURE, ws1PropagationStatus.getStatus());
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 83 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issue186.

@Test
public void issue186() {
    // 1. create an user with strict mandatory attributes only
    UserTO userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    String userId = getUUIDString() + "issue186@syncope.apache.org";
    userTO.setUsername(userId);
    userTO.setPassword("password123");
    userTO.getPlainAttrs().add(attrTO("userId", userId));
    userTO.getPlainAttrs().add(attrTO("fullname", userId));
    userTO.getPlainAttrs().add(attrTO("surname", userId));
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertTrue(userTO.getResources().isEmpty());
    // 2. update assigning a resource forcing mandatory constraints: must fail with RequiredValuesMissing
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123").build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS2).build());
    try {
        userTO = updateUser(userPatch).getEntity();
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
    // 3. update assigning a resource NOT forcing mandatory constraints
    // AND priority: must fail with PropagationException
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123").build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_WS1).build());
    ProvisioningResult<UserTO> result = updateUser(userPatch);
    assertNotNull(result.getPropagationStatuses().get(0).getFailureReason());
    userTO = result.getEntity();
    // 4. update assigning a resource NOT forcing mandatory constraints
    // BUT not priority: must succeed
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123456").build());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_CSV).build());
    updateUser(userPatch);
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 84 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE108.

@Test
public void issueSYNCOPE108() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope108@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getMemberships().clear();
    userTO.getVirAttrs().clear();
    userTO.getAuxClasses().add("csv");
    userTO.getMemberships().add(new MembershipTO.Builder().group("0626100b-a4ba-4e00-9971-86fad52a6216").build());
    userTO.getMemberships().add(new MembershipTO.Builder().group("ba9ed509-b1f5-48ab-a334-c8530a6422dc").build());
    userTO.getResources().add(RESOURCE_NAME_CSV);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals(2, userTO.getMemberships().size());
    assertEquals(1, userTO.getResources().size());
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // -----------------------------------
    // Remove the first membership: de-provisioning shouldn't happen
    // -----------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(userTO.getMemberships().get(0).getGroupKey()).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    assertEquals(1, userTO.getMemberships().size());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // -----------------------------------
    // -----------------------------------
    // Remove the resource assigned directly: de-provisioning shouldn't happen
    // -----------------------------------
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(userTO.getResources().iterator().next()).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    assertEquals(1, userTO.getMemberships().size());
    assertFalse(userTO.getResources().isEmpty());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // -----------------------------------
    // -----------------------------------
    // Remove the first membership: de-provisioning should happen
    // -----------------------------------
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(userTO.getMemberships().get(0).getGroupKey()).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    assertTrue(userTO.getMemberships().isEmpty());
    assertTrue(userTO.getResources().isEmpty());
    try {
        resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
        fail("Read should not succeeed");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 85 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE136AES.

@Test
public void issueSYNCOPE136AES() {
    // 1. read configured cipher algorithm in order to be able to restore it at the end of test
    AttrTO pwdCipherAlgo = configurationService.get("password.cipher.algorithm");
    String origpwdCipherAlgo = pwdCipherAlgo.getValues().get(0);
    // 2. set AES password cipher algorithm
    pwdCipherAlgo.getValues().set(0, "AES");
    configurationService.set(pwdCipherAlgo);
    UserTO userTO = null;
    try {
        // 3. create user with no resources
        userTO = UserITCase.getUniqueSampleTO("syncope136_AES@apache.org");
        userTO.getResources().clear();
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        // 4. update user, assign a propagation priority resource but don't provide any password
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_LDAP).build());
        userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_LDAP).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        userTO = result.getEntity();
        assertNotNull(userTO);
        // 5. verify that propagation was successful
        List<PropagationStatus> props = result.getPropagationStatuses();
        assertNotNull(props);
        assertEquals(1, props.size());
        PropagationStatus prop = props.iterator().next();
        assertNotNull(prop);
        assertEquals(RESOURCE_NAME_LDAP, prop.getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
    } finally {
        // restore initial cipher algorithm
        pwdCipherAlgo.getValues().set(0, origpwdCipherAlgo);
        configurationService.set(pwdCipherAlgo);
        if (userTO != null) {
            deleteUser(userTO.getKey());
        }
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9