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