Search in sources :

Example 1 with I18nKeyAndParams

use of org.projectforge.framework.i18n.I18nKeyAndParams in project projectforge by micromata.

the class SetupForm method init.

@Override
@SuppressWarnings("serial")
protected void init() {
    add(createFeedbackPanel());
    final GridBuilder gridBuilder = newGridBuilder(this, "flowform");
    gridBuilder.newFormHeading(getString("administration.setup.heading"));
    final DivPanel panel = gridBuilder.getPanel();
    panel.add(new ParTextPanel(panel.newChildId(), getString("administration.setup.heading.subtitle")));
    {
        // RadioChoice mode
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.setup.target"));
        final DivPanel radioPanel = fs.addNewRadioBoxButtonDiv();
        fs.add(radioPanel);
        fs.setLabelFor(radioPanel);
        final RadioGroupPanel<SetupTarget> radioGroup = new RadioGroupPanel<>(radioPanel.newChildId(), "setuptarget", setupModeModel);
        radioPanel.add(radioGroup);
        for (final SetupTarget target : SetupTarget.values()) {
            radioGroup.add(new Model<SetupTarget>(target), getString(target.getI18nKey()), getString(target.getI18nKey() + ".tooltip"));
        }
    }
    // final RequiredMaxLengthTextField organizationField = new RequiredMaxLengthTextField(this, "organization", getString("organization"),
    // new PropertyModel<String>(this, "organization"), 100);
    // add(organizationField);
    {
        // User name
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("username"));
        RequiredMaxLengthTextField usernameTextField = new RequiredMaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(adminUser, "username"), 100);
        usernameTextField.setMarkupId("username");
        usernameTextField.setOutputMarkupId(true);
        fs.add(usernameTextField);
    }
    final PasswordTextField passwordField = createPasswordField();
    passwordField.setMarkupId("password").setOutputMarkupId(true);
    {
        // Password
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("password"));
        // No setReset(true), otherwise uploading and re-entering passwords is a real pain.
        passwordField.setRequired(true);
        fs.add(passwordField);
        WicketUtils.setFocus(passwordField);
    }
    {
        // Password repeat
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("passwordRepeat"));
        final PasswordTextField passwordRepeatField = createPasswordField();
        // No setReset(true), otherwise uploading and re-entering passwords is a real pain.
        passwordRepeatField.setRequired(true);
        passwordRepeatField.setMarkupId("passwordRepeat").setOutputMarkupId(true);
        passwordRepeatField.add((IValidator<String>) validatable -> {
            final String input = validatable.getValue();
            final String passwordInput = passwordField.getConvertedInput();
            if (StringUtils.equals(input, passwordInput) == false) {
                passwordRepeatField.error(getString("user.error.passwordAndRepeatDoesNotMatch"));
                adminUser.setPassword(null);
                return;
            }
            if (MAGIC_PASSWORD.equals(passwordInput) == false || adminUser.getPassword() == null) {
                final List<I18nKeyAndParams> errorMsgKeys = passwordQualityService.checkPasswordQuality(passwordInput.toCharArray());
                if (errorMsgKeys.isEmpty() == false) {
                    adminUser.setPassword(null);
                    for (I18nKeyAndParams errorMsgKey : errorMsgKeys) {
                        passwordField.error(I18nHelper.getLocalizedMessage(errorMsgKey));
                    }
                } else {
                    userService.createEncryptedPassword(adminUser, passwordInput.toCharArray());
                }
            }
        });
        fs.add(passwordRepeatField);
    }
    {
        // Time zone
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.configuration.param.timezone"));
        final TimeZonePanel timeZone = new TimeZonePanel(fs.newChildId(), new PropertyModel<>(this, "timeZone"));
        fs.setLabelFor(timeZone);
        fs.add(timeZone);
        fs.addHelpIcon(getString("administration.configuration.param.timezone.description"));
    }
    {
        // Calendar domain
        calendarDomainModel.setObject("local");
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.configuration.param.calendarDomain"));
        final RequiredMaxLengthTextField textField = new RequiredMaxLengthTextField(InputPanel.WICKET_ID, calendarDomainModel, ConfigurationDO.Companion.getParamLength());
        fs.add(textField);
        textField.setMarkupId("calendarDomain").setOutputMarkupId(true);
        textField.add(new IValidator<String>() {

            @Override
            public void validate(final IValidatable<String> validatable) {
                if (Configuration.isDomainValid(validatable.getValue()) == false) {
                    textField.error(getString("validation.error.generic"));
                }
            }
        });
        fs.addHelpIcon(getString("administration.configuration.param.calendarDomain.description"));
    }
    {
        // E-Mail sysops
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.configuration.param.systemAdministratorEMail.label"), getString("email"));
        fs.add(new MaxLengthTextField(InputPanel.WICKET_ID, sysopEMailModel, ConfigurationDO.Companion.getParamLength()));
        fs.addHelpIcon(getString("administration.configuration.param.systemAdministratorEMail.description"));
    }
    {
        // E-Mail sysops
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.configuration.param.feedbackEMail.label"), getString("email"));
        fs.add(new MaxLengthTextField(InputPanel.WICKET_ID, feedbackEMailModel, ConfigurationDO.Companion.getParamLength()));
        fs.addHelpIcon(getString("administration.configuration.param.feedbackEMail.description"));
    }
    final RepeatingView actionButtons = new RepeatingView("buttons");
    add(actionButtons);
    {
        final Button finishButton = new Button(SingleButtonPanel.WICKET_ID, new Model<String>("finish")) {

            @Override
            public final void onSubmit() {
                csrfTokenHandler.onSubmit();
                parentPage.finishSetup();
            }
        };
        finishButton.setMarkupId("finish").setOutputMarkupId(true);
        final SingleButtonPanel finishButtonPanel = new SingleButtonPanel(actionButtons.newChildId(), finishButton, getString("administration.setup.finish"), SingleButtonPanel.DEFAULT_SUBMIT);
        actionButtons.add(finishButtonPanel);
        setDefaultButton(finishButton);
    }
}
Also used : PropertyModel(org.apache.wicket.model.PropertyModel) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) TimeZonePanel(org.projectforge.web.wicket.components.TimeZonePanel) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) IValidatable(org.apache.wicket.validation.IValidatable) GridBuilder(org.projectforge.web.wicket.bootstrap.GridBuilder) IValidator(org.apache.wicket.validation.IValidator) Button(org.apache.wicket.markup.html.form.Button) MaxLengthTextField(org.projectforge.web.wicket.components.MaxLengthTextField) RequiredMaxLengthTextField(org.projectforge.web.wicket.components.RequiredMaxLengthTextField) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams) RequiredMaxLengthTextField(org.projectforge.web.wicket.components.RequiredMaxLengthTextField) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Example 2 with I18nKeyAndParams

