Search in sources :

Example 1 with LanguageBean

use of org.gluu.oxauth.i18n.LanguageBean in project oxAuth by GluuFederation.

the class PasswordValidator method validate.

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    // This is workaround unless this bug will be fixed in JSF
    if (attributeService == null) {
        attributeService = CdiUtil.bean(AttributeService.class);
    }
    if (languageBean == null) {
        languageBean = CdiUtil.bean(LanguageBean.class);
    }
    AttributeValidation validation = attributeService.getAttributeByName(USER_PASSWORD).getAttributeValidation();
    if (validation != null) {
        String regexp = validation.getRegexp();
        if (regexp != null && !regexp.isEmpty()) {
            pattern = Pattern.compile(regexp);
            matcher = pattern.matcher(value.toString());
            hasValidation = true;
        }
    }
    if (hasValidation && !matcher.matches()) {
        String message = languageBean.getMessage("password.validation.invalid");
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
        context.validationFailed();
        ((UIInput) component).setValid(false);
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation) AttributeService(org.gluu.service.AttributeService) LanguageBean(org.gluu.oxauth.i18n.LanguageBean) FacesMessage(javax.faces.application.FacesMessage) UIInput(javax.faces.component.UIInput)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)1 UIInput (javax.faces.component.UIInput)1 AttributeValidation (org.gluu.model.attribute.AttributeValidation)1 LanguageBean (org.gluu.oxauth.i18n.LanguageBean)1 AttributeService (org.gluu.service.AttributeService)1