use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class StatusPanel method init.
private void init(final AnyTO any, final IModel<List<StatusBean>> model, final List<Pair<ConnObjectTO, ConnObjectWrapper>> connObjects, final PageReference pageRef, final boolean enableConnObjectLink) {
final List<StatusBean> statusBeans = new ArrayList<>(connObjects.size() + 1);
initialStatusBeanMap = new LinkedHashMap<>(connObjects.size() + 1);
final StatusBean syncope = new StatusBean(any, Constants.SYNCOPE);
if (any instanceof UserTO) {
syncope.setConnObjectLink(((UserTO) any).getUsername());
Status syncopeStatus = Status.UNDEFINED;
if (((UserTO) any).getStatus() != null) {
try {
syncopeStatus = Status.valueOf(((UserTO) any).getStatus().toUpperCase());
} catch (IllegalArgumentException e) {
LOG.warn("Unexpected status found: {}", ((UserTO) any).getStatus(), e);
}
}
syncope.setStatus(syncopeStatus);
} else if (any instanceof GroupTO) {
syncope.setConnObjectLink(((GroupTO) any).getName());
syncope.setStatus(Status.ACTIVE);
}
statusBeans.add(syncope);
initialStatusBeanMap.put(syncope.getResource(), syncope);
connObjects.forEach(pair -> {
ConnObjectWrapper entry = pair.getRight();
final StatusBean statusBean = statusUtils.getStatusBean(entry.getAny(), entry.getResourceName(), entry.getConnObjectTO(), any instanceof GroupTO);
initialStatusBeanMap.put(entry.getResourceName(), statusBean);
statusBeans.add(statusBean);
});
final MultilevelPanel mlp = new MultilevelPanel("resources");
add(mlp);
ListViewPanel.Builder<StatusBean> builder = new ListViewPanel.Builder<StatusBean>(StatusBean.class, pageRef) {
private static final long serialVersionUID = -6809736686861678498L;
@Override
protected Component getValueComponent(final String key, final StatusBean bean) {
if ("status".equalsIgnoreCase(key)) {
return StatusUtils.getStatusImagePanel("field", bean.getStatus());
} else {
return super.getValueComponent(key, bean);
}
}
};
builder.setModel(model);
builder.setItems(statusBeans);
builder.includes("resource", "connObjectLink", "status");
builder.withChecks(ListViewPanel.CheckAvailability.NONE);
builder.setReuseItem(false);
final ActionLink<StatusBean> connObjectLink = new ActionLink<StatusBean>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
protected boolean statusCondition(final StatusBean bean) {
final Pair<ConnObjectTO, ConnObjectTO> pair = getConnObjectTO(bean.getKey(), bean.getResource(), connObjects);
return pair != null && pair.getRight() != null;
}
@Override
public void onClick(final AjaxRequestTarget target, final StatusBean bean) {
mlp.next(bean.getResource(), new RemoteAnyPanel(bean, connObjects), target);
}
};
if (!enableConnObjectLink) {
connObjectLink.disable();
}
builder.addAction(connObjectLink, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
listViewPanel = ListViewPanel.class.cast(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
mlp.setFirstLevel(listViewPanel);
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupWizardBuilder method onApplyInternal.
@Override
protected Serializable onApplyInternal(final AnyWrapper<GroupTO> modelObject) {
GroupTO inner = modelObject instanceof GroupWrapper ? GroupWrapper.class.cast(modelObject).fillDynamicConditions() : modelObject.getInnerObject();
ProvisioningResult<GroupTO> actual;
if (inner.getKey() == null) {
actual = groupRestClient.create(inner);
} else {
GroupPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
GroupTO originaObj = getOriginalItem().getInnerObject();
// SYNCOPE-1170
boolean othersNotEqualsOrBlanks = !inner.getADynMembershipConds().equals(originaObj.getADynMembershipConds()) || (StringUtils.isNotBlank(originaObj.getUDynMembershipCond()) && StringUtils.isBlank(inner.getUDynMembershipCond())) || (StringUtils.isBlank(originaObj.getUDynMembershipCond()) && StringUtils.isNotBlank(inner.getUDynMembershipCond())) || StringUtils.isAllBlank(originaObj.getUDynMembershipCond(), inner.getUDynMembershipCond()) || !inner.getUDynMembershipCond().equals(originaObj.getUDynMembershipCond()) || !CollectionUtils.diff(inner.getTypeExtensions(), originaObj.getTypeExtensions()).isEmpty();
// update just if it is changed
if (patch.isEmpty() && !othersNotEqualsOrBlanks) {
actual = new ProvisioningResult<>();
actual.setEntity(inner);
} else {
actual = groupRestClient.update(getOriginalItem().getInnerObject().getETagValue(), patch);
}
}
return actual;
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
LOG.debug("Search all available groups");
ResourceResponse response = new ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN does not match");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
return response;
}
String realm = URLDecoder.decode(attributes.getParameters().get("realm").toString(SyncopeConstants.ROOT_REALM), "UTF-8");
StringValue term = attributes.getParameters().get("term");
final GroupResponse groupResponse = new GroupResponse();
final int totGroups = SyncopeEnduserSession.get().getService(SyncopeService.class).numbers().getTotalGroups();
final List<GroupTO> groupTOs = SyncopeEnduserSession.get().getService(SyncopeService.class).searchAssignableGroups(realm, term.isNull() || term.isEmpty() ? null : URLDecoder.decode(term.toString(), "UTF-8"), 1, 30).getResult();
groupResponse.setTotGroups(totGroups);
groupResponse.setGroupTOs(groupTOs.stream().collect(Collectors.toMap(GroupTO::getKey, GroupTO::getName)));
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(groupResponse));
}
});
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving available groups", e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
}
return response;
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class Ownership method onEvent.
@Override
public void onEvent(final IEvent<?> event) {
if (event.getPayload() instanceof SearchClausePanel.SearchEvent) {
final AjaxRequestTarget target = SearchClausePanel.SearchEvent.class.cast(event.getPayload()).getTarget();
if (Ownership.this.isGroupOwnership.getObject()) {
final String fiql = SearchUtils.buildFIQL(groupSearchPanel.getModel().getObject(), SyncopeClient.getGroupSearchConditionBuilder());
groupDirectoryPanel.search(fiql, target);
} else {
final String fiql = SearchUtils.buildFIQL(userSearchPanel.getModel().getObject(), SyncopeClient.getUserSearchConditionBuilder());
userDirectoryPanel.search(fiql, target);
}
} else if (event.getPayload() instanceof AnySelectionDirectoryPanel.ItemSelection) {
final AnyTO sel = ((AnySelectionDirectoryPanel.ItemSelection) event.getPayload()).getSelection();
if (sel == null) {
wrapper.getInnerObject().setUserOwner(null);
wrapper.getInnerObject().setGroupOwner(null);
} else if (sel instanceof UserTO) {
wrapper.getInnerObject().setUserOwner(sel.getKey());
wrapper.getInnerObject().setGroupOwner(null);
} else if (sel instanceof GroupTO) {
wrapper.getInnerObject().setGroupOwner(sel.getKey());
wrapper.getInnerObject().setUserOwner(null);
}
((AnySelectionDirectoryPanel.ItemSelection) event.getPayload()).getTarget().add(ownerContainer);
} else {
super.onEvent(event);
}
}
use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.
the class GroupLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_DELETE + "')")
@Override
public ProvisioningResult<GroupTO> delete(final String key, final boolean nullPriorityAsync) {
GroupTO group = binder.getGroupTO(key);
Pair<GroupTO, List<LogicActions>> before = beforeDelete(group);
Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_DELETE), before.getLeft().getRealm());
securityChecks(effectiveRealms, before.getLeft().getRealm(), before.getLeft().getKey());
List<Group> ownedGroups = groupDAO.findOwnedByGroup(before.getLeft().getKey());
if (!ownedGroups.isEmpty()) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.GroupOwnership);
sce.getElements().addAll(ownedGroups.stream().map(g -> g.getKey() + " " + g.getName()).collect(Collectors.toList()));
throw sce;
}
List<PropagationStatus> statuses = provisioningManager.delete(before.getLeft().getKey(), nullPriorityAsync);
GroupTO groupTO = new GroupTO();
groupTO.setKey(before.getLeft().getKey());
return afterDelete(groupTO, statuses, before.getRight());
}
Aggregations