Search in sources :

Example 1 with SchemaAttribute

use of io.jans.scim.model.scim2.provider.schema.SchemaAttribute 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 SchemaAttribute

use of io.jans.scim.model.scim2.provider.schema.SchemaAttribute in project oxTrust by GluuFederation.

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz) throws Exception {
    SchemaResource resource;
    Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
    Schema annotation = ScimResourceUtil.getSchemaAnnotation(clazz);
    if (!clazz.equals(schemaCls) && annotation != null) {
        Meta meta = new Meta();
        meta.setResourceType(ScimResourceUtil.getType(schemaCls));
        meta.setLocation(endpointUrl + "/" + annotation.id());
        resource = new SchemaResource();
        resource.setId(annotation.id());
        resource.setName(annotation.name());
        resource.setDescription(annotation.description());
        resource.setMeta(meta);
        List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
        // paths are, happily alphabetically sorted :)
        for (String path : IntrospectUtil.allAttrs.get(clazz)) {
            SchemaAttribute schAttr = new SchemaAttribute();
            Field f = IntrospectUtil.findFieldFromPath(clazz, path);
            Attribute attrAnnot = f.getAnnotation(Attribute.class);
            if (attrAnnot != null) {
                JsonProperty jsonAnnot = f.getAnnotation(JsonProperty.class);
                schAttr.setName(jsonAnnot == null ? f.getName() : jsonAnnot.value());
                schAttr.setType(attrAnnot.type().getName());
                schAttr.setMultiValued(!attrAnnot.multiValueClass().equals(NullType.class) || IntrospectUtil.isCollection(f.getType()));
                schAttr.setDescription(attrAnnot.description());
                schAttr.setRequired(attrAnnot.isRequired());
                schAttr.setCanonicalValues(attrAnnot.canonicalValues().length == 0 ? null : Arrays.asList(attrAnnot.canonicalValues()));
                schAttr.setCaseExact(attrAnnot.isCaseExact());
                schAttr.setMutability(attrAnnot.mutability().getName());
                schAttr.setReturned(attrAnnot.returned().getName());
                schAttr.setUniqueness(attrAnnot.uniqueness().getName());
                schAttr.setReferenceTypes(attrAnnot.referenceTypes().length == 0 ? null : Arrays.asList(attrAnnot.referenceTypes()));
                if (attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX))
                    schAttr.setSubAttributes(new ArrayList<SchemaAttribute>());
                // root list
                List<SchemaAttribute> list = attribs;
                String[] parts = path.split("\\.");
                for (int i = 0; i < parts.length - 1; i++) {
                    // skip last part (real attribute name)
                    int j = list.indexOf(new SchemaAttribute(parts[i]));
                    list = list.get(j).getSubAttributes();
                }
                list.add(schAttr);
            }
        }
        resource.setAttributes(attribs);
    } else
        resource = null;
    return resource;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) JsonProperty(org.codehaus.jackson.annotate.JsonProperty) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) Schema(org.gluu.oxtrust.model.scim2.annotations.Schema) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) NullType(javax.lang.model.type.NullType) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) SchemaResource(org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)

Example 3 with SchemaAttribute

use of io.jans.scim.model.scim2.provider.schema.SchemaAttribute in project jans by JanssenProject.

the class SchemasTest method inspectUserExtensionSchema.

@Test(dependsOnMethods = "checkSchemasExistence")
public void inspectUserExtensionSchema() {
    Optional<SchemaResource> userExtSchemaOpt = listResponse.getResources().stream().map(SchemaResource.class::cast).filter(sr -> sr.getId().contains(USER_EXT_SCHEMA_ID)).findFirst();
    if (userExtSchemaOpt.isPresent()) {
        String name = userExtSchemaOpt.get().getName();
        assertNotNull(name);
        logger.info("Found User Schema Extension: {}", name);
        Boolean[] foundAttr = new Boolean[3];
        for (SchemaAttribute attribute : userExtSchemaOpt.get().getAttributes()) {
            switch(attribute.getName()) {
                case "scimCustomFirst":
                    foundAttr[0] = true;
                    logger.info("scimCustomFirst found");
                    assertEquals(attribute.getType(), "string");
                    assertFalse(attribute.isMultiValued());
                    break;
                case "scimCustomSecond":
                    foundAttr[1] = true;
                    logger.info("scimCustomSecond found");
                    assertEquals(attribute.getType(), "dateTime");
                    assertTrue(attribute.isMultiValued());
                    break;
                case "scimCustomThird":
                    foundAttr[2] = true;
                    logger.info("scimCustomThird found");
                    assertEquals(attribute.getType(), "decimal");
                    assertFalse(attribute.isMultiValued());
                    break;
            }
        }
        Arrays.asList(foundAttr).forEach(org.testng.Assert::assertTrue);
    } else
        logger.warn("There is no Schema Resource associated to User Schema Extension ({})", USER_EXT_SCHEMA_ID);
}
Also used : Arrays(java.util.Arrays) UserResource(io.jans.scim.model.scim2.user.UserResource) USER_EXT_SCHEMA_ID(io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) ArrayList(java.util.ArrayList) GroupResource(io.jans.scim.model.scim2.group.GroupResource) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) BeforeTest(org.testng.annotations.BeforeTest) List(java.util.List) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) ListResponse(io.jans.scim.model.scim2.ListResponse) Optional(java.util.Optional) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Assert(org.testng.Assert) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with SchemaAttribute

