Search in sources :

Example 11 with Schema

use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.

the class ResourceValidator method validateSchemasAttribute.

/**
 * Inspects the {@link BaseScimResource#getSchemas() schemas} attribute of the resource passed in the constructor and
 * checks the default schema <code>urn</code> associated to the resource type is present in the list. If some of the
 * <code>urn</code>s part of the <code>Extension</code>s passed in the constructor are contained in the list, the validation is also
 * successful.
 * <p>This method should be called after a successful call to {@link #validateRequiredAttributes()}.</p>
 * @throws SCIMException If there is no {@link BaseScimResource#getSchemas() schemas} in this resource or if some of
 * the <code>urn</code>s there are not known.
 */
public void validateSchemasAttribute() throws SCIMException {
    Set<String> schemaList = new HashSet<String>(resource.getSchemas());
    if (schemaList.size() == 0)
        throw new SCIMException(WRONG_SCHEMAS_ATTR);
    Set<String> allSchemas = new HashSet<String>();
    allSchemas.add(ScimResourceUtil.getDefaultSchemaUrn(resourceClass));
    for (Extension ext : extensions) allSchemas.add(ext.getUrn());
    schemaList.removeAll(allSchemas);
    if (// means that some wrong extension urn is there
    schemaList.size() > 0)
        throw new SCIMException(WRONG_SCHEMAS_ATTR);
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 12 with Schema

use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.

the class GroupCoreLoadingStrategy 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);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
    serializer.setSchemaType(schemaType);
    groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
    mapper.registerModule(groupCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyGroup());
    return serializer.getSchemaType();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaTypeGroupSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeGroupSerializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 13 with Schema

use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.

the class UserCoreLoadingStrategy 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);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyUser());
    return serializer.getSchemaType();
}
Also used : SchemaTypeUserSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeUserSerializer) Meta(org.gluu.oxtrust.model.scim2.Meta) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 14 with Schema

use of org.gluu.oxtrust.model.scim2.annotations.Schema 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 15 with Schema

use of org.gluu.oxtrust.model.scim2.annotations.Schema in project oxTrust by GluuFederation.

the class FilterUtil method stripScim2Schema.

public static String stripScim2Schema(String uri) {
    for (SchemaType schemaType : SchemaTypeMapping.getSchemaInstances()) {
        String schema = schemaType.getId() + ":";
        if (uri.startsWith(schema)) {
            int index = uri.indexOf(schema) + schema.length();
            uri = uri.substring(index);
            break;
        }
    }
    return uri;
}
Also used : SchemaType(org.gluu.oxtrust.model.scim2.schema.SchemaType)

Aggregations

ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)7 ArrayList (java.util.ArrayList)6 Response (javax.ws.rs.core.Response)6 Meta (org.gluu.oxtrust.model.scim2.Meta)6 URI (java.net.URI)5 DefaultValue (javax.ws.rs.DefaultValue)4 GET (javax.ws.rs.GET)4 HeaderParam (javax.ws.rs.HeaderParam)4 Produces (javax.ws.rs.Produces)4 Version (org.codehaus.jackson.Version)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)3 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)3 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)3 IOException (java.io.IOException)2 JsonNode (org.codehaus.jackson.JsonNode)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)2