Search in sources :

Example 16 with PropagationStatus

use of org.apache.syncope.common.lib.to.PropagationStatus in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE136AES.

@Test
public void issueSYNCOPE136AES() {
    // 1. read configured cipher algorithm in order to be able to restore it at the end of test
    AttrTO pwdCipherAlgo = configurationService.get("password.cipher.algorithm");
    String origpwdCipherAlgo = pwdCipherAlgo.getValues().get(0);
    // 2. set AES password cipher algorithm
    pwdCipherAlgo.getValues().set(0, "AES");
    configurationService.set(pwdCipherAlgo);
    UserTO userTO = null;
    try {
        // 3. create user with no resources
        userTO = UserITCase.getUniqueSampleTO("syncope136_AES@apache.org");
        userTO.getResources().clear();
        userTO = createUser(userTO).getEntity();
        assertNotNull(userTO);
        // 4. update user, assign a propagation priority resource but don't provide any password
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(userTO.getKey());
        userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_LDAP).build());
        userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_LDAP).build());
        ProvisioningResult<UserTO> result = updateUser(userPatch);
        assertNotNull(result);
        userTO = result.getEntity();
        assertNotNull(userTO);
        // 5. verify that propagation was successful
        List<PropagationStatus> props = result.getPropagationStatuses();
        assertNotNull(props);
        assertEquals(1, props.size());
        PropagationStatus prop = props.iterator().next();
        assertNotNull(prop);
        assertEquals(RESOURCE_NAME_LDAP, prop.getResource());
        assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
    } finally {
        // restore initial cipher algorithm
        pwdCipherAlgo.getValues().set(0, origpwdCipherAlgo);
        configurationService.set(pwdCipherAlgo);
        if (userTO != null) {
            deleteUser(userTO.getKey());
        }
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 17 with PropagationStatus

use of org.apache.syncope.common.lib.to.PropagationStatus in project syncope by apache.

the class Realm method customResultBody.

@Override
@SuppressWarnings("unchecked")
protected Panel customResultBody(final String panelId, final RealmTO item, final Serializable result) {
    if (!(result instanceof ProvisioningResult)) {
        throw new IllegalStateException("Unsupported result type");
    }
    final MultilevelPanel mlp = new MultilevelPanel(panelId);
    add(mlp);
    final PropagationStatus syncope = new PropagationStatus();
    syncope.setStatus(PropagationTaskExecStatus.SUCCESS);
    syncope.setResource(Constants.SYNCOPE);
    ArrayList<PropagationStatus> propagations = new ArrayList<>();
    propagations.add(syncope);
    propagations.addAll(((ProvisioningResult) result).getPropagationStatuses());
    ListViewPanel.Builder<PropagationStatus> builder = new ListViewPanel.Builder<PropagationStatus>(PropagationStatus.class, pageRef) {

        private static final long serialVersionUID = -6809736686861678498L;

        @Override
        protected Component getValueComponent(final String key, final PropagationStatus bean) {
            if ("afterObj".equalsIgnoreCase(key)) {
                ConnObjectTO afterObj = bean.getAfterObj();
                String remoteId = afterObj == null || afterObj.getAttrs().isEmpty() || !afterObj.getAttr(ConnIdSpecialName.NAME).isPresent() || afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues() == null || afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues().isEmpty() ? StringUtils.EMPTY : afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0);
                return new Label("field", remoteId);
            } else if ("status".equalsIgnoreCase(key)) {
                return StatusUtils.getStatusImagePanel("field", bean.getStatus());
            } else {
                return super.getValueComponent(key, bean);
            }
        }
    };
    builder.setItems(propagations);
    builder.includes("resource", "afterObj", "status");
    builder.withChecks(ListViewPanel.CheckAvailability.NONE);
    builder.setReuseItem(false);
    builder.addAction(new ActionLink<PropagationStatus>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        protected boolean statusCondition(final PropagationStatus bean) {
            return !Constants.SYNCOPE.equals(bean.getResource()) && (PropagationTaskExecStatus.CREATED == bean.getStatus() || PropagationTaskExecStatus.SUCCESS == bean.getStatus());
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final PropagationStatus bean) {
            mlp.next(bean.getResource(), new RemoteRealmPanel(bean), target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
    mlp.setFirstLevel(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
    return mlp;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO)

Example 18 with PropagationStatus

use of org.apache.syncope.common.lib.to.PropagationStatus in project syncope by apache.

the class UserRestClient method reactivate.

public BulkActionResult reactivate(final String etag, final String userKey, final List<StatusBean> statuses) {
    StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses, true);
    statusPatch.setKey(userKey);
    statusPatch.setType(StatusPatchType.REACTIVATE);
    BulkActionResult result;
    synchronized (this) {
        result = new BulkActionResult();
        Map<String, BulkActionResult.Status> res = result.getResults();
        UserService service = getService(etag, UserService.class);
        @SuppressWarnings("unchecked") ProvisioningResult<UserTO> provisions = (ProvisioningResult<UserTO>) service.status(statusPatch).readEntity(ProvisioningResult.class);
        if (statusPatch.isOnSyncope()) {
            res.put(StringUtils.capitalize(Constants.SYNCOPE), "active".equalsIgnoreCase(provisions.getEntity().getStatus()) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
        }
        for (PropagationStatus status : provisions.getPropagationStatuses()) {
            res.put(status.getResource(), BulkActionResult.Status.valueOf(status.getStatus().name()));
        }
        resetClient(UserService.class);
    }
    return result;
}
Also used : PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserService(org.apache.syncope.common.rest.api.service.UserService) UserTO(org.apache.syncope.common.lib.to.UserTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StatusPatch(org.apache.syncope.common.lib.patch.StatusPatch) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult)

Example 19 with PropagationStatus

use of org.apache.syncope.common.lib.to.PropagationStatus in project syncope by apache.

the class UserLogic method doDelete.

protected ProvisioningResult<UserTO> doDelete(final UserTO userTO, final boolean self, final boolean nullPriorityAsync) {
    Pair<UserTO, List<LogicActions>> before = beforeDelete(userTO);
    if (!self) {
        Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_DELETE), before.getLeft().getRealm());
        securityChecks(effectiveRealms, before.getLeft().getRealm(), before.getLeft().getKey());
    }
    List<Group> ownedGroups = groupDAO.findOwnedByUser(before.getLeft().getKey());
    if (!ownedGroups.isEmpty()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.GroupOwnership);
        sce.getElements().addAll(ownedGroups.stream().map(group -> group.getKey() + " " + group.getName()).collect(Collectors.toList()));
        throw sce;
    }
    List<PropagationStatus> statuses = provisioningManager.delete(before.getLeft().getKey(), nullPriorityAsync);
    UserTO deletedTO;
    if (userDAO.find(before.getLeft().getKey()) == null) {
        deletedTO = new UserTO();
        deletedTO.setKey(before.getLeft().getKey());
    } else {
        deletedTO = binder.getUserTO(before.getLeft().getKey());
    }
    return afterDelete(binder.returnUserTO(deletedTO), statuses, before.getRight());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) List(java.util.List)

Example 20 with PropagationStatus

use of org.apache.syncope.common.lib.to.PropagationStatus 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

PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)24 UserTO (org.apache.syncope.common.lib.to.UserTO)12 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)11 Test (org.junit.jupiter.api.Test)9 GroupTO (org.apache.syncope.common.lib.to.GroupTO)7 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 List (java.util.List)4 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)3 Group (org.apache.syncope.core.persistence.api.entity.group.Group)3 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)2 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)2 AttrTO (org.apache.syncope.common.lib.to.AttrTO)2 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)2 UserService (org.apache.syncope.common.rest.api.service.UserService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1