Search in sources :

Example 1 with ExtensionField

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;
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) Meta(org.gluu.oxtrust.model.scim2.Meta) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) AttributeDefinition(org.gluu.oxtrust.model.scim2.AttributeDefinition) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) SchemaResource(org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)

Example 2 with ExtensionField

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;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) GluuAttribute(org.xdi.model.GluuAttribute)

Example 3 with ExtensionField

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;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField)

Example 4 with ExtensionField

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);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) HashMap(java.util.HashMap)

Example 5 with ExtensionField

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;
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField)

Aggregations

ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)8 Extension (io.jans.scim.model.scim2.extensions.Extension)7 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)7 Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)5 HashMap (java.util.HashMap)3 Type (io.jans.scim.model.scim2.AttributeDefinition.Type)2 Attribute (io.jans.scim.model.scim2.annotations.Attribute)2 CompValueType (io.jans.scim.service.antlr.scimFilter.enums.CompValueType)2 ArrayList (java.util.ArrayList)2 Type (org.gluu.oxtrust.model.scim2.AttributeDefinition.Type)2 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)2 CompValueType (org.gluu.oxtrust.service.antlr.scimFilter.enums.CompValueType)2 GluuAttribute (io.jans.model.GluuAttribute)1 Filter (io.jans.orm.search.filter.Filter)1 SCIMException (io.jans.scim.model.exception.SCIMException)1 AttributeDefinition (io.jans.scim.model.scim2.AttributeDefinition)1 Meta (io.jans.scim.model.scim2.Meta)1 SchemaAttribute (io.jans.scim.model.scim2.provider.schema.SchemaAttribute)1 SchemaResource (io.jans.scim.model.scim2.provider.schema.SchemaResource)1 ScimFilterParser (io.jans.scim.service.antlr.scimFilter.antlr4.ScimFilterParser)1