Search in sources :

Example 21 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO 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 22 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO 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 23 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE505LDAP.

@Test
public void issueSYNCOPE505LDAP() throws Exception {
    // 1. create user
    UserTO user = UserITCase.getUniqueSampleTO("syncope505-ldap@syncope.apache.org");
    user.setPassword("security123");
    user = createUser(user).getEntity();
    assertNotNull(user);
    assertTrue(user.getResources().isEmpty());
    // 2. Add LDAPPasswordPropagationActions
    ImplementationTO propagationActions = new ImplementationTO();
    propagationActions.setKey(LDAPPasswordPropagationActions.class.getSimpleName());
    propagationActions.setEngine(ImplementationEngine.JAVA);
    propagationActions.setType(ImplementationType.PROPAGATION_ACTIONS);
    propagationActions.setBody(LDAPPasswordPropagationActions.class.getName());
    Response response = implementationService.create(propagationActions);
    propagationActions = implementationService.read(propagationActions.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    assertNotNull(propagationActions);
    ResourceTO resourceTO = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().add(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(false);
    resourceService.update(resourceTO);
    // 3. Add a resource to the User
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(user.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());
    user = updateUser(userPatch).getEntity();
    assertNotNull(user);
    assertEquals(1, user.getResources().size());
    // 4. Check that the LDAP resource has the correct password
    ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), user.getKey());
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "security123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
    // 5. Remove LDAPPasswordPropagationActions
    resourceTO = resourceService.read(RESOURCE_NAME_LDAP);
    assertNotNull(resourceTO);
    resourceTO.getPropagationActions().remove(propagationActions.getKey());
    resourceTO.setRandomPwdIfNotProvided(true);
    resourceService.update(resourceTO);
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) LDAPPasswordPropagationActions(org.apache.syncope.core.provisioning.java.propagation.LDAPPasswordPropagationActions) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) 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 24 with ConnObjectTO

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

the class UserIssuesITCase method issueSYNCOPE493.

@Test
public void issueSYNCOPE493() {
    // 1.  create user and check that firstname is not propagated on resource with mapping for firstname set to NONE
    UserTO userTO = UserITCase.getUniqueSampleTO("493@test.org");
    userTO.getResources().add(RESOURCE_NAME_WS1);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(userTO);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO actual = resourceService.readConnObject(RESOURCE_NAME_WS1, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(actual);
    // check if mapping attribute with purpose NONE really hasn't been propagated
    assertFalse(actual.getAttr("NAME").isPresent());
    // 2.  update resource ws-target-resource-1
    ResourceTO ws1 = resourceService.read(RESOURCE_NAME_WS1);
    assertNotNull(ws1);
    MappingTO ws1NewUMapping = ws1.getProvision(AnyTypeKind.USER.name()).get().getMapping();
    // change purpose from NONE to BOTH
    for (ItemTO itemTO : ws1NewUMapping.getItems()) {
        if ("firstname".equals(itemTO.getIntAttrName())) {
            itemTO.setPurpose(MappingPurpose.BOTH);
        }
    }
    ws1.getProvision(AnyTypeKind.USER.name()).get().setMapping(ws1NewUMapping);
    resourceService.update(ws1);
    ResourceTO newWs1 = resourceService.read(ws1.getKey());
    assertNotNull(newWs1);
    // check for existence
    Collection<ItemTO> mapItems = newWs1.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems();
    assertNotNull(mapItems);
    assertEquals(7, mapItems.size());
    // 3.  update user and check firstname propagation
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("firstname", "firstnameNew"));
    result = updateUser(userPatch);
    assertNotNull(userTO);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO newUser = resourceService.readConnObject(RESOURCE_NAME_WS1, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(newUser.getAttr("NAME"));
    assertEquals("firstnameNew", newUser.getAttr("NAME").get().getValues().get(0));
    // 4.  restore resource ws-target-resource-1 mapping
    ws1NewUMapping = newWs1.getProvision(AnyTypeKind.USER.name()).get().getMapping();
    // restore purpose from BOTH to NONE
    for (ItemTO itemTO : ws1NewUMapping.getItems()) {
        if ("firstname".equals(itemTO.getIntAttrName())) {
            itemTO.setPurpose(MappingPurpose.NONE);
        }
    }
    newWs1.getProvision(AnyTypeKind.USER.name()).get().setMapping(ws1NewUMapping);
    resourceService.update(newWs1);
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 25 with ConnObjectTO

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

the class VirAttrITCase method issueSYNCOPE260.

@Test
public void issueSYNCOPE260() {
    // create new virtual schema for the resource below
    ResourceTO ws2 = resourceService.read(RESOURCE_NAME_WS2);
    ProvisionTO provision = ws2.getProvision(AnyTypeKind.USER.name()).get();
    assertNotNull(provision);
    VirSchemaTO virSchema = new VirSchemaTO();
    virSchema.setKey("syncope260" + getUUIDString());
    virSchema.setExtAttrName("companyName");
    virSchema.setResource(RESOURCE_NAME_WS2);
    virSchema.setAnyType(provision.getAnyType());
    virSchema = createSchema(SchemaType.VIRTUAL, virSchema);
    assertNotNull(virSchema);
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("syncope260" + getUUIDString());
    newClass.getVirSchemas().add(virSchema.getKey());
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    // ----------------------------------
    // create user and check virtual attribute value propagation
    // ----------------------------------
    UserTO userTO = UserITCase.getUniqueSampleTO("260@a.com");
    userTO.getAuxClasses().add(newClass.getKey());
    userTO.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue"));
    userTO.getResources().add(RESOURCE_NAME_WS2);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user virtual attribute and check virtual attribute value update propagation
    // ----------------------------------
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getVirAttrs().add(attrTO(virSchema.getKey(), "virtualvalue2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // suspend/reactivate user and check virtual attribute value (unchanged)
    // ----------------------------------
    StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("suspended", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertEquals("active", userTO.getStatus());
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
    // ----------------------------------
    // ----------------------------------
    // update user attribute and check virtual attribute value (unchanged)
    // ----------------------------------
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "Surname2"));
    result = updateUser(userPatch);
    assertNotNull(result);
    assertFalse(result.getPropagationStatuses().isEmpty());
    assertEquals(RESOURCE_NAME_WS2, result.getPropagationStatuses().get(0).getResource());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    connObjectTO = resourceService.readConnObject(RESOURCE_NAME_WS2, AnyTypeKind.USER.name(), userTO.getKey());
    assertEquals("Surname2", connObjectTO.getAttr("SURNAME").get().getValues().get(0));
    // virtual attribute value did not change
    assertFalse(connObjectTO.getAttr("COMPANYNAME").get().getValues().isEmpty());
    assertEquals("virtualvalue2", connObjectTO.getAttr("COMPANYNAME").get().getValues().get(0));
// ----------------------------------
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) UserTO(org.apache.syncope.common.lib.to.UserTO) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) 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