Search in sources :

Example 6 with PasswordAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto 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);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityQuestionsPanel(com.evolveum.midpoint.web.page.self.component.SecurityQuestionsPanel) ChangePasswordPanel(com.evolveum.midpoint.web.page.self.component.ChangePasswordPanel) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) Component(org.apache.wicket.Component) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with PasswordAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto 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);
}
Also used : PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)

Example 8 with PasswordAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto in project midpoint by Evolveum.

the class ChangePasswordPanel method createPasswordAccountDto.

private PasswordAccountDto createPasswordAccountDto(MyPasswordsDto passwordDto, PrismObject<ShadowType> account, Task task, OperationResult result) {
    PrismReference resourceRef = account.findReference(ShadowType.F_RESOURCE_REF);
    String resourceName;
    if (resourceRef == null || resourceRef.getValue() == null || resourceRef.getValue().getObject() == null) {
        resourceName = getString("PageSelfCredentials.couldntResolve");
    } else {
        resourceName = WebComponentUtil.getName(resourceRef.getValue().getObject());
    }
    PasswordAccountDto passwordAccountDto = new PasswordAccountDto(account, resourceName, resourceRef.getOid());
    ShadowType shadowType = account.asObjectable();
    ResourceType resource = (ResourceType) shadowType.getResourceRef().asReferenceValue().getObject().asObjectable();
    if (resource != null) {
        ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource.asPrismObject(), shadowType.getKind(), shadowType.getIntent());
        passwordAccountDto.setPasswordCapabilityEnabled(ResourceTypeUtil.isPasswordCapabilityEnabled(resource, resourceObjectTypeDefinitionType));
        passwordAccountDto.setMaintenanceState(ResourceTypeUtil.isInMaintenance(resource));
        try {
            ResourceObjectDefinition rOCDef = getPageBase().getModelInteractionService().getEditObjectClassDefinition(account, resource.asPrismObject(), AuthorizationPhaseType.REQUEST, task, result);
            if (rOCDef != null) {
                passwordAccountDto.setPasswordOutbound(getPasswordOutbound(account, resource, rOCDef));
                CredentialsPolicyType credentialsPolicy = getPasswordCredentialsPolicy(rOCDef);
                if (credentialsPolicy != null && credentialsPolicy.getPassword() != null && credentialsPolicy.getPassword().getValuePolicyRef() != null) {
                    PrismObject<ValuePolicyType> valuePolicy = WebModelServiceUtils.resolveReferenceNoFetch(credentialsPolicy.getPassword().getValuePolicyRef(), getPageBase(), task, task.getResult());
                    if (valuePolicy != null) {
                        passwordAccountDto.setPasswordValuePolicyOid(valuePolicy.getOid());
                        passwordDto.addPasswordPolicy(valuePolicy.asObjectable());
                    }
                }
            } else {
                passwordAccountDto.setPasswordOutbound(false);
            }
        } catch (Exception e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Fail to get ResourceObjectTypeDefinition for {} ", e, account);
            result.recordFatalError("Fail to get ResourceObjectTypeDefinition for " + account, e);
            getPageBase().showResult(result);
            passwordAccountDto.setPasswordOutbound(false);
        }
    } else {
        passwordAccountDto.setPasswordCapabilityEnabled(false);
        passwordAccountDto.setPasswordOutbound(false);
    }
    return passwordAccountDto;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) PrismReference(com.evolveum.midpoint.prism.PrismReference) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)

Example 9 with PasswordAccountDto

use of com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto in project midpoint by Evolveum.

the class ChangePasswordPanel method createDefaultPasswordAccountDto.

private PasswordAccountDto createDefaultPasswordAccountDto(PrismObject<? extends FocusType> focus, String passwordPolicyOid) {
    String customSystemName = WebComponentUtil.getMidpointCustomSystemName(getPageBase(), "midpoint.default.system.name");
    PasswordAccountDto accountDto = new PasswordAccountDto(focus, focus.getName().getOrig(), getString("PageSelfCredentials.resourceMidpoint", customSystemName), WebComponentUtil.isActivationEnabled(focus, ActivationType.F_EFFECTIVE_STATUS), true);
    accountDto.setPasswordValuePolicyOid(passwordPolicyOid);
    return accountDto;
}
Also used : PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)

Aggregations

PasswordAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)9 MyPasswordsDto (com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)5 PrismReference (com.evolveum.midpoint.prism.PrismReference)4 PasswordPanel (com.evolveum.midpoint.gui.api.component.password.PasswordPanel)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 TablePanel (com.evolveum.midpoint.web.component.data.TablePanel)3 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 AttributeModifier (org.apache.wicket.AttributeModifier)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 Label (org.apache.wicket.markup.html.basic.Label)3 PasswordTextField (org.apache.wicket.markup.html.form.PasswordTextField)3 AuthUtil (com.evolveum.midpoint.authentication.api.util.AuthUtil)2 GuiStyleConstants (com.evolveum.midpoint.gui.api.GuiStyleConstants)2 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)2