use of org.projectforge.framework.i18n.I18nKeyAndParams in project projectforge by micromata.

the class UserTest method testPasswordQuality.

/**
 * Test password quality.
 */
@Test
public void testPasswordQuality() {
    final ConfigurationDO minPwLenEntry = configurationDao.getEntry(ConfigurationParam.MIN_PASSWORD_LENGTH);
    minPwLenEntry.setIntValue(10);
    configurationDao.internalUpdate(minPwLenEntry);
    List<I18nKeyAndParams> passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, null);
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_MIN_LENGTH_ERROR, 10)), "Empty password not allowed.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, "".toCharArray());
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_MIN_LENGTH_ERROR, 10)), "Empty password not allowed.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, "abcd12345".toCharArray());
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_MIN_LENGTH_ERROR, 10)), "Password with less than " + "10" + " characters not allowed.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, "ProjectForge".toCharArray());
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_NONCHAR_ERROR)), "Password must have one non letter at minimum.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, "1234567890".toCharArray());
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_CHARACTER_ERROR)), "Password must have one non letter at minimum.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, "12345678901".toCharArray());
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_CHARACTER_ERROR)), "Password must have one non letter at minimum.");
    passwordQualityMessages = passwordQualityService.checkPasswordQuality(STRONGOLDPW, STRONGOLDPW);
    assertTrue(passwordQualityMessages.contains(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_OLD_EQ_NEW_ERROR)), "Password must New password should not be the same as the old one.");
    assertTrue(passwordQualityService.checkPasswordQuality(STRONGOLDPW, "kabcdjh!id".toCharArray()).isEmpty(), "Password OK.");
    assertTrue(passwordQualityService.checkPasswordQuality(STRONGOLDPW, "kjh8iabcddsf".toCharArray()).isEmpty(), "Password OK.");
    assertTrue(passwordQualityService.checkPasswordQuality(STRONGOLDPW, "  5     g ".toCharArray()).isEmpty(), "Password OK.");
}
Also used : I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams) ConfigurationDO(org.projectforge.framework.configuration.entities.ConfigurationDO) Test(org.junit.jupiter.api.Test)

Example 3 with I18nKeyAndParams

use of org.projectforge.framework.i18n.I18nKeyAndParams in project projectforge by micromata.

the class UserEditForm method addPasswordFields.

