use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.
the class GroupITCase method aDynMembership.
@Test
public void aDynMembership() {
String fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").notNullValue().query();
// 1. create group with a given aDynMembership condition
GroupTO group = getBasicSampleTO("aDynMembership");
group.getADynMembershipConds().put("PRINTER", fiql);
group = createGroup(group).getEntity();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
group = groupService.read(group.getKey());
final String groupKey = group.getKey();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
// verify that the condition is dynamically applied
AnyObjectTO newAny = AnyObjectITCase.getSampleTO("aDynMembership");
newAny.getResources().clear();
newAny = createAnyObject(newAny).getEntity();
assertNotNull(newAny.getPlainAttr("location"));
List<MembershipTO> memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
// 2. update group and change aDynMembership condition
fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").nullValue().query();
GroupPatch patch = new GroupPatch();
patch.setKey(group.getKey());
patch.getADynMembershipConds().put("PRINTER", fiql);
group = updateGroup(patch).getEntity();
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
group = groupService.read(group.getKey());
assertEquals(fiql, group.getADynMembershipConds().get("PRINTER"));
// verify that the condition is dynamically applied
AnyObjectPatch anyPatch = new AnyObjectPatch();
anyPatch.setKey(newAny.getKey());
anyPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("location").build()).build());
newAny = updateAnyObject(anyPatch).getEntity();
assertFalse(newAny.getPlainAttr("location").isPresent());
memberships = anyObjectService.read("fc6dbc3a-6c07-4965-8781-921e7401a4a5").getDynMemberships();
assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read("8559d14d-58c2-46eb-a2d4-a7d35161e8f8").getDynMemberships();
assertFalse(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
memberships = anyObjectService.read(newAny.getKey()).getDynMemberships();
assertTrue(memberships.stream().anyMatch(m -> m.getGroupKey().equals(groupKey)));
}
use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.
the class UpdateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
if (actual instanceof UserPatch || isPull()) {
WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks;
if (isPull()) {
boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
} else {
tasks = getPropagationManager().getUserUpdateTasks(updated);
}
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyPatch) {
WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
}
}
}
use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.
the class AnyObjectLogic method link.
@Override
public AnyObjectTO link(final String key, final Collection<String> resources) {
// security checks
AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
AnyObjectPatch patch = new AnyObjectPatch();
patch.setKey(key);
patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
return binder.getAnyObjectTO(provisioningManager.link(patch));
}
use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.
the class AnyObjectLogic method unlink.
@Override
public AnyObjectTO unlink(final String key, final Collection<String> resources) {
// security checks
AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
AnyObjectPatch patch = new AnyObjectPatch();
patch.setKey(key);
patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
return binder.getAnyObjectTO(provisioningManager.unlink(patch));
}
use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.
the class AnyObjectLogic method assign.
@Override
public ProvisioningResult<AnyObjectTO> assign(final String key, final Collection<String> resources, final boolean changepwd, final String password, final boolean nullPriorityAsync) {
// security checks
AnyObjectTO anyObjectTO = binder.getAnyObjectTO(key);
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), anyObjectTO.getRealm());
securityChecks(effectiveRealms, anyObjectTO.getRealm(), anyObjectTO.getKey());
AnyObjectPatch patch = new AnyObjectPatch();
patch.setKey(key);
patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
return update(patch, nullPriorityAsync);
}
Aggregations