Search in sources :

Example 1 with MyPasswordsDto

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

the class ChangePasswordPanel method initLayout.

private void initLayout(final boolean oldPasswordVisible) {
    model = (LoadableModel<MyPasswordsDto>) getModel();
    Label oldPasswordLabel = new Label(ID_OLD_PASSWORD_LABEL, createStringResource("PageSelfCredentials.oldPasswordLabel"));
    add(oldPasswordLabel);
    oldPasswordLabel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return oldPasswordVisible;
        }
    });
    Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
    add(passwordLabel);
    PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<String>(model, MyPasswordsDto.F_OLD_PASSWORD));
    oldPasswordField.setRequired(false);
    oldPasswordField.setResetPassword(false);
    add(oldPasswordField);
    oldPasswordField.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        public boolean isVisible() {
            return oldPasswordVisible;
        }

        ;
    });
    PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<ProtectedStringType>(model, MyPasswordsDto.F_PASSWORD));
    passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
    add(passwordPanel);
    WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
    List<IColumn<PasswordAccountDto, String>> columns = initColumns();
    ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<PasswordAccountDto>(this, new PropertyModel<List<PasswordAccountDto>>(model, MyPasswordsDto.F_ACCOUNTS));
    TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
    accounts.setItemsPerPage(30);
    accounts.setShowPaging(false);
    if (model.getObject().getPropagation() != null && model.getObject().getPropagation().equals(CredentialsPropagationUserControlType.MAPPING)) {
        accountContainer.setVisible(false);
    }
    accountContainer.add(accounts);
    AjaxLink help = new AjaxLink(ID_BUTTON_HELP) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHelpPerformed(target);
        }
    };
    accountContainer.add(help);
    add(accountContainer);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) Label(org.apache.wicket.markup.html.basic.Label) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) TablePanel(com.evolveum.midpoint.web.component.data.TablePanel)

Example 2 with MyPasswordsDto

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

the class PageAbstractSelfCredentials method loadPageModel.

private MyPasswordsDto loadPageModel() {
    LOGGER.debug("Loading user and accounts.");
    MyPasswordsDto dto = new MyPasswordsDto();
    OperationResult result = new OperationResult(OPERATION_LOAD_USER_WITH_ACCOUNTS);
    try {
        String userOid = SecurityUtils.getPrincipalUser().getOid();
        Task task = createSimpleTask(OPERATION_LOAD_USER);
        OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
        user = getModelService().getObject(UserType.class, userOid, null, task, subResult);
        subResult.recordSuccessIfUnknown();
        dto.getAccounts().add(createDefaultPasswordAccountDto(user));
        CredentialsPolicyType credentialsPolicyType = getPasswordCredentialsPolicy();
        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);
                }
            }
        }
        if (dto.getPropagation() == null || dto.getPropagation().equals(CredentialsPropagationUserControlType.USER_CHOICE)) {
            PrismReference reference = user.findReference(UserType.F_LINK_REF);
            if (reference == null || reference.getValues() == null) {
                LOGGER.debug("No accounts found for user {}.", new Object[] { userOid });
                return dto;
            }
            final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ShadowType.F_RESOURCE, GetOperationOptions.createResolve());
            List<PrismReferenceValue> values = reference.getValues();
            for (PrismReferenceValue value : values) {
                subResult = result.createSubresult(OPERATION_LOAD_ACCOUNT);
                try {
                    String accountOid = value.getOid();
                    task = createSimpleTask(OPERATION_LOAD_ACCOUNT);
                    PrismObject<ShadowType> account = getModelService().getObject(ShadowType.class, accountOid, options, task, subResult);
                    dto.getAccounts().add(createPasswordAccountDto(account));
                    subResult.recordSuccessIfUnknown();
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load account", ex);
                    subResult.recordFatalError("Couldn't load account.", ex);
                }
            }
        }
        result.recordSuccessIfUnknown();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
        result.recordFatalError("Couldn't load accounts", ex);
    } finally {
        result.recomputeStatus();
    }
    Collections.sort(dto.getAccounts());
    if (!result.isSuccess() && !result.isHandledError()) {
        showResult(result);
    }
    return dto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismReference(com.evolveum.midpoint.prism.PrismReference) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)

Example 3 with MyPasswordsDto

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

the class PageAbstractSelfCredentials method setEncryptedPasswordData.

