Search in sources :

Example 1 with EqualPasswordInputValidator

use of org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator in project ocvn by devgateway.

the class EditUserPage method onInitialize.

@Override
protected void onInitialize() {
    Person person = SecurityUtil.getCurrentAuthenticatedPerson();
    if (!SecurityUtil.isCurrentUserAdmin()) {
        if (person.getId() != getPageParameters().get(WebConstants.PARAM_ID).toLong()) {
            setResponsePage(getApplication().getHomePage());
        }
    }
    super.onInitialize();
    userName.required();
    userName.getField().add(new UsernamePatternValidator());
    StringValue idPerson = getPageParameters().get(WebConstants.PARAM_ID);
    if (!idPerson.isNull()) {
        userName.getField().add(new UniqueUsernameValidator(idPerson.toLong()));
    } else {
        userName.getField().add(new UniqueUsernameValidator());
    }
    userName.setIsFloatedInput(true);
    editForm.add(userName);
    MetaDataRoleAuthorizationStrategy.authorize(userName, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);
    firstName.required();
    firstName.setIsFloatedInput(true);
    editForm.add(firstName);
    lastName.required();
    lastName.setIsFloatedInput(true);
    editForm.add(lastName);
    email.required();
    email.getField().add(EmailAddressValidator.getInstance());
    if (!idPerson.isNull()) {
        email.getField().add(new UniqueEmailAddressValidator(idPerson.toLong()));
    } else {
        email.getField().add(new UniqueEmailAddressValidator());
    }
    email.setIsFloatedInput(true);
    editForm.add(email);
    title.setIsFloatedInput(true);
    editForm.add(title);
    group.required();
    group.setIsFloatedInput(true);
    editForm.add(group);
    MetaDataRoleAuthorizationStrategy.authorize(group, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    editForm.add(defaultDashboard);
    MetaDataRoleAuthorizationStrategy.authorize(defaultDashboard, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);
    roles.required();
    roles.getField().setOutputMarkupId(true);
    roles.setIsFloatedInput(true);
    editForm.add(roles);
    MetaDataRoleAuthorizationStrategy.authorize(roles, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    // stop resetting the password fields each time they are rendered
    password.getField().setResetPassword(false);
    cpassword.getField().setResetPassword(false);
    if (SecurityUtil.isCurrentUserAdmin() && !SecurityUtil.isUserAdmin(compoundModel.getObject()) && idPerson.isNull()) {
        // hide the change password checkbox and set it's model to true
        compoundModel.getObject().setChangePass(true);
        changePass.setVisibilityAllowed(false);
    } else {
        compoundModel.getObject().setChangePass(compoundModel.getObject().getChangePassword());
        password.getField().setEnabled(compoundModel.getObject().getChangePassword());
        cpassword.getField().setEnabled(compoundModel.getObject().getChangePassword());
    }
    changePass.setIsFloatedInput(true);
    editForm.add(changePass);
    password.getField().add(new PasswordPatternValidator());
    password.setOutputMarkupId(true);
    password.setIsFloatedInput(true);
    editForm.add(password);
    cpassword.setOutputMarkupId(true);
    cpassword.setIsFloatedInput(true);
    editForm.add(cpassword);
    editForm.add(new EqualPasswordInputValidator(password.getField(), cpassword.getField()));
    enabled.setIsFloatedInput(true);
    editForm.add(enabled);
    MetaDataRoleAuthorizationStrategy.authorize(enabled, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    changePassword.setIsFloatedInput(true);
    editForm.add(changePassword);
    MetaDataRoleAuthorizationStrategy.authorize(changePassword, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    MetaDataRoleAuthorizationStrategy.authorize(deleteButton, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
}
Also used : StringValue(org.apache.wicket.util.string.StringValue) Person(org.devgateway.toolkit.persistence.dao.Person) EqualPasswordInputValidator(org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator)

Example 2 with EqualPasswordInputValidator

use of org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator in project oc-explorer by devgateway.

the class EditUserPage method onInitialize.

@Override
protected void onInitialize() {
    Person person = SecurityUtil.getCurrentAuthenticatedPerson();
    if (!SecurityUtil.isCurrentUserAdmin()) {
        if (person.getId() != getPageParameters().get(WebConstants.PARAM_ID).toLong()) {
            setResponsePage(getApplication().getHomePage());
        }
    }
    super.onInitialize();
    userName.required();
    userName.getField().add(new UsernamePatternValidator());
    StringValue idPerson = getPageParameters().get(WebConstants.PARAM_ID);
    if (!idPerson.isNull()) {
        userName.getField().add(new UniqueUsernameValidator(idPerson.toLong()));
    } else {
        userName.getField().add(new UniqueUsernameValidator());
    }
    userName.setIsFloatedInput(true);
    editForm.add(userName);
    MetaDataRoleAuthorizationStrategy.authorize(userName, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);
    firstName.required();
    firstName.setIsFloatedInput(true);
    editForm.add(firstName);
    lastName.required();
    lastName.setIsFloatedInput(true);
    editForm.add(lastName);
    email.required();
    email.getField().add(EmailAddressValidator.getInstance());
    if (!idPerson.isNull()) {
        email.getField().add(new UniqueEmailAddressValidator(idPerson.toLong()));
    } else {
        email.getField().add(new UniqueEmailAddressValidator());
    }
    email.setIsFloatedInput(true);
    editForm.add(email);
    title.setIsFloatedInput(true);
    editForm.add(title);
    group.required();
    group.setIsFloatedInput(true);
    editForm.add(group);
    MetaDataRoleAuthorizationStrategy.authorize(group, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    editForm.add(defaultDashboard);
    MetaDataRoleAuthorizationStrategy.authorize(defaultDashboard, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);
    roles.required();
    roles.getField().setOutputMarkupId(true);
    roles.setIsFloatedInput(true);
    editForm.add(roles);
    MetaDataRoleAuthorizationStrategy.authorize(roles, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    // stop resetting the password fields each time they are rendered
    password.getField().setResetPassword(false);
    cpassword.getField().setResetPassword(false);
    if (SecurityUtil.isCurrentUserAdmin() && !SecurityUtil.isUserAdmin(compoundModel.getObject()) && idPerson.isNull()) {
        // hide the change password checkbox and set it's model to true
        compoundModel.getObject().setChangePass(true);
        changePass.setVisibilityAllowed(false);
    } else {
        compoundModel.getObject().setChangePass(compoundModel.getObject().getChangePassword());
        password.getField().setEnabled(compoundModel.getObject().getChangePassword());
        cpassword.getField().setEnabled(compoundModel.getObject().getChangePassword());
    }
    changePass.setIsFloatedInput(true);
    editForm.add(changePass);
    password.getField().add(new PasswordPatternValidator());
    password.setOutputMarkupId(true);
    password.setIsFloatedInput(true);
    editForm.add(password);
    cpassword.setOutputMarkupId(true);
    cpassword.setIsFloatedInput(true);
    editForm.add(cpassword);
    editForm.add(new EqualPasswordInputValidator(password.getField(), cpassword.getField()));
    enabled.setIsFloatedInput(true);
    editForm.add(enabled);
    MetaDataRoleAuthorizationStrategy.authorize(enabled, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    changePassword.setIsFloatedInput(true);
    editForm.add(changePassword);
    MetaDataRoleAuthorizationStrategy.authorize(changePassword, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
    MetaDataRoleAuthorizationStrategy.authorize(deleteButton, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);
}
Also used : StringValue(org.apache.wicket.util.string.StringValue) Person(org.devgateway.toolkit.persistence.dao.Person) EqualPasswordInputValidator(org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator)

Example 3 with EqualPasswordInputValidator

use of org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator in project the-app by devops-dojo.

the class RegistrationPage method loginData.

private Component loginData() {
    Form<UserInfo> loginData = new Form<>("registration");
    loginData.add(firstnameField());
    loginData.add(lastnameField());
    loginData.add(usernameField());
    PasswordTextField password = passwordField();
    loginData.add(password);
    PasswordTextField repeatPassword = passwordRepeatField();
    loginData.add(repeatPassword);
    loginData.add(new EqualPasswordInputValidator(password, repeatPassword));
    loginData.add(streetField());
    loginData.add(zipField());
    loginData.add(cityField());
    loginData.add(submitLink());
    loginData.add(emailField());
    return loginData;
}
Also used : UserInfo(io.github.zutherb.appstash.shop.service.user.model.UserInfo) EqualPasswordInputValidator(org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator)

Aggregations

EqualPasswordInputValidator (org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator)3 StringValue (org.apache.wicket.util.string.StringValue)2 Person (org.devgateway.toolkit.persistence.dao.Person)2 UserInfo (io.github.zutherb.appstash.shop.service.user.model.UserInfo)1