Package org.apache.syncope.client.mod

Examples of org.apache.syncope.client.mod.UserMod


        final UserTO updatedUserTO = (UserTO) form.getModelObject();

        if (updatedUserTO.getId() == 0) {
            userTO = userRestClient.create(updatedUserTO);
        } else {
            final UserMod userMod = AttributableOperations.diff(updatedUserTO, initialUserTO);

            // update user just if it is changed
            if (!userMod.isEmpty()) {
                userTO = userRestClient.update(userMod);
            }
        }

    }
View Full Code Here


public class Update extends AbstractActivitiDelegate {

    @Override
    protected void doExecute(final DelegateExecution execution) throws Exception {
        SyncopeUser user = (SyncopeUser) execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER);
        UserMod userMod = (UserMod) execution.getVariable(ActivitiUserWorkflowAdapter.USER_MOD);

        // update SyncopeUser
        PropagationByResource propByRes = dataBinder.update(user, userMod);

        // report updated user and propagation by resource as result
View Full Code Here

     * @param original original UserTO
     * @param incremental perform incremental diff (without removing existing info)
     * @return UserMod containing differences
     */
    public static UserMod diff(final UserTO updated, final UserTO original, boolean incremental) {
        UserMod result = new UserMod();

        diff(updated, original, result, incremental);

        // 1. password
        if (original.getPassword() != null && !original.getPassword().equals(updated.getPassword())) {

            result.setPassword(updated.getPassword());
        }

        // 2. username
        if (original.getUsername() != null && !original.getUsername().equals(updated.getUsername())) {

            result.setUsername(updated.getUsername());
        }

        // 3. memberships
        Map<Long, MembershipTO> updatedMembs = updated.getMembershipMap();
        Map<Long, MembershipTO> originalMembs = original.getMembershipMap();

        for (Map.Entry<Long, MembershipTO> entry : updatedMembs.entrySet()) {
            MembershipMod membMod = new MembershipMod();
            membMod.setRole(entry.getValue().getRoleId());

            if (originalMembs.containsKey(entry.getKey())) {
                diff(entry.getValue(), originalMembs.get(entry.getKey()), membMod, false);
            } else {
                for (AttributeTO attr : entry.getValue().getAttributes()) {

                    AttributeMod attrMod = new AttributeMod();
                    attrMod.setSchema(attr.getSchema());
                    attrMod.setValuesToBeAdded(attr.getValues());

                    if (!attrMod.isEmpty()) {
                        membMod.addAttributeToBeUpdated(attrMod);
                        membMod.addAttributeToBeRemoved(attrMod.getSchema());
                    }
                }
                for (AttributeTO attr : entry.getValue().getDerivedAttributes()) {

                    membMod.addDerivedAttributeToBeAdded(attr.getSchema());
                }
                for (AttributeTO attr : entry.getValue().getVirtualAttributes()) {

                    AttributeMod attrMod = new AttributeMod();
                    attrMod.setSchema(attr.getSchema());
                    attrMod.setValuesToBeAdded(attr.getValues());

                    if (!attrMod.isEmpty()) {
                        membMod.addVirtualAttributeToBeUpdated(attrMod);
                        membMod.addAttributeToBeRemoved(attrMod.getSchema());
                    }
                }
                membMod.setResourcesToBeAdded(entry.getValue().getResources());
            }

            if (!membMod.isEmpty()) {
                result.addMembershipToBeAdded(membMod);
            }
        }

        if (!incremental) {
            Set<Long> originalRoles = new HashSet<Long>(originalMembs.keySet());
            originalRoles.removeAll(updatedMembs.keySet());
            for (Long roleId : originalRoles) {
                result.addMembershipToBeRemoved(originalMembs.get(roleId).getId());
            }
        }

        return result;
    }
View Full Code Here

            }
        } else {
            final UserTO originalUserTO = mode == Mode.SELF
                    ? userRestClient.read(updatedUserTO.getUsername())
                    : userRestClient.read(updatedUserTO.getId());
            final UserMod userMod = AttributableOperations.diff(updatedUserTO, originalUserTO);

            // update user only if it has changed
            if (!userMod.isEmpty()) {
                switch (mode) {
                    case SELF:
                        requestRestClient.requestUpdate(userMod);
                        break;
View Full Code Here

            if (memb != null) {
                membTO.setId(memb.getId());
            }
        }

        final UserMod userMod = AttributableOperations.diff(updated, original, true);

        return userMod;
    }
View Full Code Here

    private void updateUser(final Long userId, SyncDelta delta, final boolean dryRun, final SyncResult result)
            throws Exception {

        UserTO userTO = userDataBinder.getUserTO(userId);
        UserMod userMod = connObjectUtil.getUserMod(userId, delta.getObject(), (SyncTask) task);

        delta = actions.beforeUpdate(delta, userTO, userMod);

        if (dryRun) {
            return;
        }

        WorkflowResult<Map.Entry<Long, Boolean>> updated;
        try {
            updated = wfAdapter.update(userMod);
        } catch (Exception e) {
            LOG.error("Update of user {} failed, trying to sync its status anyway (if configured)", userId, e);

            result.setStatus(Status.FAILURE);
            result.setMessage("Update failed, trying to sync status anyway (if configured)\n" + e.getMessage());

            updated = new WorkflowResult<Map.Entry<Long, Boolean>>(
                    new SimpleEntry<Long, Boolean>(userId, false), new PropagationByResource(), new HashSet<String>());
        }

        Boolean enabled = readEnabled(delta.getObject());
        if (enabled != null) {
            WorkflowResult<Long> enableUpdate = null;

            SyncopeUser user = userDAO.find(userId);
            enableUpdate = user.isSuspended() == null
                    ? wfAdapter.activate(userId, null)
                    : enabled
                    ? wfAdapter.reactivate(userId)
                    : wfAdapter.suspend(userId);

            if (enableUpdate != null) {
                if (enableUpdate.getPropByRes() != null) {
                    updated.getPropByRes().merge(enableUpdate.getPropByRes());
                    updated.getPropByRes().purge();
                }
                updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
            }
        }

        List<PropagationTask> tasks = propagationManager.getUpdateTaskIds(updated,
                userMod.getPassword(),
                userMod.getVirtualAttributesToBeRemoved(),
                userMod.getVirtualAttributesToBeUpdated(),
                Collections.singleton(((SyncTask) this.task).getResource().getName()));

        propagationManager.execute(tasks);

        notificationManager.createTasks(new WorkflowResult<Long>(updated.getResult().getKey(),
View Full Code Here

        membershipTO.addAttribute(membershipAttr);
        userTO.addMembership(membershipTO);

        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);

        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.setPassword("newPassword");

        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);

        // check for changePwdDate
        assertNotNull(userTO.getChangePwdDate());
View Full Code Here

        assertEquals(newMaxId, maxId);

        // --------------------------------------
        // Update operation
        // --------------------------------------
        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());

        AttributeMod attributeMod = new AttributeMod();
        attributeMod.setSchema("surname");
        attributeMod.addValueToBeAdded("surname");
        userMod.addAttributeToBeUpdated(attributeMod);

        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);

        assertNotNull(userTO);
View Full Code Here

        AttributeTO loginDate = userTO.getAttributeMap().get("loginDate");
        assertNotNull(loginDate);
        assertEquals(1, loginDate.getValues().size());

        UserMod userMod = new UserMod();

        AttributeMod loginDateMod = new AttributeMod();
        loginDateMod.addValueToBeAdded("2000-01-01");

        userMod.setId(userTO.getId());
        userMod.addAttributeToBeUpdated(loginDateMod);

        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
        assertNotNull(userTO);

        loginDate = userTO.getAttributeMap().get("loginDate");
View Full Code Here

        String username =
                jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class, userTO.getUsername());

        assertEquals(userTO.getUsername(), username);

        UserMod userMod = new UserMod();

        userMod.setId(userTO.getId());
        userMod.addResourceToBeRemoved("resource-testdb");

        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);

        assertTrue(userTO.getResources().isEmpty());
View Full Code Here

TOP

Related Classes of org.apache.syncope.client.mod.UserMod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.