@SuppressWarnings("serial")
private void addPasswordFields() {
    // Password
    final FieldsetPanel fs = gridBuilder.newFieldset(getString("password"), getString("passwordRepeat"));
    final PasswordTextField passwordField = new PasswordTextField(fs.getTextFieldId(), new PropertyModel<>(this, "password")) {

        @Override
        protected void onComponentTag(final ComponentTag tag) {
            super.onComponentTag(tag);
            if (passwordUser == null) {
                tag.put("value", "");
            }
        }
    };
    passwordField.setMarkupId("password").setOutputMarkupId(true);
    passwordField.setResetPassword(false).setRequired(isNew());
    // Password repeat
    final PasswordTextField passwordRepeatField = new PasswordTextField(fs.getTextFieldId(), new PropertyModel<>(this, "passwordRepeat")) {

        @Override
        protected void onComponentTag(final ComponentTag tag) {
            super.onComponentTag(tag);
            if (passwordUser == null) {
                tag.put("value", "");
            }
        }
    };
    passwordRepeatField.setMarkupId("passwordRepeat").setOutputMarkupId(true);
    passwordRepeatField.setResetPassword(false).setRequired(false);
    // validation
    passwordRepeatField.add((INullAcceptingValidator<String>) validatable -> {
        final String passwordRepeatInput = validatable.getValue();
        passwordField.validate();
        final String passwordInput = passwordField.getConvertedInput();
        if (StringUtils.isEmpty(passwordInput) == true && StringUtils.isEmpty(passwordRepeatInput) == true) {
            passwordUser = null;
            return;
        }
        if (StringUtils.equals(passwordInput, passwordRepeatInput) == false) {
            passwordUser = null;
            validatable.error(new ValidationError().addKey("user.error.passwordAndRepeatDoesNotMatch"));
            return;
        }
        if (passwordUser == null) {
            final List<I18nKeyAndParams> errorMsgKeys = passwordQualityService.checkPasswordQuality(passwordInput.toCharArray());
            if (errorMsgKeys.isEmpty() == false) {
                for (I18nKeyAndParams errorMsgKey : errorMsgKeys) {
                    final String localizedMessage = I18nHelper.getLocalizedMessage(errorMsgKey);
                    validatable.error(new ValidationError().setMessage(localizedMessage));
                }
            } else {
                passwordUser = new PFUserDO();
                char[] pw = passwordInput.toCharArray();
                userService.createEncryptedPassword(passwordUser, pw);
                LoginHandler.clearPassword(pw);
            }
        }
    });
    WicketUtils.setPercentSize(passwordField, 50);
    WicketUtils.setPercentSize(passwordRepeatField, 50);
    fs.add(passwordField);
    fs.add(passwordRepeatField);
    final I18nKeyAndParams passwordQualityI18nKeyAndParams = passwordQualityService.getPasswordQualityI18nKeyAndParams();
    fs.addHelpIcon(I18nHelper.getLocalizedMessage(passwordQualityI18nKeyAndParams));
}
Also used : java.util(java.util) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) TimeNotation(org.projectforge.framework.time.TimeNotation) DateTimeFormatter(org.projectforge.framework.time.DateTimeFormatter) SimpleDateFormat(java.text.SimpleDateFormat) GroupDO(org.projectforge.framework.persistence.user.entities.GroupDO) StringUtils(org.apache.commons.lang3.StringUtils) Login(org.projectforge.business.login.Login) Gender(org.projectforge.framework.persistence.user.entities.Gender) GridBuilder(org.projectforge.web.wicket.bootstrap.GridBuilder) GroupService(org.projectforge.business.group.service.GroupService) LoginHandler(org.projectforge.business.login.LoginHandler) ThreadLocalUserContext(org.projectforge.framework.persistence.user.api.ThreadLocalUserContext) WicketUtils(org.projectforge.web.wicket.WicketUtils) ApplicationContextProvider(org.projectforge.framework.configuration.ApplicationContextProvider) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) AbstractEditForm(org.projectforge.web.wicket.AbstractEditForm) Const(org.projectforge.Const) I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams) Logger(org.slf4j.Logger) org.projectforge.web.wicket.components(org.projectforge.web.wicket.components) StringHelper(org.projectforge.common.StringHelper) GridSize(org.projectforge.web.wicket.bootstrap.GridSize) Model(org.apache.wicket.model.Model) AccessChecker(org.projectforge.framework.access.AccessChecker) WebConstants(org.projectforge.web.wicket.WebConstants) org.projectforge.business.user(org.projectforge.business.user) ValidationError(org.apache.wicket.validation.ValidationError) AttributeModifier(org.apache.wicket.AttributeModifier) ConfigurationService(org.projectforge.business.configuration.ConfigurationService) DivTextPanel(org.projectforge.web.wicket.flowlayout.DivTextPanel) IValidator(org.apache.wicket.validation.IValidator) Select2MultiChoice(org.wicketstuff.select2.Select2MultiChoice) PasswordQualityService(org.projectforge.business.password.PasswordQualityService) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) PropertyModel(org.apache.wicket.model.PropertyModel) MultiChoiceListHelper(org.projectforge.web.common.MultiChoiceListHelper) PFUserDO(org.projectforge.framework.persistence.user.entities.PFUserDO) org.apache.wicket.markup.html.form(org.apache.wicket.markup.html.form) UserService(org.projectforge.business.user.service.UserService) INullAcceptingValidator(org.apache.wicket.validation.INullAcceptingValidator) org.projectforge.business.ldap(org.projectforge.business.ldap) Configuration(org.projectforge.framework.configuration.Configuration) I18nHelper(org.projectforge.framework.i18n.I18nHelper) IFormValidator(org.apache.wicket.markup.html.form.validation.IFormValidator) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) ResourceModel(org.apache.wicket.model.ResourceModel) ComponentTag(org.apache.wicket.markup.ComponentTag) I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) ValidationError(org.apache.wicket.validation.ValidationError) PFUserDO(org.projectforge.framework.persistence.user.entities.PFUserDO)

