use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class AnyOperations method patch.
public static AnyObjectTO patch(final AnyObjectTO anyObjectTO, final AnyObjectPatch anyObjectPatch) {
AnyObjectTO result = SerializationUtils.clone(anyObjectTO);
patch(anyObjectTO, anyObjectPatch, result);
if (anyObjectPatch.getName() != null) {
result.setName(anyObjectPatch.getName().getValue());
}
// 1. relationships
anyObjectPatch.getRelationships().forEach(relPatch -> {
if (relPatch.getRelationshipTO() == null) {
LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
} else {
result.getRelationships().remove(relPatch.getRelationshipTO());
if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
result.getRelationships().add(relPatch.getRelationshipTO());
}
}
});
// 2. memberships
anyObjectPatch.getMemberships().forEach(membPatch -> {
if (membPatch.getGroup() == null) {
LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
} else {
Optional<MembershipTO> memb = result.getMemberships().stream().filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
if (memb.isPresent()) {
result.getMemberships().remove(memb.get());
}
if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
// 3. plain attributes
newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
// 4. virtual attributes
newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
result.getMemberships().add(newMembershipTO);
}
}
});
return result;
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class AnyObjectLogic method delete.
@Override
public ProvisioningResult<AnyObjectTO> delete(final String key, final boolean nullPriorityAsync) {
AnyObjectTO anyObject = binder.getAnyObjectTO(key);
Pair<AnyObjectTO, List<LogicActions>> before = beforeDelete(anyObject);
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.DELETE.getFor(before.getLeft().getType())), before.getLeft().getRealm());
securityChecks(effectiveRealms, before.getLeft().getRealm(), before.getLeft().getKey());
List<PropagationStatus> statuses = provisioningManager.delete(before.getLeft().getKey(), nullPriorityAsync);
AnyObjectTO anyObjectTO = new AnyObjectTO();
anyObjectTO.setKey(before.getLeft().getKey());
return afterDelete(anyObjectTO, statuses, before.getRight());
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class AnyObjectLogic method update.
@Override
public ProvisioningResult<AnyObjectTO> update(final AnyObjectPatch anyObjectPatch, final boolean nullPriorityAsync) {
AnyObjectTO anyObjectTO = binder.getAnyObjectTO(anyObjectPatch.getKey());
Set<String> dynRealmsBefore = new HashSet<>(anyObjectTO.getDynRealms());
Pair<AnyObjectPatch, List<LogicActions>> before = beforeUpdate(anyObjectPatch, anyObjectTO.getRealm());
String realm = before.getLeft().getRealm() != null && StringUtils.isNotBlank(before.getLeft().getRealm().getValue()) ? before.getLeft().getRealm().getValue() : anyObjectTO.getRealm();
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(AnyEntitlement.UPDATE.getFor(anyObjectTO.getType())), realm);
boolean authDynRealms = securityChecks(effectiveRealms, realm, before.getLeft().getKey());
Pair<AnyObjectPatch, List<PropagationStatus>> updated = provisioningManager.update(anyObjectPatch, nullPriorityAsync);
return afterUpdate(binder.getAnyObjectTO(updated.getLeft().getKey()), updated.getRight(), before.getRight(), authDynRealms, dynRealmsBefore);
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class AnyObjectLogic method unassign.
@Override
public ProvisioningResult<AnyObjectTO> unassign(final String key, final Collection<String> resources, 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.DELETE).value(resource).build()).collect(Collectors.toList()));
return update(patch, nullPriorityAsync);
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class AnyOperationsTest method mindiff.
@Test
public void mindiff() {
AnyObjectTO oldOne = new AnyObjectTO();
oldOne.setName("name");
oldOne.getPlainAttrs().add(new AttrTO.Builder().schema("plain").value("oldValue").build());
oldOne.getPlainAttrs().add(new AttrTO.Builder().schema("encrypted").value("oldValue").build());
AnyObjectTO newOne = new AnyObjectTO();
newOne.setName("name");
newOne.getPlainAttrs().add(new AttrTO.Builder().schema("plain").value("newValue").build());
newOne.getPlainAttrs().add(new AttrTO.Builder().schema("encrypted").value("oldValue").build());
AnyObjectPatch diff = AnyOperations.diff(newOne, oldOne, true);
assertEquals(1, diff.getPlainAttrs().size());
AttrPatch patch = diff.getPlainAttrs().iterator().next();
assertEquals(PatchOperation.ADD_REPLACE, patch.getOperation());
assertEquals("plain", patch.getAttrTO().getSchema());
}
Aggregations