Search in sources :

Example 81 with GroupTO

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);
}
Also used : Status(org.apache.syncope.client.console.commons.status.Status) ArrayList(java.util.ArrayList) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) MultilevelPanel(org.apache.syncope.client.console.panels.MultilevelPanel) StatusBean(org.apache.syncope.client.console.commons.status.StatusBean) UserTO(org.apache.syncope.common.lib.to.UserTO) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ConnObjectWrapper(org.apache.syncope.client.console.commons.status.ConnObjectWrapper) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 82 with GroupTO

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;
}
Also used : GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 83 with GroupTO

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;
}
Also used : AbstractResource(org.apache.wicket.request.resource.AbstractResource) IOException(java.io.IOException) IOException(java.io.IOException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringValue(org.apache.wicket.util.string.StringValue)

Example 84 with GroupTO

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);
    }
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AnyTO(org.apache.syncope.common.lib.to.AnyTO) AnySelectionDirectoryPanel(org.apache.syncope.client.console.panels.search.AnySelectionDirectoryPanel) UserTO(org.apache.syncope.common.lib.to.UserTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 85 with GroupTO

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());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) List(java.util.List) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9