use of io.jans.scim.model.scim2.provider.schema.SchemaAttribute in project jans by JanssenProject.

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<>();
                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(io.jans.scim.model.scim2.extensions.Extension) Meta(io.jans.scim.model.scim2.Meta) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) ArrayList(java.util.ArrayList) AttributeDefinition(io.jans.scim.model.scim2.AttributeDefinition) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource)

Example 5 with SchemaAttribute

use of io.jans.scim.model.scim2.provider.schema.SchemaAttribute in project jans by JanssenProject.

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz) throws Exception {
    SchemaResource resource;
    Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
    Schema annotation = ScimResourceUtil.getSchemaAnnotation(clazz);
    if (!clazz.equals(schemaCls) && annotation != null) {
        Meta meta = new Meta();
        meta.setResourceType(ScimResourceUtil.getType(schemaCls));
        meta.setLocation(endpointUrl + "/" + annotation.id());
        resource = new SchemaResource();
        resource.setId(annotation.id());
        resource.setName(annotation.name());
        resource.setDescription(annotation.description());
        resource.setMeta(meta);
        List<SchemaAttribute> attribs = new ArrayList<>();
        // paths are, happily alphabetically sorted :)
        for (String path : IntrospectUtil.allAttrs.get(clazz)) {
            SchemaAttribute schAttr = new SchemaAttribute();
            Field f = IntrospectUtil.findFieldFromPath(clazz, path);
            Attribute attrAnnot = f.getAnnotation(Attribute.class);
            if (attrAnnot != null) {
                JsonProperty jsonAnnot = f.getAnnotation(JsonProperty.class);
                schAttr.setName(jsonAnnot == null ? f.getName() : jsonAnnot.value());
                schAttr.setType(attrAnnot.type().getName());
                schAttr.setMultiValued(!attrAnnot.multiValueClass().equals(NullType.class) || IntrospectUtil.isCollection(f.getType()));
                schAttr.setDescription(attrAnnot.description());
                schAttr.setRequired(attrAnnot.isRequired());
                schAttr.setCanonicalValues(attrAnnot.canonicalValues().length == 0 ? null : Arrays.asList(attrAnnot.canonicalValues()));
                schAttr.setCaseExact(attrAnnot.isCaseExact());
                schAttr.setMutability(attrAnnot.mutability().getName());
                schAttr.setReturned(attrAnnot.returned().getName());
                schAttr.setUniqueness(attrAnnot.uniqueness().getName());
                schAttr.setReferenceTypes(attrAnnot.referenceTypes().length == 0 ? null : Arrays.asList(attrAnnot.referenceTypes()));
                if (attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX))
                    schAttr.setSubAttributes(new ArrayList<>());
                // root list
                List<SchemaAttribute> list = attribs;
                String[] parts = path.split("\\.");
                for (int i = 0; i < parts.length - 1; i++) {
                    // skip last part (real attribute name)
                    int j = list.indexOf(new SchemaAttribute(parts[i]));
                    list = list.get(j).getSubAttributes();
                }
                list.add(schAttr);
            }
        }
        resource.setAttributes(attribs);
    } else
        resource = null;
    return resource;
}
Also used : Meta(io.jans.scim.model.scim2.Meta) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Attribute(io.jans.scim.model.scim2.annotations.Attribute) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) Schema(io.jans.scim.model.scim2.annotations.Schema) ArrayList(java.util.ArrayList) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) NullType(javax.lang.model.type.NullType) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource)

Aggregations

SchemaAttribute (io.jans.scim.model.scim2.provider.schema.SchemaAttribute)3 SchemaResource (io.jans.scim.model.scim2.provider.schema.SchemaResource)3 ArrayList (java.util.ArrayList)3 Meta (io.jans.scim.model.scim2.Meta)2 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)2 Field (java.lang.reflect.Field)2 NullType (javax.lang.model.type.NullType)2 Meta (org.gluu.oxtrust.model.scim2.Meta)2 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)2 SchemaAttribute (org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute)2 SchemaResource (org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 AttributeDefinition (io.jans.scim.model.scim2.AttributeDefinition)1 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)1 USER_EXT_SCHEMA_ID (io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID)1 ListResponse (io.jans.scim.model.scim2.ListResponse)1 Attribute (io.jans.scim.model.scim2.annotations.Attribute)1 Schema (io.jans.scim.model.scim2.annotations.Schema)1 Extension (io.jans.scim.model.scim2.extensions.Extension)1 Fido2DeviceResource (io.jans.scim.model.scim2.fido.Fido2DeviceResource)1