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);
}
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)));
}
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());
}
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();
}
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());
}
}
}
Aggregations