protected void setEncryptedPasswordData(EncryptedDataType data) {
    MyPasswordsDto dto = model.getObject();
    ProtectedStringType password = dto.getPassword();
    if (password != null) {
        password.setEncryptedData(data);
    }
}
Also used : MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 4 with MyPasswordsDto

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

the class PageResetPassword method finishChangePassword.

@Override
protected void finishChangePassword(final OperationResult result, AjaxRequestTarget target, boolean showFeedback) {
    if (result.getStatus() == OperationResultStatus.SUCCESS) {
        result.setMessage(getString("PageResetPassword.reset.successful"));
        setResponsePage(PageLogin.class);
        MyPasswordsDto passwords = getPasswordDto();
        PrismObject<? extends FocusType> focus = passwords.getFocus();
        if (focus == null) {
            SecurityContextHolder.getContext().setAuthentication(null);
            return;
        }
        FocusType focusType = focus.asObjectable();
        if (focusType.getCredentials() != null && focusType.getCredentials().getNonce() != null) {
            try {
                ObjectDelta<UserType> deleteNonceDelta = getPrismContext().deltaFactory().object().createModificationDeleteContainer(UserType.class, focusType.getOid(), SchemaConstants.PATH_NONCE, focusType.getCredentials().getNonce().clone());
                WebModelServiceUtils.save(deleteNonceDelta, result, this);
            } catch (SchemaException e) {
            // nothing to do, just let the nonce here.. it will be invalid
            }
        }
        SecurityContextHolder.getContext().setAuthentication(null);
        showResult(result);
        target.add(getFeedbackPanel());
    } else if (showFeedback) {
        showResult(result);
    }
    target.add(getFeedbackPanel());
// get(ID_MAIN_FORM).setVisible(false);
// success(getString("PageShowPassword.success")); //TODO uncomment when remove old mechanism
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 5 with MyPasswordsDto

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

the class ChangePasswordPanel method loadPageModel.

private MyPasswordsDto loadPageModel() {
    LOGGER.debug("Loading user and accounts.");
    MyPasswordsDto passwordsDto = new MyPasswordsDto();
    OperationResult result = new OperationResult(OPERATION_LOAD_USER_WITH_ACCOUNTS);
    try {
        String focusOid = AuthUtil.getPrincipalUser().getOid();
        Task task = getPageBase().createSimpleTask(OPERATION_LOAD_USER);
        OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
        PrismObject<? extends FocusType> focus = getPageBase().getModelService().getObject(FocusType.class, focusOid, null, task, subResult);
        passwordsDto = createMyPasswordsDto(focus);
        subResult.recordSuccessIfUnknown();
        getModel().setObject(passwordsDto);
        if (!shouldShowPasswordPropagation()) {
            LOGGER.debug("Skip loading account, because policy said so (enabled {} propagation).", passwordsDto.getPropagation());
            return passwordsDto;
        }
        PrismReference reference = focus.findReference(FocusType.F_LINK_REF);
        if (reference == null || CollectionUtils.isEmpty(reference.getValues())) {
            LOGGER.debug("No accounts found for user {}.", focusOid);
            return passwordsDto;
        }
        addAccountsToMyPasswordsDto(passwordsDto, reference.getValues(), task, result);
        result.recordSuccessIfUnknown();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
        result.recordFatalError(getString("PageAbstractSelfCredentials.message.couldntLoadAccounts.fatalError"), ex);
    } finally {
        result.recomputeStatus();
    }
    Collections.sort(passwordsDto.getAccounts());
    if (!result.isSuccess() && !result.isHandledError()) {
        getPageBase().showResult(result);
    }
    return passwordsDto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismReference(com.evolveum.midpoint.prism.PrismReference) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

MyPasswordsDto (com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)9 Task (com.evolveum.midpoint.task.api.Task)4 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 PasswordAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)3 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ArrayList (java.util.ArrayList)2 PasswordPanel (com.evolveum.midpoint.gui.api.component.password.PasswordPanel)1 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 TablePanel (com.evolveum.midpoint.web.component.data.TablePanel)1 ProgressReporter (com.evolveum.midpoint.web.component.progress.ProgressReporter)1 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 ChangePasswordPanel (com.evolveum.midpoint.web.page.self.component.ChangePasswordPanel)1