Search in sources :

Example 56 with UserPatch

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

the class ProvisionProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    List<String> resources = exchange.getProperty("resources", List.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (getAnyTypeKind() == AnyTypeKind.USER) {
        Boolean changePwd = exchange.getProperty("changePwd", Boolean.class);
        String password = exchange.getProperty("password", String.class);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(key);
        userPatch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
        if (changePwd) {
            userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build());
        }
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<>(ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update");
        List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    } else {
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        AnyTypeKind anyTypeKind = AnyTypeKind.GROUP;
        if (getAnyTypeKind() != null) {
            anyTypeKind = getAnyTypeKind();
        }
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(anyTypeKind, key, false, null, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 57 with UserPatch

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

the class SearchITCase method issueSYNCOPE1223.

@Test
public void issueSYNCOPE1223() {
    UserPatch patch = new UserPatch();
    patch.setKey("vivaldi");
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("ctype", "ou=sample,o=isp")).build());
    userService.update(patch);
    try {
        PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("ou=sample%252Co=isp").query()).build());
        assertEquals(1, users.getTotalCount());
        assertEquals("vivaldi", users.getResult().get(0).getUsername());
    } finally {
        patch.getPlainAttrs().clear();
        patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("ctype", "F")).build());
        userService.update(patch);
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AnyQuery(org.apache.syncope.common.rest.api.beans.AnyQuery) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) Test(org.junit.jupiter.api.Test)

Example 58 with UserPatch

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

the class UserITCase method updateWithoutPassword.

@Test
public void updateWithoutPassword() {
    UserTO userTO = getUniqueSampleTO("updatewithout@password.com");
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("ctype").build()).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    assertFalse(userTO.getPlainAttr("ctype").isPresent());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 59 with UserPatch

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

the class UserITCase method update.

@Test
public void update() {
    UserTO userTO = getUniqueSampleTO("g.h@t.com");
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    userTO = createUser(userTO).getEntity();
    assertFalse(userTO.getDerAttrs().isEmpty());
    assertEquals(1, userTO.getMemberships().size());
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch.Builder().value("new2Password").build());
    String newUserId = getUUIDString() + "t.w@spre.net";
    userPatch.getPlainAttrs().add(attrAddReplacePatch("userId", newUserId));
    String newFullName = getUUIDString() + "g.h@t.com";
    userPatch.getPlainAttrs().add(attrAddReplacePatch("fullname", newFullName));
    userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(userTO.getMemberships().get(0).getGroupKey()).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    // issue SYNCOPE-15
    assertNotNull(userTO.getCreationDate());
    assertNotNull(userTO.getCreator());
    assertNotNull(userTO.getLastChangeDate());
    assertNotNull(userTO.getLastModifier());
    assertTrue(userTO.getCreationDate().before(userTO.getLastChangeDate()));
    assertEquals(1, userTO.getMemberships().size());
    assertFalse(userTO.getDerAttrs().isEmpty());
    AttrTO userIdAttr = userTO.getPlainAttr("userId").get();
    assertEquals(Collections.singletonList(newUserId), userIdAttr.getValues());
    AttrTO fullNameAttr = userTO.getPlainAttr("fullname").get();
    assertEquals(Collections.singletonList(newFullName), fullNameAttr.getValues());
    // update by username
    userPatch = new UserPatch();
    userPatch.setKey(userTO.getUsername());
    String newUsername = UUID.randomUUID().toString();
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(newUsername).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    assertEquals(newUsername, userTO.getUsername());
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 60 with UserPatch

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

the class RESTITCase method ifMatch.

@Test
public void ifMatch() {
    UserTO userTO = userService.create(UserITCase.getUniqueSampleTO("ifmatch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertNotNull(userTO.getKey());
    EntityTag etag = adminClient.getLatestEntityTag(userService);
    assertNotNull(etag);
    assertTrue(StringUtils.isNotBlank(etag.getValue()));
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "XX").build());
    userTO = userService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertTrue(userTO.getUsername().endsWith("XX"));
    EntityTag etag1 = adminClient.getLatestEntityTag(userService);
    assertFalse(etag.getValue().equals(etag1.getValue()));
    UserService ifMatchService = adminClient.ifMatch(adminClient.getService(UserService.class), etag);
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "YY").build());
    try {
        ifMatchService.update(userPatch);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.ConcurrentModification, e.getType());
    }
    userTO = userService.read(userTO.getKey());
    assertTrue(userTO.getUsername().endsWith("XX"));
}
Also used : GenericType(javax.ws.rs.core.GenericType) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) 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) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) EntityTag(javax.ws.rs.core.EntityTag) 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