Search in sources :

Example 71 with UserPatch

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

the class UserITCase method updatePasswordOnly.

@Test
public void updatePasswordOnly() {
    int beforeTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build()).getTotalCount();
    assertFalse(beforeTasks <= 0);
    UserTO userTO = getUniqueSampleTO("pwdonly@t.com");
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    userTO = createUser(userTO).getEntity();
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123").resource(RESOURCE_NAME_WS2).build());
    userTO = updateUser(userPatch).getEntity();
    // check for changePwdDate
    assertNotNull(userTO.getChangePwdDate());
    int afterTasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build()).getTotalCount();
    assertFalse(afterTasks <= 0);
    assertTrue(beforeTasks < afterTasks);
}
Also used : TaskQuery(org.apache.syncope.common.rest.api.beans.TaskQuery) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 72 with UserPatch

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

the class UserITCase method async.

@Test
public void async() {
    SyncopeClient asyncClient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
    UserService asyncService = asyncClient.nullPriorityAsync(asyncClient.getService(UserService.class), true);
    UserTO user = getUniqueSampleTO("async@syncope.apache.org");
    user.getResources().add(RESOURCE_NAME_TESTDB);
    user.getResources().add(RESOURCE_NAME_TESTDB2);
    user.getResources().add(RESOURCE_NAME_LDAP);
    ProvisioningResult<UserTO> result = asyncService.create(user, true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertNotNull(result);
    verifyAsyncResult(result.getPropagationStatuses());
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(result.getEntity().getKey());
    userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).resources(RESOURCE_NAME_LDAP, RESOURCE_NAME_TESTDB, RESOURCE_NAME_TESTDB2).value("password321").build());
    result = asyncService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertNotNull(result);
    verifyAsyncResult(result.getPropagationStatuses());
    result = asyncService.delete(result.getEntity().getKey()).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    });
    assertNotNull(result);
    verifyAsyncResult(result.getPropagationStatuses());
}
Also used : GenericType(javax.ws.rs.core.GenericType) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 73 with UserPatch

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

the class UserITCase method updateInvalidPassword.

@Test
public void updateInvalidPassword() {
    assertThrows(SyncopeClientException.class, () -> {
        UserTO userTO = getSampleTO("updateinvalid@password.com");
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        userPatch.setPassword(new PasswordPatch.Builder().value("pass").build());
        userService.update(userPatch);
    });
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 74 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch 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 75 with UserPatch

use of org.apache.syncope.common.lib.patch.UserPatch 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)

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