use of io.jans.scim.model.scim2.annotations.Validator in project oxTrust by GluuFederation.
the class ResourceValidator method validateValidableAttributes.
/**
* Inspects the resource passed in the constructor and applies validations for every attribute annotated with
* {@link Validator}. Validations are of different nature as seen{@link Validations here}.
* @throws SCIMException When a validation does not pass (the {@link Validations#apply(Validations, Object) apply}
* method returns false)
*/
public void validateValidableAttributes() throws SCIMException {
Map<String, List<Method>> map = IntrospectUtil.validableCoreAttrs.get(resourceClass);
for (String attributePath : map.keySet()) {
Field f = IntrospectUtil.findFieldFromPath(resourceClass, attributePath);
Validations valToApply = f.getAnnotation(Validator.class).value();
log.debug("Validating value(s) of attribute '{}'", attributePath);
for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath))) {
if (val != null && !Validations.apply(valToApply, val)) {
log.error("Error validating attribute '{}', wrong value supplied: '{}'", attributePath, val.toString());
throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attributePath));
}
}
}
}
use of io.jans.scim.model.scim2.annotations.Validator in project jans by JanssenProject.
the class IntrospectUtil method traverseClassForNames.
private static void traverseClassForNames(Class clazz, String prefix, List<Field> extraFields, boolean prune) throws Exception {
List<Field> fields = new ArrayList<>();
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
fields.addAll(extraFields);
for (Field f : fields) {
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null) {
String name = f.getName();
if (prefix.length() > 0)
name = prefix + "." + name;
switch(attrAnnot.returned()) {
case ALWAYS:
alwaysAttrsNames.add(name);
break;
case DEFAULT:
defaultAttrsNames.add(name);
break;
case NEVER:
neverAttrsNames.add(name);
break;
case REQUEST:
requestAttrsNames.add(name);
break;
}
if (attrAnnot.isRequired())
requiredAttrsNames.add(name);
if (attrAnnot.canonicalValues().length > 0)
canonicalizedAttrsNames.add(name);
Validator vAnnot = f.getAnnotation(Validator.class);
if (vAnnot != null)
validableAttrsNames.add(name);
if (!prune && attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX)) {
// Use <T> parameter of Collection if present
Class cls = attrAnnot.multiValueClass();
if (cls.equals(NullType.class)) {
cls = f.getType();
}
if (clazz.equals(cls)) {
// Prevent infinite loop
prune = true;
}
traverseClassForNames(cls, name, new ArrayList<>(), prune);
}
}
}
}
use of io.jans.scim.model.scim2.annotations.Validator in project oxTrust by GluuFederation.
the class IntrospectUtil method traverseClassForNames.
private static void traverseClassForNames(Class clazz, String prefix, List<Field> extraFields, boolean prune) throws Exception {
List<Field> fields = new ArrayList<Field>();
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
fields.addAll(extraFields);
for (Field f : fields) {
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null) {
String name = f.getName();
if (prefix.length() > 0)
name = prefix + "." + name;
switch(attrAnnot.returned()) {
case ALWAYS:
alwaysAttrsNames.add(name);
break;
case DEFAULT:
defaultAttrsNames.add(name);
break;
case NEVER:
neverAttrsNames.add(name);
break;
case REQUEST:
requestAttrsNames.add(name);
break;
}
if (attrAnnot.isRequired())
requiredAttrsNames.add(name);
if (attrAnnot.canonicalValues().length > 0)
canonicalizedAttrsNames.add(name);
Validator vAnnot = f.getAnnotation(Validator.class);
if (vAnnot != null)
validableAttrsNames.add(name);
if (!prune && attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX)) {
// Use <T> parameter of Collection if present
Class cls = attrAnnot.multiValueClass();
if (cls.equals(NullType.class))
cls = f.getType();
if (// Prevent infinite loop
clazz.equals(cls))
prune = true;
traverseClassForNames(cls.equals(NullType.class) ? f.getType() : cls, name, new ArrayList<Field>(), prune);
}
}
}
}
use of io.jans.scim.model.scim2.annotations.Validator in project jans by JanssenProject.
the class ResourceValidator method validateValidableAttributes.
/**
* Inspects the resource passed in the constructor and applies validations for every attribute annotated with
* {@link Validator}. Validations are of different nature as seen{@link Validations here}.
* @throws SCIMException When a validation does not pass (the {@link Validations#apply(Validations, Object) apply}
* method returns false)
*/
public void validateValidableAttributes() throws SCIMException {
Map<String, List<Method>> map = IntrospectUtil.validableCoreAttrs.get(resourceClass);
for (String attributePath : map.keySet()) {
Field f = IntrospectUtil.findFieldFromPath(resourceClass, attributePath);
Validations valToApply = f.getAnnotation(Validator.class).value();
log.debug("Validating value(s) of attribute '{}'", attributePath);
for (Object val : IntrospectUtil.getAttributeValues(resource, map.get(attributePath))) {
if (val != null && !Validations.apply(valToApply, val)) {
log.error("Error validating attribute '{}', wrong value supplied: '{}'", attributePath, val.toString());
throw new SCIMException(String.format(ATTR_VALIDATION_FAILED, attributePath));
}
}
}
}
Aggregations