use of com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto in project midpoint by Evolveum.
the class ChangePasswordPanel method createMyPasswordsDto.
private MyPasswordsDto createMyPasswordsDto(PrismObject<? extends FocusType> focus) {
MyPasswordsDto dto = new MyPasswordsDto();
dto.setFocus(focus);
Task task = getPageBase().createSimpleTask(OPERATION_GET_CREDENTIALS_POLICY);
CredentialsPolicyType credentialsPolicyType = WebComponentUtil.getPasswordCredentialsPolicy(focus, getPageBase(), task);
dto.getAccounts().add(createDefaultPasswordAccountDto(focus, getPasswordPolicyOid(credentialsPolicyType)));
if (credentialsPolicyType != null) {
PasswordCredentialsPolicyType passwordCredentialsPolicy = credentialsPolicyType.getPassword();
if (passwordCredentialsPolicy != null) {
CredentialsPropagationUserControlType propagationUserControl = passwordCredentialsPolicy.getPropagationUserControl();
if (propagationUserControl != null) {
dto.setPropagation(propagationUserControl);
}
PasswordChangeSecurityType passwordChangeSecurity = passwordCredentialsPolicy.getPasswordChangeSecurity();
if (passwordChangeSecurity != null) {
dto.setPasswordChangeSecurity(passwordChangeSecurity);
}
ObjectReferenceType valuePolicyRef = passwordCredentialsPolicy.getValuePolicyRef();
if (valuePolicyRef != null && valuePolicyRef.getOid() != null) {
task = getPageBase().createSimpleTask("load value policy");
PrismObject<ValuePolicyType> valuePolicy = WebModelServiceUtils.resolveReferenceNoFetch(valuePolicyRef, getPageBase(), task, task.getResult());
if (valuePolicy != null) {
dto.addPasswordPolicy(valuePolicy.asObjectable());
}
}
}
}
return dto;
}
use of com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto in project midpoint by Evolveum.
the class ChangePasswordPanel method initMidpointAccountSelected.
private void initMidpointAccountSelected() {
MyPasswordsDto dto = getModelObject();
PasswordAccountDto midpointAccount = null;
for (PasswordAccountDto account : dto.getAccounts()) {
if (account.isMidpoint()) {
midpointAccount = account;
}
}
midpointAccountSelected = new PropertyModel<>(midpointAccount, Selectable.F_SELECTED);
}
use of com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method setNullEncryptedPasswordData.
protected void setNullEncryptedPasswordData() {
MyPasswordsDto dto = getPasswordDto();
ProtectedStringType password = dto.getPassword();
if (password != null) {
password.setEncryptedData(null);
}
}
use of com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method onSavePerformed.
protected void onSavePerformed(AjaxRequestTarget target) {
Component actualTab = getActualTabPanel();
if (actualTab instanceof ChangePasswordPanel) {
ProtectedStringType oldPassword = null;
if (isCheckOldPassword()) {
LOGGER.debug("Check old password");
MyPasswordsDto modelObject = getPasswordDto();
if (modelObject.getOldPassword() == null || modelObject.getOldPassword().trim().equals("")) {
warn(getString("PageSelfCredentials.specifyOldPasswordMessage"));
target.add(getFeedbackPanel());
return;
} else {
OperationResult checkPasswordResult = new OperationResult(OPERATION_CHECK_PASSWORD);
Task checkPasswordTask = createSimpleTask(OPERATION_CHECK_PASSWORD);
try {
oldPassword = new ProtectedStringType();
oldPassword.setClearValue(modelObject.getOldPassword());
boolean isCorrectPassword = getModelInteractionService().checkPassword(modelObject.getFocusOid(), oldPassword, checkPasswordTask, checkPasswordResult);
if (!isCorrectPassword) {
error(getString("PageSelfCredentials.incorrectOldPassword"));
target.add(getFeedbackPanel());
return;
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't check password", ex);
checkPasswordResult.recordFatalError(getString("PageAbstractSelfCredentials.message.onSavePerformed.fatalError", ex.getMessage()), ex);
target.add(getFeedbackPanel());
return;
} finally {
checkPasswordResult.computeStatus();
}
}
}
if (getPasswordDto().getPassword() == null) {
warn(getString("PageSelfCredentials.emptyPasswordFiled"));
target.add(getFeedbackPanel());
return;
}
List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();
if (selectedAccounts.isEmpty()) {
warn(getString("PageSelfCredentials.noAccountSelected"));
target.add(getFeedbackPanel());
return;
}
OperationResult result = new OperationResult(OPERATION_SAVE_PASSWORD);
ProgressReporter reporter = new ProgressReporter(MidPointApplication.get());
reporter.getProgress().clear();
reporter.setWriteOpResultForProgressActivity(true);
reporter.recordExecutionStart();
boolean showFeedback = true;
try {
MyPasswordsDto dto = getPasswordDto();
ProtectedStringType password = dto.getPassword();
if (!password.isEncrypted()) {
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
}
final ItemPath valuePath = ItemPath.create(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
for (PasswordAccountDto accDto : selectedAccounts) {
PrismObjectDefinition objDef = accDto.isMidpoint() ? registry.findObjectDefinitionByCompileTimeClass(UserType.class) : registry.findObjectDefinitionByCompileTimeClass(ShadowType.class);
PropertyDelta<ProtectedStringType> delta = getPrismContext().deltaFactory().property().createModificationReplaceProperty(valuePath, objDef, password);
if (oldPassword != null) {
delta.addEstimatedOldValue(getPrismContext().itemFactory().createPropertyValue(oldPassword));
}
Class<? extends ObjectType> type = accDto.isMidpoint() ? UserType.class : ShadowType.class;
deltas.add(getPrismContext().deltaFactory().object().createModifyDelta(accDto.getOid(), delta, type));
}
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_PASSWORD, SchemaConstants.CHANNEL_SELF_SERVICE_URI), Collections.singleton(reporter), result);
result.computeStatus();
} catch (Exception ex) {
setNullEncryptedPasswordData();
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save password changes", ex);
result.recordFatalError(getString("PageAbstractSelfCredentials.save.password.failed", ex.getMessage()), ex);
} finally {
reporter.recordExecutionStop();
getPasswordDto().setProgress(reporter.getProgress());
if (getActualTabPanel() != null) {
((ChangePasswordPanel) getActualTabPanel()).updateResultColumnOfTable(target);
}
result.computeStatusIfUnknown();
if (shouldLoadAccounts()) {
showFeedback = false;
if (result.isError()) {
error(createStringResource("PageAbstractSelfCredentials.message.resultInTable.error").getString());
} else {
success(createStringResource("PageAbstractSelfCredentials.message.resultInTable").getString());
}
}
if (!result.isError()) {
this.savedPassword = true;
target.add(getSaveButton());
}
}
finishChangePassword(result, target, showFeedback);
} else if (actualTab instanceof SecurityQuestionsPanel) {
((SecurityQuestionsPanel) actualTab).onSavePerformed(target);
}
}
Aggregations