use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class GroupITCase method aDynMembershipCount.
@Test
public void aDynMembershipCount() {
// Create a new printer as a dynamic member of a new group
GroupTO group = getBasicSampleTO("aDynamicMembership");
String fiql = SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("home").query();
group.getADynMembershipConds().put("PRINTER", fiql);
group = createGroup(group).getEntity();
AnyObjectTO printer = new AnyObjectTO();
printer.setRealm(SyncopeConstants.ROOT_REALM);
printer.setName("Printer_" + getUUIDString());
printer.setType("PRINTER");
AttrTO location = new AttrTO.Builder().schema("location").value("home").build();
printer.getPlainAttrs().add(location);
printer = createAnyObject(printer).getEntity();
group = groupService.read(group.getKey());
assertEquals(0, group.getStaticAnyObjectMembershipCount());
assertEquals(1, group.getDynamicAnyObjectMembershipCount());
anyObjectService.delete(printer.getKey());
groupService.delete(group.getKey());
}
use of org.apache.syncope.common.lib.to.AnyObjectTO 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.to.AnyObjectTO in project syncope by apache.
the class AnyObjectDirectoryPanel method getActions.
@Override
public ActionsPanel<AnyObjectTO> getActions(final IModel<AnyObjectTO> model) {
final ActionsPanel<AnyObjectTO> panel = super.getActions(model);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new AnyWrapper<>(new AnyObjectRestClient().read(model.getObject().getKey())), target));
}
}, ActionType.EDIT, StringUtils.join(new String[] { AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type) }, ",")).setRealm(realm);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770645L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
final AnyObjectTO clone = SerializationUtils.clone(model.getObject());
clone.setKey(null);
send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new AnyWrapper<>(clone), target));
}
@Override
protected boolean statusCondition(final AnyObjectTO modelObject) {
return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
}
}, ActionType.CLONE, AnyEntitlement.CREATE.getFor(type)).setRealm(realm);
if (wizardInModal) {
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770645L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
final IModel<AnyWrapper<AnyObjectTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
altDefaultModal.setFormModel(formModel);
target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
altDefaultModal.show(true);
}
}, ActionType.MANAGE_RESOURCES, AnyEntitlement.UPDATE.getFor(type)).setRealm(realm);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
utilityModal.show(true);
}
}, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
utilityModal.header(new StringResourceModel("any.notification.tasks", model));
utilityModal.show(true);
target.add(utilityModal);
}
}, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
}
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770646L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
try {
restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
LOG.error("While deleting object {}", model.getObject().getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
@Override
protected boolean statusCondition(final AnyObjectTO modelObject) {
return realm.startsWith(SyncopeConstants.ROOT_REALM);
}
}, ActionType.DELETE, AnyEntitlement.DELETE.getFor(type), true).setRealm(realm);
return panel;
}
use of org.apache.syncope.common.lib.to.AnyObjectTO in project syncope by apache.
the class CreateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (actual instanceof UserTO) {
WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyTO) {
WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
if (actual instanceof GroupTO && isPull()) {
Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
if (groupOwner.isPresent()) {
groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
}
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), null));
} else {
List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
}
}
}
}
use of org.apache.syncope.common.lib.to.AnyObjectTO 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));
}
Aggregations