Search in sources :

Example 46 with UserPatch

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

the class UserLogic method unassign.

@PreAuthorize("hasRole('" + StandardEntitlement.USER_UPDATE + "')")
@Override
public ProvisioningResult<UserTO> unassign(final String key, final Collection<String> resources, final boolean nullPriorityAsync) {
    // security checks
    UserTO user = binder.getUserTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_UPDATE), user.getRealm());
    securityChecks(effectiveRealms, user.getRealm(), user.getKey());
    UserPatch patch = new UserPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
    return update(patch, nullPriorityAsync);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 47 with UserPatch

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

the class UserLogic method unlink.

@PreAuthorize("hasRole('" + StandardEntitlement.USER_UPDATE + "')")
@Override
public UserTO unlink(final String key, final Collection<String> resources) {
    // security checks
    UserTO user = binder.getUserTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_UPDATE), user.getRealm());
    securityChecks(effectiveRealms, user.getRealm(), user.getKey());
    UserPatch patch = new UserPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
    return binder.returnUserTO(binder.getUserTO(provisioningManager.unlink(patch)));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with UserPatch

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

the class UserWorkflowLogic method executeWorkflowTask.

@PreAuthorize("hasRole('" + StandardEntitlement.USER_UPDATE + "')")
public UserTO executeWorkflowTask(final UserTO userTO, final String taskId) {
    WorkflowResult<String> updated = uwfAdapter.execute(userTO, taskId);
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    List<PropagationTaskTO> tasks = propagationManager.getUserUpdateTasks(new WorkflowResult<>(Pair.<UserPatch, Boolean>of(userPatch, null), updated.getPropByRes(), updated.getPerformedTasks()));
    taskExecutor.execute(tasks, false);
    return binder.getUserTO(updated.getResult());
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 49 with UserPatch

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

the class DefaultUserPullResultHandler method doUpdate.

@Override
protected AnyPatch doUpdate(final AnyTO before, final AnyPatch anyPatch, final SyncDelta delta, final ProvisioningReport result) {
    UserPatch userPatch = UserPatch.class.cast(anyPatch);
    Boolean enabled = pullUtils.readEnabled(delta.getObject(), profile.getTask());
    Pair<UserPatch, List<PropagationStatus>> updated = userProvisioningManager.update(userPatch, result, enabled, Collections.singleton(profile.getTask().getResource().getKey()), true);
    return updated.getLeft();
}
Also used : List(java.util.List) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 50 with UserPatch

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

the class MembershipITCase method misc.

@Test
public void misc() {
    UserTO user = UserITCase.getUniqueSampleTO("memb@apache.org");
    user.setRealm("/even/two");
    user.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1976").build());
    user.getPlainAttrs().remove(user.getPlainAttr("ctype").get());
    // the group 034740a9-fa10-453b-af37-dc7897e98fb1 has USER type extensions for 'csv' and 'other'
    // any type classes
    MembershipTO membership = new MembershipTO.Builder().group("034740a9-fa10-453b-af37-dc7897e98fb1").build();
    membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1977").build());
    // 'fullname' is in 'minimal user', so it is not allowed for this membership
    membership.getPlainAttrs().add(new AttrTO.Builder().schema("fullname").value("discarded").build());
    user.getMemberships().add(membership);
    // user creation fails because of fullname
    try {
        createUser(user);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.InvalidUser, e.getType());
        assertTrue(e.getMessage().contains("InvalidPlainAttr: fullname not allowed for membership of group"));
    }
    // remove fullname and try again
    membership.getPlainAttrs().remove(membership.getPlainAttr("fullname").get());
    try {
        user = createUser(user).getEntity();
        // 1. verify that 'aLong' is correctly populated for user
        assertEquals(1, user.getPlainAttr("aLong").get().getValues().size());
        assertEquals("1976", user.getPlainAttr("aLong").get().getValues().get(0));
        // 2. verify that 'aLong' is correctly populated for user's membership
        assertEquals(1, user.getMemberships().size());
        membership = user.getMembership("034740a9-fa10-453b-af37-dc7897e98fb1").get();
        assertNotNull(membership);
        assertEquals(1, membership.getPlainAttr("aLong").get().getValues().size());
        assertEquals("1977", membership.getPlainAttr("aLong").get().getValues().get(0));
        // 3. verify that derived attrbutes from 'csv' and 'other' are also populated for user's membership
        assertFalse(membership.getDerAttr("csvuserid").get().getValues().isEmpty());
        assertFalse(membership.getDerAttr("noschema").get().getValues().isEmpty());
        // update user - change some values and add new membership attribute
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(user.getKey());
        userPatch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(new AttrTO.Builder().schema("aLong").value("1977").build()).build());
        MembershipPatch membershipPatch = new MembershipPatch.Builder().group(membership.getGroupKey()).build();
        membershipPatch.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("1976").build());
        membershipPatch.getPlainAttrs().add(new AttrTO.Builder().schema("ctype").value("membership type").build());
        userPatch.getMemberships().add(membershipPatch);
        user = updateUser(userPatch).getEntity();
        // 4. verify that 'aLong' is correctly populated for user
        assertEquals(1, user.getPlainAttr("aLong").get().getValues().size());
        assertEquals("1977", user.getPlainAttr("aLong").get().getValues().get(0));
        assertFalse(user.getPlainAttr("ctype").isPresent());
        // 5. verify that 'aLong' is correctly populated for user's membership
        assertEquals(1, user.getMemberships().size());
        membership = user.getMembership("034740a9-fa10-453b-af37-dc7897e98fb1").get();
        assertNotNull(membership);
        assertEquals(1, membership.getPlainAttr("aLong").get().getValues().size());
        assertEquals("1976", membership.getPlainAttr("aLong").get().getValues().get(0));
        // 6. verify that 'ctype' is correctly populated for user's membership
        assertEquals("membership type", membership.getPlainAttr("ctype").get().getValues().get(0));
        // finally remove membership
        userPatch = new UserPatch();
        userPatch.setKey(user.getKey());
        membershipPatch = new MembershipPatch.Builder().group(membership.getGroupKey()).operation(PatchOperation.DELETE).build();
        userPatch.getMemberships().add(membershipPatch);
        user = updateUser(userPatch).getEntity();
        assertTrue(user.getMemberships().isEmpty());
    } finally {
        if (user.getKey() != null) {
            userService.delete(user.getKey());
        }
    }
}
Also used : MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) 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