Search in sources :

Example 26 with ProvisioningResult

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

the class UserITCase method suspendReactivate.

@Test
public void suspendReactivate() {
    UserTO userTO = getUniqueSampleTO("suspendReactivate@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus());
    StatusPatch statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.SUSPEND).token(userTO.getToken()).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("suspended", userTO.getStatus());
    statusPatch = new StatusPatch.Builder().key(userTO.getKey()).type(StatusPatchType.REACTIVATE).build();
    userTO = userService.status(statusPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) Test(org.junit.jupiter.api.Test)

Example 27 with ProvisioningResult

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

the class UserITCase method restResource.

@Test
public void restResource() {
    UserTO userTO = getUniqueSampleTO("rest@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getResources().add("rest-target-resource");
    // 1. create
    ProvisioningResult<UserTO> result = userService.create(userTO, true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    assertEquals("rest-target-resource", result.getPropagationStatuses().get(0).getResource());
    assertEquals("surname", userTO.getPlainAttr("surname").get().getValues().get(0));
    // verify user exists on the backend REST service
    WebClient webClient = WebClient.create("http://localhost:9080/syncope-fit-build-tools/cxf/rest/users/" + result.getEntity().getKey());
    Response response = webClient.get();
    assertEquals(200, response.getStatus());
    assertNotNull(response.getEntity());
    // 2. update
    UserPatch patch = new UserPatch();
    patch.setKey(result.getEntity().getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder().schema("surname").value("surname2").build()).build());
    result = userService.update(patch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    assertEquals("rest-target-resource", result.getPropagationStatuses().get(0).getResource());
    assertEquals("surname2", result.getEntity().getPlainAttr("surname").get().getValues().get(0));
    // verify user still exists on the backend REST service
    response = webClient.get();
    assertEquals(200, response.getStatus());
    assertNotNull(response.getEntity());
    // 3. delete
    result = userService.delete(result.getEntity().getKey()).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    assertEquals("rest-target-resource", result.getPropagationStatuses().get(0).getResource());
    // verify user was removed by the backend REST service
    assertEquals(404, webClient.get().getStatus());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) WebClient(org.apache.cxf.jaxrs.client.WebClient) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Test(org.junit.jupiter.api.Test)

Example 28 with ProvisioningResult

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

the class UserIssuesITCase method issueSYNCOPE426.

@Test
public void issueSYNCOPE426() {
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope426@syncope.apache.org");
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("anotherPassword123").build());
    userTO = userService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 29 with ProvisioningResult

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

the class UserSelfITCase method createAndApprove.

@Test
public void createAndApprove() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // self-create user with membership: goes 'createApproval' with resources and membership but no propagation
    UserTO userTO = UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group("29f96485-729e-4d31-88a1-6fc60e4677f3").build());
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    SyncopeClient anonClient = clientFactory.create();
    userTO = anonClient.getService(UserSelfService.class).create(userTO, true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("createApproval", userTO.getStatus());
    assertFalse(userTO.getMemberships().isEmpty());
    assertFalse(userTO.getResources().isEmpty());
    try {
        resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    // now approve and verify that propagation has happened
    WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
    form = userWorkflowService.claimForm(form.getTaskId());
    form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
    userTO = userWorkflowService.submitForm(form);
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
    assertNotNull(resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey()));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Example 30 with ProvisioningResult

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

ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)39 UserTO (org.apache.syncope.common.lib.to.UserTO)24 Test (org.junit.jupiter.api.Test)21 GroupTO (org.apache.syncope.common.lib.to.GroupTO)14 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 Response (javax.ws.rs.core.Response)8 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)8 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)8 UserService (org.apache.syncope.common.rest.api.service.UserService)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 GenericType (javax.ws.rs.core.GenericType)6 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)6 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)5 SyncopeClient (org.apache.syncope.client.lib.SyncopeClient)4 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4