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);
}
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());
}
}
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)));
}
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);
}
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;
}
Aggregations