Search in sources :

Example 66 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class PageSelfRegistration method createPasswordPanel.

private void createPasswordPanel(WebMarkupContainer staticRegistrationForm) {
    // ProtectedStringType initialPassword = null;
    PasswordPanel password = new PasswordPanel(ID_PASSWORD, new PropertyModel<ProtectedStringType>(userModel, "credentials.password.value"), false, true);
    password.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    password.getBaseFormComponent().setRequired(true);
    staticRegistrationForm.add(password);
    Label help = new Label(ID_TOOLTIP);
    final StringResourceModel tooltipText = createStringResource("PageSelfRegistration.password.policy");
    help.add(AttributeModifier.replace("title", tooltipText));
    help.add(new InfoTooltipBehavior());
    help.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(tooltipText.getObject());
        }
    });
    staticRegistrationForm.add(help);
}
Also used : InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) PasswordPanel(com.evolveum.midpoint.gui.api.component.password.PasswordPanel) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) Label(org.apache.wicket.markup.html.basic.Label) MultiLineLabel(org.apache.wicket.markup.html.basic.MultiLineLabel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 67 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class PageSelfRegistration method createNonce.

private NonceType createNonce(NonceCredentialsPolicyType noncePolicy, Task task, OperationResult result) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException {
    ProtectedStringType nonceCredentials = new ProtectedStringType();
    nonceCredentials.setClearValue(generateNonce(noncePolicy, null, task, result));
    NonceType nonceType = new NonceType();
    nonceType.setValue(nonceCredentials);
    return nonceType;
}
Also used : NonceType(com.evolveum.midpoint.xml.ns._public.common.common_3.NonceType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 68 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class PageAbstractSelfCredentials method onSavePerformed.

protected void onSavePerformed(AjaxRequestTarget target) {
    List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();
    if (isCheckOldPassword()) {
        LOGGER.debug("Check old password");
        if (model.getObject().getOldPassword() == null || model.getObject().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 {
                ProtectedStringType oldPassword = new ProtectedStringType();
                oldPassword.setClearValue(model.getObject().getOldPassword());
                boolean isCorrectPassword = getModelInteractionService().checkPassword(user.getOid(), oldPassword, checkPasswordTask, checkPasswordResult);
                if (!isCorrectPassword) {
                    warn(getString("PageSelfCredentials.incorrectOldPassword"));
                    target.add(getFeedbackPanel());
                    return;
                }
            } catch (Exception ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't check password", ex);
                checkPasswordResult.recordFatalError("Couldn't check password." + ex.getMessage(), ex);
                target.add(getFeedbackPanel());
                return;
            } finally {
                checkPasswordResult.computeStatus();
            }
        }
    }
    if (selectedAccounts.isEmpty()) {
        warn(getString("PageSelfCredentials.noAccountSelected"));
        target.add(getFeedbackPanel());
        return;
    }
    if (getModelObject().getPassword() == null) {
        warn(getString("PageSelfCredentials.emptyPasswordFiled"));
        target.add(getFeedbackPanel());
        return;
    }
    OperationResult result = new OperationResult(OPERATION_SAVE_PASSWORD);
    try {
        MyPasswordsDto dto = model.getObject();
        ProtectedStringType password = dto.getPassword();
        if (!password.isEncrypted()) {
            WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
        }
        final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        for (PasswordAccountDto accDto : selectedAccounts) {
            PrismObjectDefinition objDef = accDto.isMidpoint() ? registry.findObjectDefinitionByCompileTimeClass(UserType.class) : registry.findObjectDefinitionByCompileTimeClass(ShadowType.class);
            PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, password);
            Class<? extends ObjectType> type = accDto.isMidpoint() ? UserType.class : ShadowType.class;
            deltas.add(ObjectDelta.createModifyDelta(accDto.getOid(), delta, type, getPrismContext()));
        }
        getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_PASSWORD), result);
        result.computeStatus();
    } catch (Exception ex) {
        setEncryptedPasswordData(null);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save password changes", ex);
        result.recordFatalError(getString("PageAbstractSelfCredentials.save.password.failed", ex.getMessage()), ex);
    } finally {
        result.computeStatusIfUnknown();
        ;
    }
    finishChangePassword(result, target);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) 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 69 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class WebComponentUtil method encryptCredentials.

public static void encryptCredentials(ObjectDelta delta, boolean encrypt, MidPointApplication app) {
    if (delta == null || delta.isEmpty()) {
        return;
    }
    PropertyDelta propertyDelta = delta.findPropertyDelta(new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE));
    if (propertyDelta == null) {
        return;
    }
    Collection<PrismPropertyValue<ProtectedStringType>> values = propertyDelta.getValues(ProtectedStringType.class);
    for (PrismPropertyValue<ProtectedStringType> value : values) {
        ProtectedStringType string = value.getValue();
        encryptProtectedString(string, encrypt, app);
    }
}
Also used : PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 70 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.

the class NotificationConfigurationDto method getNewObject.

public NotificationConfigurationType getNewObject(SystemConfigurationType systemConfig) {
    NotificationConfigurationType notificationConfig = (systemConfig.getNotificationConfiguration() != null) ? systemConfig.getNotificationConfiguration() : new NotificationConfigurationType();
    MailConfigurationType mailConfig = (notificationConfig.getMail() != null) ? notificationConfig.getMail() : new MailConfigurationType();
    mailConfig.setDebug(isDebug());
    mailConfig.setDefaultFrom(getDefaultFrom());
    mailConfig.setRedirectToFile(getRedirectToFile());
    mailConfig.getServer().clear();
    for (MailServerConfigurationTypeDto serverDto : getServers()) {
        MailServerConfigurationType newConfig = new MailServerConfigurationType();
        newConfig.setHost(serverDto.getHost());
        newConfig.setPort(serverDto.getPort());
        newConfig.setUsername(serverDto.getUsername());
        newConfig.setTransportSecurity(serverDto.getMailTransportSecurityType());
        if (serverDto.getPassword() != null && StringUtils.isNotEmpty(serverDto.getPassword())) {
            ProtectedStringType pass = new ProtectedStringType();
            pass.setClearValue(serverDto.getPassword());
            newConfig.setPassword(pass);
        } else {
            newConfig.setPassword(serverDto.getOldConfig().getPassword());
        }
        mailConfig.getServer().add(newConfig);
    }
    notificationConfig.setMail(mailConfig);
    return notificationConfig;
}
Also used : NotificationConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationConfigurationType) MailConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailConfigurationType) MailServerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MailServerConfigurationType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Aggregations

ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)120 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 Test (org.testng.annotations.Test)48 Task (com.evolveum.midpoint.task.api.Task)39 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 QName (javax.xml.namespace.QName)20 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)18 PasswordType (com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType)18 CredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)11 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)9 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)9 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)9 Document (org.w3c.dom.Document)8 ArrayList (java.util.ArrayList)7 Entry (org.apache.directory.api.ldap.model.entry.Entry)7