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