Search in sources :

Example 6 with PasswordPatch

use of org.apache.syncope.common.lib.patch.PasswordPatch in project syncope by apache.

the class ChangePasswordModal method onSubmit.

@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
    final UserTO inner = wrapper.getInnerObject();
    try {
        if (StringUtils.isBlank(inner.getPassword()) || statusModel.getObject().isEmpty()) {
            SyncopeConsoleSession.get().error(getString(Constants.OPERATION_ERROR));
        } else {
            final List<String> resources = new ArrayList<>();
            boolean isOnSyncope = false;
            for (StatusBean sb : statusModel.getObject()) {
                if (sb.getResource().equals(Constants.SYNCOPE)) {
                    isOnSyncope = true;
                } else {
                    resources.add(sb.getResource());
                }
            }
            final UserPatch patch = new UserPatch();
            patch.setKey(inner.getKey());
            PasswordPatch passwordPatch = new PasswordPatch.Builder().value(inner.getPassword()).onSyncope(isOnSyncope).resources(resources).build();
            patch.setPassword(passwordPatch);
            userRestClient.update(inner.getETagValue(), patch);
            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
            modal.show(false);
            modal.close(target);
        }
    } catch (Exception e) {
        LOG.error("While updating password for user {}", inner, e);
        SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
    }
    super.onSubmit(target, form);
}
Also used : StatusBean(org.apache.syncope.client.console.commons.status.StatusBean) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) ArrayList(java.util.ArrayList) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 7 with PasswordPatch

use of org.apache.syncope.common.lib.patch.PasswordPatch in project syncope by apache.

the class DBPasswordPullActions method beforeUpdate.

@Transactional(readOnly = true)
@Override
public <M extends AnyPatch> void beforeUpdate(final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final EntityTO entityTO, final M anyPatch) throws JobExecutionException {
    if (anyPatch instanceof UserPatch) {
        PasswordPatch modPassword = ((UserPatch) anyPatch).getPassword();
        parseEncodedPassword(modPassword == null ? null : modPassword.getValue(), profile.getConnector());
    }
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with PasswordPatch

use of org.apache.syncope.common.lib.patch.PasswordPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE454.

@Test
public void issueSYNCOPE454() throws NamingException {
    // 1. create user with LDAP resource (with 'Generate password if missing' enabled)
    UserTO userTO = UserITCase.getUniqueSampleTO("syncope454@syncope.apache.org");
    userTO.getResources().add(RESOURCE_NAME_LDAP);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    // 2. read resource configuration for LDAP binding
    ConnObjectTO connObject = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
    // 3. try (and succeed) to perform simple LDAP binding with provided password ('password123')
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "password123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
    // 4. update user without any password change request
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
    userService.update(userPatch);
    // 5. try (and succeed again) to perform simple LDAP binding: password has not changed
    assertNotNull(getLdapRemoteObject(connObject.getAttr(Name.NAME).get().getValues().get(0), "password123", connObject.getAttr(Name.NAME).get().getValues().get(0)));
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 9 with PasswordPatch

use of org.apache.syncope.common.lib.patch.PasswordPatch in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE493.

@Test
public void issueSYNCOPE493() {
    // 1.  create user and check that firstname is not propagated on resource with mapping for firstname set to NONE
    UserTO userTO = UserITCase.getUniqueSampleTO("493@test.org");
    userTO.getResources().add(RESOURCE_NAME_WS1);
    ProvisioningResult<UserTO> result = createUser(userTO);
    assertNotNull(userTO);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO actual = resourceService.readConnObject(RESOURCE_NAME_WS1, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(actual);
    // check if mapping attribute with purpose NONE really hasn't been propagated
    assertFalse(actual.getAttr("NAME").isPresent());
    // 2.  update resource ws-target-resource-1
    ResourceTO ws1 = resourceService.read(RESOURCE_NAME_WS1);
    assertNotNull(ws1);
    MappingTO ws1NewUMapping = ws1.getProvision(AnyTypeKind.USER.name()).get().getMapping();
    // change purpose from NONE to BOTH
    for (ItemTO itemTO : ws1NewUMapping.getItems()) {
        if ("firstname".equals(itemTO.getIntAttrName())) {
            itemTO.setPurpose(MappingPurpose.BOTH);
        }
    }
    ws1.getProvision(AnyTypeKind.USER.name()).get().setMapping(ws1NewUMapping);
    resourceService.update(ws1);
    ResourceTO newWs1 = resourceService.read(ws1.getKey());
    assertNotNull(newWs1);
    // check for existence
    Collection<ItemTO> mapItems = newWs1.getProvision(AnyTypeKind.USER.name()).get().getMapping().getItems();
    assertNotNull(mapItems);
    assertEquals(7, mapItems.size());
    // 3.  update user and check firstname propagation
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    userPatch.setPassword(new PasswordPatch());
    userPatch.getPlainAttrs().add(attrAddReplacePatch("firstname", "firstnameNew"));
    result = updateUser(userPatch);
    assertNotNull(userTO);
    assertEquals(1, result.getPropagationStatuses().size());
    assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
    userTO = result.getEntity();
    ConnObjectTO newUser = resourceService.readConnObject(RESOURCE_NAME_WS1, AnyTypeKind.USER.name(), userTO.getKey());
    assertNotNull(newUser.getAttr("NAME"));
    assertEquals("firstnameNew", newUser.getAttr("NAME").get().getValues().get(0));
    // 4.  restore resource ws-target-resource-1 mapping
    ws1NewUMapping = newWs1.getProvision(AnyTypeKind.USER.name()).get().getMapping();
    // restore purpose from BOTH to NONE
    for (ItemTO itemTO : ws1NewUMapping.getItems()) {
        if ("firstname".equals(itemTO.getIntAttrName())) {
            itemTO.setPurpose(MappingPurpose.NONE);
        }
    }
    newWs1.getProvision(AnyTypeKind.USER.name()).get().setMapping(ws1NewUMapping);
    resourceService.update(newWs1);
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 10 with PasswordPatch

use of org.apache.syncope.common.lib.patch.PasswordPatch in project syncope by apache.

the class UserWizardBuilder method onApplyInternal.

@Override
protected Serializable onApplyInternal(final AnyWrapper<UserTO> modelObject) {
    UserTO inner = modelObject.getInnerObject();
    ProvisioningResult<UserTO> actual;
    if (inner.getKey() == null) {
        actual = userRestClient.create(inner, modelObject instanceof UserWrapper ? UserWrapper.class.cast(modelObject).isStorePasswordInSyncope() : StringUtils.isNotBlank(inner.getPassword()));
    } else {
        UserPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
        if (StringUtils.isNotBlank(inner.getPassword())) {
            PasswordPatch passwordPatch = new PasswordPatch.Builder().value(inner.getPassword()).onSyncope(true).resources(inner.getResources()).build();
            patch.setPassword(passwordPatch);
        }
        // update just if it is changed
        if (patch.isEmpty()) {
            actual = new ProvisioningResult<>();
            actual.setEntity(inner);
        } else {
            actual = userRestClient.update(getOriginalItem().getInnerObject().getETagValue(), patch);
        }
    }
    return actual;
}
Also used : PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Aggregations

PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)10 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)10 UserTO (org.apache.syncope.common.lib.to.UserTO)7 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Pair (org.apache.commons.lang3.tuple.Pair)2 AttrTO (org.apache.syncope.common.lib.to.AttrTO)2 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)2 User (org.apache.syncope.core.persistence.api.entity.user.User)2 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1