use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class ExtensionService method extensionOfAttribute.
public Extension extensionOfAttribute(Class<? extends BaseScimResource> cls, String attribute) {
List<Extension> extensions = getResourceExtensions(cls);
Extension belong = null;
try {
for (Extension ext : extensions) {
if (attribute.startsWith(ext.getUrn() + ":")) {
attribute = attribute.substring(ext.getUrn().length() + 1);
for (String fieldName : ext.getFields().keySet()) if (attribute.equals(fieldName)) {
belong = ext;
break;
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return belong;
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class IntrospectUtil method computeGettersMap.
private static Map<String, List<Method>> computeGettersMap(List<String> attrNames, Class baseClass) throws Exception {
Map<String, List<Method>> map = new HashMap<>();
for (String attrName : attrNames) {
List<Method> list = new ArrayList<>();
Class clazz = baseClass;
for (String prop : attrName.split("\\.")) {
Method method = getGetter(prop, clazz);
list.add(method);
if (isCollection(method.getReturnType())) {
// Use class of parameter in collection
Field f = findField(clazz, prop);
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null)
clazz = attrAnnot.multiValueClass();
} else
clazz = method.getReturnType();
}
map.put(attrName, list);
}
return map;
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class ScimResourceUtil method deleteFromResource.
/**
* Returns a SCIM resource with the same data found in <code>origin</code> object, except for the attribute referenced
* by <code>path</code> being removed from the output. In other words, this method nullifies an attribute.
* @param origin The resource having the the original data
* @param path An attribute path (in dot notation). Examples could be: <code>displayName, emails.type, addresses,
* meta.lastModified</code>.
* @param extensions A list of <code>Extension</code>s associated to <code>origin</code> Object
* @return The resulting object: data in origin without the attribute referenced by <code>path</code>
* @throws InvalidAttributeValueException If there is an attempt to remove an attribute annotated as {@link Attribute#isRequired()
* required} or {@link io.jans.scim.model.scim2.AttributeDefinition.Mutability#READ_ONLY read-only}
*/
public static BaseScimResource deleteFromResource(BaseScimResource origin, String path, List<Extension> extensions) throws InvalidAttributeValueException {
Field f = IntrospectUtil.findFieldFromPath(origin.getClass(), path);
if (f != null) {
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null && (attrAnnot.mutability().equals(READ_ONLY) || attrAnnot.isRequired()))
throw new InvalidAttributeValueException("Cannot remove read-only or required attribute " + path);
}
Map<String, Object> map = mapper.convertValue(origin, new TypeReference<Map<String, Object>>() {
});
traversalClass tclass = new traversalClass(origin.getClass());
if (// Extensions stuff
f == null)
deleteCustomAttribute(map, path, extensions);
else
tclass.traverseDelete(map, path);
return mapper.convertValue(map, origin.getClass());
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class BaseScimWebService method assignMetaInformation.
protected void assignMetaInformation(BaseScimResource resource) {
// Generate some meta information (this replaces the info client passed in the request)
String val = DateUtil.millisToISOString(System.currentTimeMillis());
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(resource.getClass()));
meta.setCreated(val);
meta.setLastModified(val);
// For version attritute: Service provider support for this attribute is optional and subject to the service provider's support for versioning
// For location attribute: this will be set after current user creation in LDAP
resource.setMeta(meta);
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class SimpleExpression method evaluate.
public Boolean evaluate(Map<String, Object> item) {
/*
There are 3 categories for attribute operators:
- eq, ne (applicable to all types)
- co, sw, ew (applicable to STRING, REFERENCE)
- gt, ge, lt, le (applicable to STRING, DECIMAL, REFERENCE, DATETIME)
*/
Boolean val = null;
Type attrType = null;
log.trace("SimpleExpression.evaluate.");
String msg = String.format("%s%s", StringUtils.isEmpty(parentAttribute) ? "" : (parentAttribute + "."), resourceClass.getSimpleName());
Attribute attrAnnot = getAttributeAnnotation();
if (attrAnnot == null) {
if (extService != null) {
ExtensionField field = extService.getFieldOfExtendedAttribute(resourceClass, attribute);
if (field == null)
log.error("SimpleExpression.evaluate. Attribute '{}' is not recognized in {}", attribute, msg);
else
attrType = field.getAttributeDefinitionType();
}
} else
attrType = attrAnnot.type();
if (attrType == null) {
log.error("SimpleExpression.evaluate. Could not determine type of attribute '{}' in {}", attribute, msg);
} else {
String errMsg = FilterUtil.checkFilterConsistency(attribute, attrType, type, operator);
if (errMsg == null) {
Object currentAttrValue = item.get(attribute);
if (type.equals(CompValueType.NULL)) {
// implies attributeValue==null
log.trace("SimpleExpression.evaluate. Using null as compare value");
val = operator.equals(ScimOperator.EQUAL) ? currentAttrValue == null : currentAttrValue != null;
} else if (currentAttrValue == null) {
// If value is absent, filter won't match against anything (only when comparing with null as in previous case)
log.trace("SimpleExpression.evaluate. Attribute \"{}\" is absent in resource data", attribute);
val = false;
} else if (// check it's a string or reference
Type.STRING.equals(attrType) || Type.REFERENCE.equals(attrType))
val = evaluateStringAttribute(attrAnnot != null && attrAnnot.isCaseExact(), currentAttrValue);
else if (Type.INTEGER.equals(attrType) || Type.DECIMAL.equals(attrType))
val = evaluateNumericAttribute(attrType, currentAttrValue);
else if (Type.BOOLEAN.equals(attrType))
val = evaluateBooleanAttribute(attrType, currentAttrValue);
else if (Type.DATETIME.equals(attrType))
val = evaluateDateTimeAttribute(attrType, currentAttrValue);
} else
log.error("SimpleExpression.evaluate. {}", errMsg);
}
return val;
}
Aggregations