Package org.apache.syncope.common.mod

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


        // 2. check for virtual attribute value
        actual = userService.read(actual.getId());
        assertNotNull(actual);
        assertEquals("virtualvalue", actual.getVirtualAttributeMap().get("virtualdata").getValues().get(0));

        UserMod userMod = new UserMod();
        userMod.setId(actual.getId());
        userMod.addVirtualAttributeToBeRemoved("virtualdata");
        userMod.addVirtualAttributeToBeUpdated(attributeMod("virtualdata", "virtualupdated"));

        // 3. update virtual attribute
        actual = userService.update(userMod.getId(), userMod);
        assertNotNull(actual);

        // 4. check for virtual attribute value
        actual = userService.read(actual.getId());
        assertNotNull(actual);
View Full Code Here


        // ----------------------------------

        // ----------------------------------
        // update user virtual attribute and check virtual attribute value update propagation
        // ----------------------------------
        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());

        AttributeMod attrMod = new AttributeMod();
        attrMod.setSchema("virtualdata");
        attrMod.addValueToBeRemoved("virtualvalue");
        attrMod.addValueToBeAdded("virtualvalue2");

        userMod.addVirtualAttributeToBeUpdated(attrMod);

        userTO = userService.update(userMod.getId(), userMod);
        assertNotNull(userTO);
        assertFalse(userTO.getPropagationStatusTOs().isEmpty());
        assertEquals(RESOURCE_NAME_WS2, userTO.getPropagationStatusTOs().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationStatusTOs().get(0).getStatus());

        connObjectTO = readConnectorObject(RESOURCE_NAME_WS2, userTO.getId(), AttributableType.USER);
        assertNotNull(connObjectTO);
        assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
        // ----------------------------------

        // ----------------------------------
        // suspend/reactivate user and check virtual attribute value (unchanged)
        // ----------------------------------
        userTO = userService.suspend(userTO.getId());
        assertEquals("suspended", userTO.getStatus());

        connObjectTO = readConnectorObject(RESOURCE_NAME_WS2, userTO.getId(), AttributableType.USER);
        assertNotNull(connObjectTO);
        assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
        assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));

        userTO = userService.reactivate(userTO.getId());
        assertEquals("active", userTO.getStatus());

        connObjectTO = readConnectorObject(RESOURCE_NAME_WS2, userTO.getId(), AttributableType.USER);
        assertNotNull(connObjectTO);
        assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
        assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
        // ----------------------------------

        // ----------------------------------
        // update user attribute and check virtual attribute value (unchanged)
        // ----------------------------------
        userMod = new UserMod();
        userMod.setId(userTO.getId());

        attrMod = new AttributeMod();
        attrMod.setSchema("surname");
        attrMod.addValueToBeRemoved("Surname");
        attrMod.addValueToBeAdded("Surname2");

        userMod.addAttributeToBeUpdated(attrMod);

        userTO = userService.update(userMod.getId(), userMod);
        assertNotNull(userTO);
        assertFalse(userTO.getPropagationStatusTOs().isEmpty());
        assertEquals(RESOURCE_NAME_WS2, userTO.getPropagationStatusTOs().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationStatusTOs().get(0).getStatus());

        connObjectTO = readConnectorObject(RESOURCE_NAME_WS2, userTO.getId(), AttributableType.USER);
        assertNotNull(connObjectTO);
        assertEquals("Surname2", connObjectTO.getAttributeMap().get("SURNAME").getValues().get(0));

        // attribute "name" mapped on virtual attribute "virtualdata" shouldn't be changed
        assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
        assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
        // ----------------------------------

        // ----------------------------------
        // remove user virtual attribute and check virtual attribute value (reset)
        // ----------------------------------
        userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.addVirtualAttributeToBeRemoved("virtualdata");

        userTO = userService.update(userMod.getId(), userMod);
        assertNotNull(userTO);
        assertTrue(userTO.getVirtualAttributes().isEmpty());
        assertFalse(userTO.getPropagationStatusTOs().isEmpty());
        assertEquals(RESOURCE_NAME_WS2, userTO.getPropagationStatusTOs().get(0).getResource());
        assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationStatusTOs().get(0).getStatus());
View Full Code Here

        // 4. check for cached attribute value
        actual = userService.read(actual.getId());
        assertEquals("virattrcache", actual.getVirtualAttributeMap().get("virtualdata").getValues().get(0));

        UserMod userMod = new UserMod();
        userMod.setId(actual.getId());

        AttributeMod virtualdata = new AttributeMod();
        virtualdata.setSchema("virtualdata");
        virtualdata.addValueToBeAdded("virtualupdated");

        userMod.addVirtualAttributeToBeRemoved("virtualdata");
        userMod.addVirtualAttributeToBeUpdated(virtualdata);

        // 5. update virtual attribute
        actual = userService.update(actual.getId(), userMod);
        assertNotNull(actual);
