Search in sources :

Example 6 with AttributeValidation

use of org.gluu.model.attribute.AttributeValidation in project oxTrust by GluuFederation.

the class UpdateAttributeAction method initAttribute.

private void initAttribute() {
    if (StringHelper.isEmpty(this.attribute.getSaml1Uri())) {
        String namespace;
        if (attribute.isCustom() || StringHelper.isEmpty(attribute.getUrn()) && attribute.getUrn().startsWith("urn:gluu:dir:attribute-def:")) {
            namespace = "gluu";
        } else {
            namespace = "mace";
        }
        this.attribute.setSaml1Uri(String.format("urn:%s:dir:attribute-def:%s", namespace, attribute.getName()));
    }
    if (StringHelper.isEmpty(this.attribute.getSaml2Uri())) {
        this.attribute.setSaml2Uri(attributeService.getDefaultSaml2Uri(attribute.getName()));
    }
    if (attribute.getAttributeValidation() == null) {
        attribute.setAttributeValidation(new AttributeValidation());
    }
    if (attribute.getAttributeValidation().getRegexp() == null || StringHelper.isEmpty(attribute.getAttributeValidation().getRegexp())) {
        this.validationToggle = false;
    } else {
        this.validationToggle = true;
    }
    if (attribute.getGluuTooltip() != null) {
        this.tooltipToggle = true;
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation)

Example 7 with AttributeValidation

use of org.gluu.model.attribute.AttributeValidation 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

AttributeValidation (org.gluu.model.attribute.AttributeValidation)7 FacesMessage (javax.faces.application.FacesMessage)5 UIInput (javax.faces.component.UIInput)4 GluuAttribute (org.gluu.model.GluuAttribute)4 ValidatorException (javax.faces.validator.ValidatorException)2 Pattern (java.util.regex.Pattern)1 LanguageBean (org.gluu.oxauth.i18n.LanguageBean)1 AttributeService (org.gluu.oxtrust.service.AttributeService)1 AttributeService (org.gluu.service.AttributeService)1