Search in sources :

Example 6 with BaseScimResource

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

the class GroupWebService method searchGroups.

@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@QueryParam(QUERY_PARAM_FILTER) String filter, @QueryParam(QUERY_PARAM_START_INDEX) Integer startIndex, @QueryParam(QUERY_PARAM_COUNT) Integer count, @QueryParam(QUERY_PARAM_SORT_BY) String sortBy, @QueryParam(QUERY_PARAM_SORT_ORDER) String sortOrder, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. searchGroups");
        sortBy = translateSortByAttribute(GroupResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = scim2GroupService.searchGroups(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, userWebService.getEndpointUrl(), getMaxCount());
        String json = getListResponseSerialized(resources.getTotalResults(), startIndex, resources.getResult(), attrsList, excludedAttrsList, count == 0);
        response = Response.ok(json).location(new URI(endpointUrl)).build();
    } catch (SCIMException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at searchGroups method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) URI(java.net.URI) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 7 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource 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 8 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource 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 9 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource 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 10 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource 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)

Aggregations

Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)12 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)6 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 Response (javax.ws.rs.core.Response)5 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 DefaultValue (javax.ws.rs.DefaultValue)3 GET (javax.ws.rs.GET)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)3 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)3