Search in sources :

Example 16 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class GroupITCase method create.

@Test
public void create() {
    GroupTO groupTO = getSampleTO("lastGroup");
    groupTO.getVirAttrs().add(attrTO("rvirtualdata", "rvirtualvalue"));
    groupTO.setGroupOwner("f779c0d4-633b-4be5-8f57-32eb478a3ca5");
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertNotNull(groupTO.getVirAttr("rvirtualdata").get().getValues());
    assertFalse(groupTO.getVirAttr("rvirtualdata").get().getValues().isEmpty());
    assertEquals("rvirtualvalue", groupTO.getVirAttr("rvirtualdata").get().getValues().get(0));
    assertTrue(groupTO.getResources().contains(RESOURCE_NAME_LDAP));
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), groupTO.getKey());
    assertNotNull(connObjectTO);
    assertNotNull(connObjectTO.getAttr("owner"));
    // SYNCOPE-515: remove ownership
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.setGroupOwner(new StringReplacePatchItem());
    assertNull(updateGroup(groupPatch).getEntity().getGroupOwner());
}
Also used : StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 17 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class GroupITCase method bulkMembersAction.

@Test
public void bulkMembersAction() throws InterruptedException {
    // 1. create group without resources
    GroupTO groupTO = getBasicSampleTO("forProvision");
    groupTO = createGroup(groupTO).getEntity();
    // 2. create user with such group assigned
    UserTO userTO = UserITCase.getUniqueSampleTO("forProvision@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
    userTO = createUser(userTO).getEntity();
    // 3. modify the group by assiging the LDAP resource
    GroupPatch groupPatch = new GroupPatch();
    groupPatch.setKey(groupTO.getKey());
    groupPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).build());
    ProvisioningResult<GroupTO> groupUpdateResult = updateGroup(groupPatch);
    groupTO = groupUpdateResult.getEntity();
    PropagationStatus propStatus = groupUpdateResult.getPropagationStatuses().get(0);
    assertEquals(RESOURCE_NAME_LDAP, propStatus.getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, propStatus.getStatus());
    // 4. verify that the user above is not found on LDAP
    try {
        resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        // 5. bulk provision group members
        ExecTO exec = groupService.bulkMembersAction(groupTO.getKey(), BulkMembersActionType.PROVISION);
        assertNotNull(exec.getRefKey());
        int i = 0;
        int maxit = 50;
        // wait for task exec completion (executions incremented)
        SchedTaskTO taskTO;
        do {
            Thread.sleep(1000);
            taskTO = taskService.read(TaskType.SCHEDULED, exec.getRefKey(), true);
            assertNotNull(taskTO);
            assertNotNull(taskTO.getExecutions());
            i++;
        } while (taskTO.getExecutions().isEmpty() && i < maxit);
        assertFalse(taskTO.getExecutions().isEmpty());
        assertEquals(TaskJob.Status.SUCCESS.name(), taskTO.getExecutions().get(0).getStatus());
        // 6. verify that the user above is now fond on LDAP
        ConnObjectTO userOnLdap = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
        assertNotNull(userOnLdap);
    } finally {
        groupService.delete(groupTO.getKey());
        userService.delete(userTO.getKey());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 18 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class UserITCase method suspendReactivateOnResource.

@Test
public void suspendReactivateOnResource() {
    // Assert resources are present
    ResourceTO dbTable = resourceService.read(RESOURCE_NAME_TESTDB);
    assertNotNull(dbTable);
    ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(ldap);
    // Create user with reference to resources
    UserTO userTO = getUniqueSampleTO("suspreactonresource@syncope.apache.org");
    userTO.getMemberships().clear();
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus());
    String userKey = userTO.getKey();
    // Suspend with effect on syncope, ldap and db => user should be suspended in syncope and all resources
    StatusPatch statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.SUSPEND).onSyncope(true).resources(RESOURCE_NAME_TESTDB, RESOURCE_NAME_LDAP).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("suspended", userTO.getStatus());
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
    assertFalse(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userKey);
    assertNotNull(connObjectTO);
    // Suspend and reactivate only on ldap => db and syncope should still show suspended
    statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.SUSPEND).onSyncope(false).resources(RESOURCE_NAME_LDAP).build();
    userService.status(statusPatch);
    statusPatch.setType(StatusPatchType.REACTIVATE);
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("suspended", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
    assertFalse(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
    // Reactivate on syncope and db => syncope and db should show the user as active
    statusPatch = new StatusPatch.Builder().key(userKey).type(StatusPatchType.REACTIVATE).onSyncope(true).resources(RESOURCE_NAME_TESTDB).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userKey);
    assertTrue(getBooleanAttribute(connObjectTO, OperationalAttributes.ENABLE_NAME));
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 19 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE267.

@Test
public void issueSYNCOPE267() {
    // ----------------------------------
    // create user and check virtual attribute value propagation
    // ----------------------------------
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope267@apache.org");
    userTO.getVirAttrs().add(attrTO("virtualdata", "virtualvalue"));
    userTO.getResources().clear();
    userTO.getResources().add(RESOURCE_NAME_DBVIRATTR);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_DBVIRATTR, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBVIRATTR, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    assertEquals("virtualvalue", connObjectTO.getAttr("USERNAME").get().getValues().get(0));
    // ----------------------------------
    userTO = userService.read(userTO.getKey());
    assertNotNull(userTO);
    assertEquals(1, userTO.getVirAttrs().size());
    assertEquals("virtualvalue", userTO.getVirAttrs().iterator().next().getValues().get(0));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 20 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE391.

@Test
public void issueSYNCOPE391() {
    // 1. create user on Syncope with null password
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope391@syncope.apache.org");
    userTO.setPassword(null);
    userTO = createUser(userTO, false).getEntity();
    assertNotNull(userTO);
    assertNull(userTO.getPassword());
    // 2. create existing user on csv and check that password on Syncope is null and that password on resource
    // doesn't change
    userTO = new UserTO();
    userTO.setRealm(SyncopeConstants.ROOT_REALM);
    userTO.setPassword(null);
    userTO.setUsername("syncope391@syncope.apache.org");
    userTO.getPlainAttrs().add(attrTO("fullname", "fullname"));
    userTO.getPlainAttrs().add(attrTO("firstname", "nome0"));
    userTO.getPlainAttrs().add(attrTO("surname", "cognome0"));
    userTO.getPlainAttrs().add(attrTO("userId", "syncope391@syncope.apache.org"));
    userTO.getPlainAttrs().add(attrTO("email", "syncope391@syncope.apache.org"));
    userTO.getAuxClasses().add("csv");
    userTO.getResources().add(RESOURCE_NAME_CSV);
    userTO = createUser(userTO, false).getEntity();
    assertNotNull(userTO);
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // check if password has not changed
    assertEquals("password0", connObjectTO.getAttr(OperationalAttributes.PASSWORD_NAME).get().getValues().get(0));
    assertNull(userTO.getPassword());
    // 3. create user with not null password and propagate onto resource-csv, specify not to save password on
    // Syncope local storage
    userTO = UserITCase.getUniqueSampleTO("syncope391@syncope.apache.org");
    userTO.setPassword("passwordTESTNULL1");
    userTO.getVirAttrs().clear();
    userTO.getAuxClasses().add("csv");
    userTO.getResources().add(RESOURCE_NAME_CSV);
    userTO = createUser(userTO, false).getEntity();
    assertNotNull(userTO);
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // check if password has been propagated and that saved userTO's password is null
    assertEquals("passwordTESTNULL1", connObjectTO.getAttr(OperationalAttributes.PASSWORD_NAME).get().getValues().get(0));
    assertNull(userTO.getPassword());
    // 4. create user and propagate password on resource-csv and on Syncope local storage
    userTO = UserITCase.getUniqueSampleTO("syncope391@syncope.apache.org");
    userTO.setPassword("passwordTESTNULL1");
    userTO.getVirAttrs().clear();
    userTO.getAuxClasses().add("csv");
    userTO.getResources().add(RESOURCE_NAME_CSV);
    // storePassword true by default
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_CSV, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(connObjectTO);
    // check if password has been correctly propagated on Syncope and resource-csv as usual
    assertEquals("passwordTESTNULL1", connObjectTO.getAttr(OperationalAttributes.PASSWORD_NAME).get().getValues().get(0));
    Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(userTO.getUsername(), "passwordTESTNULL1").self();
    assertNotNull(self);
    // 4. add password policy to resource with passwordNotStore to false --> must store password
    ResourceTO csv = resourceService.read(RESOURCE_NAME_CSV);
    assertNotNull(csv);
    try {
        csv.setPasswordPolicy("55e5de0b-c79c-4e66-adda-251b6fb8579a");
        resourceService.update(csv);
        csv = resourceService.read(RESOURCE_NAME_CSV);
        assertEquals("55e5de0b-c79c-4e66-adda-251b6fb8579a", csv.getPasswordPolicy());
        userTO = UserITCase.getUniqueSampleTO("syncope391@syncope.apache.org");
        userTO.setPassword(null);
        userTO.getVirAttrs().clear();
        userTO.getAuxClasses().add("csv");
        userTO.getResources().add(RESOURCE_NAME_CSV);
        createUser(userTO, false);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidUser, e.getType());
        assertTrue(e.getMessage().contains("Password mandatory"));
    } finally {
        // resource csv with null password policy
        csv.setPasswordPolicy(null);
        resourceService.update(csv);
    }
}
Also used : ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)31 Test (org.junit.jupiter.api.Test)24 UserTO (org.apache.syncope.common.lib.to.UserTO)20 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 GroupTO (org.apache.syncope.common.lib.to.GroupTO)9 ArrayList (java.util.ArrayList)8 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)7 Response (javax.ws.rs.core.Response)6 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 List (java.util.List)4 Optional (java.util.Optional)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Set (java.util.Set)3