Search in sources :

Example 1 with Extension

use of io.jans.scim.model.scim2.extensions.Extension in project oxTrust by GluuFederation.

the class ResourceTypeWS method getUserResourceType.

private ResourceType getUserResourceType() {
    Class<? extends BaseScimResource> cls = UserResource.class;
    List<Extension> usrExtensions = extService.getResourceExtensions(cls);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    for (Extension extension : usrExtensions) {
        SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
        userExtensionSchema.setSchema(extension.getUrn());
        userExtensionSchema.setRequired(false);
        schemaExtensions.add(userExtensionSchema);
    }
    ResourceType usrRT = new ResourceType();
    fillResourceType(usrRT, ScimResourceUtil.getSchemaAnnotation(cls), userService.getEndpointUrl(), getResourceLocation(USER_SUFFIX), schemaExtensions);
    return usrRT;
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.provider.resourcetypes.SchemaExtensionHolder) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) ArrayList(java.util.ArrayList) ResourceType(org.gluu.oxtrust.model.scim2.provider.resourcetypes.ResourceType)

Example 2 with Extension

use of io.jans.scim.model.scim2.extensions.Extension 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 3 with Extension

use of io.jans.scim.model.scim2.extensions.Extension 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 4 with Extension

use of io.jans.scim.model.scim2.extensions.Extension 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 5 with Extension

use of io.jans.scim.model.scim2.extensions.Extension 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)

Aggregations

Extension (io.jans.scim.model.scim2.extensions.Extension)14 Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)14 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)7 ArrayList (java.util.ArrayList)5 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)5 HashMap (java.util.HashMap)4 SCIMException (io.jans.scim.model.exception.SCIMException)3 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)3 Attribute (io.jans.scim.model.scim2.annotations.Attribute)2 SchemaAttribute (io.jans.scim.model.scim2.provider.schema.SchemaAttribute)2 SchemaResource (io.jans.scim.model.scim2.provider.schema.SchemaResource)2 UserResource (io.jans.scim.model.scim2.user.UserResource)2 PostConstruct (javax.annotation.PostConstruct)2 NullType (javax.lang.model.type.NullType)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GluuAttribute (io.jans.model.GluuAttribute)1