THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
Note | ||
---|---|---|
| ||
The content below is for Apache Syncope <= 1.2 - for later versions the Reference Guide is available. |
Introduction
An attribute validator class is used to validate the value to be assigned to an attribute.
...
A sample validator has been provided below.
Code Block |
---|
package org.apache.syncope.core.persistence.validation.attrvalue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.syncope.core.persistence.beans.AbstractSchema;
import org.apache.syncope.core.persistence.beans.AbstractAttrValue;
public class EmailAddressValidator extends AbstractValidator {
private static final Pattern EMAIL_PATTERN = Pattern.compile(
"^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$",
Pattern.CASE_INSENSITIVE);
public EmailAddressValidator(final AbstractSchema schema) {
super(schema);
}
@Override
protected void doValidate(final AbstractAttrValue attributeValue)
throws InvalidAttrValueException {
Matcher matcher = EMAIL_PATTERN.matcher(
(CharSequence) attributeValue.getValue());
if (!matcher.matches()) {
throw new InvalidAttrValueException(attributeValue);
}
}
}
|
...