Search in sources :

Example 1 with AttributeService

use of org.gluu.oxtrust.service.AttributeService in project oxTrust by GluuFederation.

the class PasswordValidator method validate.

@Override
public void validate(FacesContext arg0, UIComponent arg1, Object value) throws ValidatorException {
    if (attributeService == null) {
        attributeService = CdiUtil.bean(AttributeService.class);
    }
    GluuAttribute attributeByName = attributeService.getAttributeByName(USER_PASSWORD);
    AttributeValidation validation = attributeByName.getAttributeValidation();
    if (validation != null && validation.getRegexp() != null && !validation.getRegexp().isEmpty()) {
        pattern = Pattern.compile(validation.getRegexp());
        hasValidation = true;
    }
    if (hasValidation) {
        matcher = pattern.matcher(value.toString());
    }
    if (hasValidation && !matcher.matches()) {
        FacesMessage msg = new FacesMessage(facesMessages.evalResourceAsString("#{msgs['password.validation.invalid']}"));
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation) ValidatorException(javax.faces.validator.ValidatorException) AttributeService(org.gluu.oxtrust.service.AttributeService) FacesMessage(javax.faces.application.FacesMessage) GluuAttribute(org.gluu.model.GluuAttribute)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)1 ValidatorException (javax.faces.validator.ValidatorException)1 GluuAttribute (org.gluu.model.GluuAttribute)1 AttributeValidation (org.gluu.model.attribute.AttributeValidation)1 AttributeService (org.gluu.oxtrust.service.AttributeService)1