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);
}
}
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.");
}
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));
}
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));
}
}
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;
}
Aggregations