View Full Code Here

        // make std controls about user
        assertNotNull(created);
        assertTrue(RESOURCE_NAME_CSV.equals(created.getResources().iterator().next()));
        // update user
        UserTO toBeUpdated = userService.read(created.getId());
        UserMod userMod = new UserMod();
        userMod.setId(toBeUpdated.getId());
        userMod.setPassword("password2");
        // assign new resource to user
        userMod.addResourceToBeAdded(RESOURCE_NAME_WS2);
        //modify virtual attribute
        userMod.addVirtualAttributeToBeRemoved("virtualdata");
        userMod.addVirtualAttributeToBeUpdated(attributeMod("virtualdata", "test@testoneone.com"));

        // check Syncope change password
        PropagationRequestTO pwdPropRequest = new PropagationRequestTO();
        pwdPropRequest.setOnSyncope(true);
        pwdPropRequest.addResource(RESOURCE_NAME_WS2);
        userMod.setPwdPropRequest(pwdPropRequest);

        toBeUpdated = userService.update(userMod.getId(), userMod);
        assertNotNull(toBeUpdated);
        assertEquals("test@testoneone.com", toBeUpdated.getVirtualAttributes().get(0).getValues().get(0));
        // check if propagates correctly with assertEquals on size of tasks list
        assertEquals(2, toBeUpdated.getPropagationStatusTOs().size());
    }
View Full Code Here

            }
        }

        connectorService.update(connInstanceBean.getId(), connInstanceBean);

        UserMod userMod = new UserMod();
        userMod.setId(actual.getId());

        AttributeMod virtualdata = new AttributeMod();
        virtualdata.setSchema("virtualdata");
        virtualdata.addValueToBeAdded("virtualupdated");

        userMod.addVirtualAttributeToBeRemoved("virtualdata");
        userMod.addVirtualAttributeToBeUpdated(virtualdata);

        actual = userService.update(actual.getId(), userMod);
        assertNotNull(actual);
        // ----------------------------------------
View Full Code Here

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

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

            if (statusPanel != null) {
                userMod.setPwdPropRequest(statusPanel.getPropagationRequestTO());
            }

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

    protected UserTO updateUser(final Long id, SyncDelta delta, final boolean dryRun, final SyncResult result)
            throws Exception {

        UserTO userTO = userDataBinder.getUserTO(id);
        UserMod userMod = connObjectUtil.getAttributableMod(
                id, delta.getObject(), userTO, syncTask, AttributableUtil.getInstance(AttributableType.USER));

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

        if (dryRun) {
            return userTO;
        }

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

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

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

        Boolean enabled = readEnabled(delta.getObject());
        if (enabled != null) {
            SyncopeUser user = userDAO.find(id);

            WorkflowResult<Long> enableUpdate = null;
            if (user.isSuspended() == null) {
                enableUpdate = uwfAdapter.activate(id, null);
            } else if (enabled && user.isSuspended()) {
                enableUpdate = uwfAdapter.reactivate(id);
            } else if (!enabled && !user.isSuspended()) {
                enableUpdate = uwfAdapter.suspend(id);
            }

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

        List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(updated,
                userMod.getPassword(),
                userMod.getVirtualAttributesToBeRemoved(),
                userMod.getVirtualAttributesToBeUpdated(),
                Collections.singleton(syncTask.getResource().getName()));

        taskExecutor.execute(tasks);

        notificationManager.createTasks(updated.getResult().getKey(), updated.getPerformedTasks());
View Full Code Here

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

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

            if (statusPanel != null) {
                userMod.setPwdPropRequest(statusPanel.getPropagationRequestTO());
            }

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

    protected Map.Entry<UserTO, UserTO> updateUser(final Long id, SyncDelta delta, final boolean dryRun,
            final SyncResult result)
            throws Exception {

        final UserTO before = userDataBinder.getUserTO(id);
        UserMod userMod = connObjectUtil.getAttributableMod(
                id, delta.getObject(), before, syncTask, AttributableUtil.getInstance(AttributableType.USER));

        delta = actions.beforeUpdate(this, delta, before, userMod);

        if (dryRun) {
            return new AbstractMap.SimpleEntry<UserTO, UserTO>(before, before);
        }

        // Attribute value transformation (if configured)
        UserMod actual = attrTransformer.transform(userMod);
        LOG.debug("Transformed: {}", actual);

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

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

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

        Boolean enabled = readEnabled(delta.getObject());
        if (enabled != null) {
            SyncopeUser user = userDAO.find(id);

            WorkflowResult<Long> enableUpdate = null;
            if (user.isSuspended() == null) {
                enableUpdate = uwfAdapter.activate(id, null);
            } else if (enabled && user.isSuspended()) {
                enableUpdate = uwfAdapter.reactivate(id);
            } else if (!enabled && !user.isSuspended()) {
                enableUpdate = uwfAdapter.suspend(id);
            }

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

        List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(updated,
                actual.getPassword(),
                actual.getVirtualAttributesToBeRemoved(),
                actual.getVirtualAttributesToBeUpdated(),
                Collections.singleton(syncTask.getResource().getName()));

        taskExecutor.execute(tasks);

        final UserTO after = userDataBinder.getUserTO(updated.getResult().getKey());
View Full Code Here

     * @param userId user to be assigned membership to given role
     * @param roleTO role for adding membership
     * @return UserMod for user update
     */
    protected UserMod getUserMod(final Long userId, final RoleTO roleTO) {
        UserMod userMod = new UserMod();
        // no actual modification takes place when user has already the role assigned
        if (membersBeforeRoleUpdate.containsKey(userId)) {
            membersBeforeRoleUpdate.remove(userId);
        } else {
            userMod.setId(userId);

            MembershipMod membershipMod = new MembershipMod();
            membershipMod.setRole(roleTO.getId());
            userMod.addMembershipToBeAdded(membershipMod);
        }

        return userMod;
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.common.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.