Search in sources :

Example 1 with UserExtensionSchema

use of org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema in project oxTrust by GluuFederation.

the class ResourceTypeWS method getResourceTypeUser.

@Path("User")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeUser(@HeaderParam("Authorization") String authorization) throws Exception {
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType};
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(userResourceType).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ArrayList(java.util.ArrayList) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with UserExtensionSchema

use of org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema in project oxTrust by GluuFederation.

the class ResourceTypeWS method listResources.

@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    // START: User
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // START: Group
    ResourceType groupResourceType = new ResourceType();
    groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
    groupResourceType.setEndpoint("/v2/Groups");
    groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
    Meta groupMeta = new Meta();
    groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    groupMeta.setResourceType("ResourceType");
    groupResourceType.setMeta(groupMeta);
    // START: FidoDevice
    ResourceType fidoDeviceResourceType = new ResourceType();
    fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
    fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
    fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
    Meta fidoDeviceMeta = new Meta();
    fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    fidoDeviceMeta.setResourceType("ResourceType");
    fidoDeviceResourceType.setMeta(fidoDeviceMeta);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
    List<Resource> resourceTypes = new ArrayList<Resource>();
    resourceTypes.add(userResourceType);
    resourceTypes.add(groupResourceType);
    resourceTypes.add(fidoDeviceResourceType);
    listResponse.setResources(resourceTypes);
    listResponse.setTotalResults(resourceTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(listResponse).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with UserExtensionSchema

use of org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema in project oxTrust by GluuFederation.

the class SchemaTypeUserSerializer method serialize.

@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (!(SchemaTypeMapping.getSchemaTypeInstance(rootNodeEntry.getKey()) instanceof UserExtensionSchema)) {
                if (rootNodeEntry.getValue() instanceof ObjectNode) {
                    if (rootNodeEntry.getKey().equalsIgnoreCase("name")) {
                        AttributeHolder attributeHolder = new AttributeHolder();
                        attributeHolder.setName(rootNodeEntry.getKey());
                        attributeHolder.setType("string");
                        attributeHolder.setDescription("Name object");
                        attributeHolder.setRequired(Boolean.FALSE);
                        List<AttributeHolder> nameAttributeHolders = new ArrayList<AttributeHolder>();
                        Iterator<Map.Entry<String, JsonNode>> nameIterator = rootNodeEntry.getValue().getFields();
                        while (nameIterator.hasNext()) {
                            Map.Entry<String, JsonNode> nameRootNodeEntry = nameIterator.next();
                            AttributeHolder nameAttributeHolder = new AttributeHolder();
                            nameAttributeHolder.setName(nameRootNodeEntry.getKey());
                            nameAttributeHolder.setType("string");
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("formatted")) {
                                nameAttributeHolder.setDescription("Formatted name on-the-fly for display. Using this in a query filter is not supported.");
                                nameAttributeHolder.setMutability("readOnly");
                            } else {
                                nameAttributeHolder.setDescription(nameRootNodeEntry.getKey());
                            }
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("givenName") || nameRootNodeEntry.getKey().equalsIgnoreCase("familyName")) {
                                nameAttributeHolder.setRequired(true);
                            } else {
                                nameAttributeHolder.setRequired(false);
                            }
                            nameAttributeHolders.add(nameAttributeHolder);
                        }
                        attributeHolder.setSubAttributes(nameAttributeHolders);
                        attributeHolders.add(attributeHolder);
                    }
                } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                    AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                    arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("groups")) {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("Group");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    } else {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                    }
                    arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                    arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                        arrayNodeAttributeHolder.setUniqueness("server");
                        arrayNodeAttributeHolder.setType("string");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        arrayNodeAttributeHolder.setReturned("always");
                    } else {
                        arrayNodeAttributeHolder.setType("complex");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("photos")) {
                        arrayNodeAttributeHolder.setType("reference");
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("uri");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    }
                    List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                    Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                    while (arrayNodeIterator.hasNext()) {
                        JsonNode jsonNode = arrayNodeIterator.next();
                        Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                        while (arrayNodeMapIterator.hasNext()) {
                            Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                            AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                            if (rootNodeEntry.getKey().equalsIgnoreCase("groups") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                                arrayNodeMapAttributeHolder.setName("$ref");
                            } else {
                                arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                            }
                            arrayNodeMapAttributeHolder.setType("string");
                            arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                            } else {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                            }
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsImageDataURI") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsURI")) {
                                arrayNodeMapAttributeHolder.setMutability("readOnly");
                                arrayNodeMapAttributeHolder.setType("reference");
                                List<String> referenceTypes = new ArrayList<String>();
                                referenceTypes.add("uri");
                                arrayNodeMapAttributeHolder.setReferenceTypes(referenceTypes);
                            }
                            arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                        }
                        arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                        attributeHolders.add(arrayNodeAttributeHolder);
                    }
                } else {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("userName") || rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setRequired(Boolean.TRUE);
                    } else {
                        attributeHolder.setRequired(Boolean.FALSE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("userName")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("externalId") || rootNodeEntry.getKey().equalsIgnoreCase("password")) {
                        attributeHolder.setCaseExact(Boolean.TRUE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setMutability("readOnly");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        UserCoreSchema userCoreSchema = (UserCoreSchema) schemaType;
        userCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = userCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the User class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) IOException(java.io.IOException) UserExtensionSchema(org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema) Iterator(java.util.Iterator) UserCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.UserCoreSchema) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 4 with UserExtensionSchema

use of org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema in project oxTrust by GluuFederation.

the class UserExtensionLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
    List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
    List<AttributeHolder> attributeHolders = new ArrayList<AttributeHolder>();
    for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
        AttributeHolder attributeHolder = new AttributeHolder();
        attributeHolder.setName(scimCustomAttribute.getName());
        if (scimCustomAttribute.getDataType() != null) {
            String typeStr = "";
            GluuAttributeDataType attributeDataType = scimCustomAttribute.getDataType();
            if (attributeDataType.equals(GluuAttributeDataType.STRING)) {
                typeStr = "string";
            } else if (attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                typeStr = "reference";
                attributeHolder.getReferenceTypes().add("external");
            } else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
                typeStr = "dateTime";
            } else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                typeStr = "decimal";
            } else {
                log.info(" NO MATCH: scimCustomAttribute.getDataType().getDisplayName() = " + scimCustomAttribute.getDataType().getDisplayName());
                typeStr = "string";
            }
            attributeHolder.setType(typeStr);
        }
        attributeHolder.setDescription(scimCustomAttribute.getDescription());
        attributeHolder.setRequired(scimCustomAttribute.isRequred());
        if (scimCustomAttribute.getOxMultivaluedAttribute() != null) {
            Boolean multiValued = Boolean.parseBoolean(scimCustomAttribute.getOxMultivaluedAttribute().getValue());
            attributeHolder.setMultiValued(multiValued);
        }
        attributeHolders.add(attributeHolder);
    }
    UserExtensionSchema userExtensionSchema = (UserExtensionSchema) schemaType;
    userExtensionSchema.setAttributeHolders(attributeHolders);
    return userExtensionSchema;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ArrayList(java.util.ArrayList) UserExtensionSchema(org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) GluuAttribute(org.xdi.model.GluuAttribute)

Example 5 with UserExtensionSchema

use of org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema in project oxTrust by GluuFederation.

the class UserSerializer method serialize.

@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        jsonGenerator.writeStartObject();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            jsonGenerator.writeFieldName(rootNodeEntry.getKey());
            if (SchemaTypeMapping.getSchemaTypeInstance(rootNodeEntry.getKey()) instanceof UserExtensionSchema) {
                serializeUserExtension(rootNodeEntry, mapper, user, jsonGenerator);
            } else {
                jsonGenerator.writeObject(rootNodeEntry.getValue());
            }
        }
        jsonGenerator.writeEndObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : UserExtensionSchema(org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException)

Aggregations

ArrayList (java.util.ArrayList)4 Meta (org.gluu.oxtrust.model.scim2.Meta)3 UserExtensionSchema (org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Map (java.util.Map)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 HeaderParam (javax.ws.rs.HeaderParam)2 Produces (javax.ws.rs.Produces)2 JsonNode (org.codehaus.jackson.JsonNode)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)2 AttributeHolder (org.gluu.oxtrust.model.scim2.schema.AttributeHolder)2 SchemaExtensionHolder (org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Path (javax.ws.rs.Path)1 ArrayNode (org.codehaus.jackson.node.ArrayNode)1