use of io.jans.scim.model.scim2.extensions.ExtensionField in project oxTrust by GluuFederation.
the class SchemaWebService method getSchemaInstance.
private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz, String urn) throws Exception {
if (ScimResourceUtil.getDefaultSchemaUrn(clazz).equals(urn))
// Process core attributes
return getSchemaInstance(clazz);
else {
// process extension attributes
SchemaResource resource = null;
Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
// Find the appropriate extension
List<Extension> extensions = extService.getResourceExtensions(clazz);
for (Extension extension : extensions) {
if (extension.getUrn().equals(urn)) {
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(schemaCls));
meta.setLocation(endpointUrl + "/" + urn);
resource = new SchemaResource();
resource.setId(urn);
resource.setName(extension.getName());
resource.setDescription(extension.getDescription());
resource.setMeta(meta);
List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
for (ExtensionField field : extension.getFields().values()) {
SchemaAttribute schAttr = new SchemaAttribute();
schAttr.setName(field.getName());
schAttr.setMultiValued(field.isMultiValued());
schAttr.setDescription(field.getDescription());
schAttr.setRequired(false);
schAttr.setCanonicalValues(null);
schAttr.setCaseExact(false);
schAttr.setMutability(AttributeDefinition.Mutability.READ_WRITE.getName());
schAttr.setReturned(AttributeDefinition.Returned.DEFAULT.getName());
schAttr.setUniqueness(AttributeDefinition.Uniqueness.NONE.getName());
schAttr.setReferenceTypes(null);
AttributeDefinition.Type type = field.getAttributeDefinitionType();
schAttr.setType(type == null ? null : type.getName());
schAttr.setSubAttributes(null);
attribs.add(schAttr);
}
resource.setAttributes(attribs);
break;
}
}
return resource;
}
}
use of io.jans.scim.model.scim2.extensions.ExtensionField in project oxTrust by GluuFederation.
the class ExtensionService method getResourceExtensions.
public List<Extension> getResourceExtensions(Class<? extends BaseScimResource> cls) {
List<Extension> list = new ArrayList<Extension>();
try {
// Currently support one extension only for User Resource
if (cls.equals(UserResource.class)) {
Map<String, ExtensionField> fields = new HashMap<String, ExtensionField>();
for (GluuAttribute attribute : attrService.getSCIMRelatedAttributes()) {
if (attribute.getOxSCIMCustomAttribute().equals(ScimCustomAtribute.TRUE)) {
// first non-null check is needed because certain entries do not have the multivalue attribute set
boolean multi = attribute.getOxMultivaluedAttribute() != null && attribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE);
ExtensionField field = new ExtensionField();
field.setDescription(attribute.getDescription());
field.setType(attribute.getDataType());
field.setMultiValued(multi);
field.setName(attribute.getName());
fields.put(attribute.getName(), field);
}
}
Extension ext = new Extension(USER_EXT_SCHEMA_ID);
ext.setFields(fields);
ext.setName(USER_EXT_SCHEMA_NAME);
ext.setDescription(USER_EXT_SCHEMA_DESCRIPTION);
list.add(ext);
}
} catch (Exception e) {
log.error("An error ocurred when building extension for {}", cls.getName());
log.error(e.getMessage(), e);
}
return list;
}
use of io.jans.scim.model.scim2.extensions.ExtensionField in project oxTrust by GluuFederation.
the class ExtensionService method getFieldOfExtendedAttribute.
public ExtensionField getFieldOfExtendedAttribute(Class<? extends BaseScimResource> cls, String attribute) {
List<Extension> extensions = getResourceExtensions(cls);
ExtensionField field = null;
try {
for (Extension ext : extensions) {
if (attribute.startsWith(ext.getUrn() + ":")) {
attribute = attribute.substring(ext.getUrn().length() + 1);
for (ExtensionField f : ext.getFields().values()) if (attribute.equals(f.getName())) {
field = f;
break;
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return field;
}
use of io.jans.scim.model.scim2.extensions.ExtensionField in project oxTrust by GluuFederation.
the class Scim2UserService method transferExtendedAttributesToResource.
private void transferExtendedAttributesToResource(GluuCustomPerson person, BaseScimResource resource) {
log.debug("transferExtendedAttributesToResource of type {}", ScimResourceUtil.getType(resource.getClass()));
// Gets the list of extensions associated to the resource passed. In practice, this will be at most a singleton list
List<Extension> extensions = extService.getResourceExtensions(resource.getClass());
// Iterate over every extension to copy extended attributes from person to resource
for (Extension extension : extensions) {
Map<String, ExtensionField> fields = extension.getFields();
// Create empty map to store the values of the extended attributes found for current extension in object person
Map<String, Object> map = new HashMap<String, Object>();
log.debug("transferExtendedAttributesToResource. Revising attributes of extension '{}'", extension.getUrn());
// Iterate over every attribute part of this extension
for (String attr : fields.keySet()) {
// Gets the values associated to this attribute that were found in LDAP
String[] values = person.getAttributes(attr);
if (values != null) {
log.debug("transferExtendedAttributesToResource. Copying to resource the value(s) for attribute '{}'", attr);
ExtensionField field = fields.get(attr);
if (field.isMultiValued())
map.put(attr, extService.convertValues(field, values));
else
map.put(attr, extService.convertValues(field, values).get(0));
}
}
// Stores all extended attributes (with their values) in the resource object
if (map.size() > 0) {
resource.addCustomAttributes(extension.getUrn(), map);
}
}
for (String urn : resource.getCustomAttributes().keySet()) resource.getSchemas().add(urn);
}
use of io.jans.scim.model.scim2.extensions.ExtensionField in project jans by JanssenProject.
the class ExtensionService method getFieldOfExtendedAttribute.
public ExtensionField getFieldOfExtendedAttribute(Class<? extends BaseScimResource> cls, String attribute) {
List<Extension> extensions = getResourceExtensions(cls);
ExtensionField field = null;
try {
for (Extension ext : extensions) {
if (attribute.startsWith(ext.getUrn() + ":")) {
attribute = attribute.substring(ext.getUrn().length() + 1);
for (ExtensionField f : ext.getFields().values()) if (attribute.equals(f.getName())) {
field = f;
break;
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return field;
}
Aggregations