Example 4 with I18nKeyAndParams

use of org.projectforge.framework.i18n.I18nKeyAndParams in project projectforge by micromata.

the class PasswordQualityServiceImpl method checkForCharsInPassword.

private void checkForCharsInPassword(final char[] password, final List<I18nKeyAndParams> result) {
    boolean letter = false;
    boolean nonLetter = false;
    for (int i = 0; i < password.length; i++) {
        final char ch = password[i];
        if (!letter && Character.isLetter(ch)) {
            letter = true;
        } else if (!nonLetter && !Character.isLetter(ch)) {
            nonLetter = true;
        }
    }
    if (!letter) {
        result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_CHARACTER_ERROR));
    }
    if (!nonLetter) {
        result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_NONCHAR_ERROR));
    }
}
Also used : I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams)

Example 5 with I18nKeyAndParams

use of org.projectforge.framework.i18n.I18nKeyAndParams in project projectforge by micromata.

the class PasswordQualityServiceImpl method validate.

private List<I18nKeyAndParams> validate(final char[] newPassword, final char[] oldPassword, final boolean checkOldPassword) {
    final List<I18nKeyAndParams> result = new ArrayList<>();
    // check min length
    final int minPasswordLength = configurationService.getMinPasswordLength();
    if (newPassword == null || newPassword.length < minPasswordLength) {
        result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_MIN_LENGTH_ERROR, configurationService.getMinPasswordLength()));
        if (newPassword == null) {
            return result;
        }
    }
    // check for character and none character
    checkForCharsInPassword(newPassword, result);
    // stop here if only the new password is validated
    if (!checkOldPassword) {
        return result;
    }
    // compare old and new password
    if (configurationService.getFlagCheckPasswordChange() && Arrays.equals(oldPassword, newPassword)) {
        result.add(new I18nKeyAndParams(MESSAGE_KEY_PASSWORD_OLD_EQ_NEW_ERROR));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) I18nKeyAndParams(org.projectforge.framework.i18n.I18nKeyAndParams)

Aggregations

I18nKeyAndParams (org.projectforge.framework.i18n.I18nKeyAndParams)8 Model (org.apache.wicket.model.Model)3 PropertyModel (org.apache.wicket.model.PropertyModel)3 IValidator (org.apache.wicket.validation.IValidator)3 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 StringUtils (org.apache.commons.lang3.StringUtils)2 AttributeModifier (org.apache.wicket.AttributeModifier)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 AjaxButton (org.apache.wicket.ajax.markup.html.form.AjaxButton)2 ComponentTag (org.apache.wicket.markup.ComponentTag)2 org.apache.wicket.markup.html.form (org.apache.wicket.markup.html.form)2 IFormValidator (org.apache.wicket.markup.html.form.validation.IFormValidator)2 ResourceModel (org.apache.wicket.model.ResourceModel)2 SpringBean (org.apache.wicket.spring.injection.annot.SpringBean)2 INullAcceptingValidator (org.apache.wicket.validation.INullAcceptingValidator)2 ValidationError (org.apache.wicket.validation.ValidationError)2 Const (org.projectforge.Const)2 ConfigurationService (org.projectforge.business.configuration.ConfigurationService)2 GroupService (org.projectforge.business.group.service.GroupService)2