Search in sources :

Example 36 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource 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 37 with BaseScimResource

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

Example 38 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.

the class SchemaWebService method getSchemaById.

@GET
@Path("{schemaUrn}")
@Produces(MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT)
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@RejectFilterParam
public Response getSchemaById(@PathParam("schemaUrn") String urn) {
    Response response;
    try {
        Class<? extends BaseScimResource> cls = resourceSchemas.get(urn);
        if (cls == null) {
            log.info("Schema urn {} not recognized", urn);
            response = Response.status(Response.Status.NOT_FOUND).build();
        } else {
            String json = resourceSerializer.serialize(getSchemaInstance(cls, urn));
            URI location = new URI(endpointUrl + "/" + urn);
            response = Response.ok(json).location(location).build();
        }
    } catch (Exception e) {
        log.error("Failure at getSchemaById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) 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) RejectFilterParam(io.jans.scim.service.scim2.interceptor.RejectFilterParam)

Example 39 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.

the class Fido2DeviceWebService method searchDevices.

private PagedResult<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count) throws Exception {
    Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("jansId"), Fido2DeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}', userId '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count, userId);
    // Currently, searching with SUB scope in Couchbase requires some help (beyond use of baseDN)
    if (StringUtils.isNotEmpty(userId)) {
        ldapFilter = Filter.createANDFilter(ldapFilter, Filter.createEqualityFilter("personInum", userId));
    }
    PagedResult<GluuFido2Device> list;
    try {
        list = entryManager.findPagedEntries(fidoDeviceService.getDnForFido2Device(null, userId), GluuFido2Device.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, getMaxCount());
    } catch (Exception e) {
        log.info("Returning an empty listViewReponse");
        log.error(e.getMessage(), e);
        list = new PagedResult<>();
        list.setEntries(new ArrayList<>());
    }
    List<BaseScimResource> resources = new ArrayList<>();
    for (GluuFido2Device device : list.getEntries()) {
        Fido2DeviceResource scimDev = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, scimDev, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
    PagedResult<BaseScimResource> result = new PagedResult<>();
    result.setEntries(resources);
    result.setTotalEntriesCount(list.getTotalEntriesCount());
    return result;
}
Also used : Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) PagedResult(io.jans.orm.model.PagedResult)

Example 40 with BaseScimResource

use of io.jans.scim.model.scim2.BaseScimResource in project jans by JanssenProject.

the class GroupWebService method doSearchGroups.

private Response doSearchGroups(String filter, Integer startIndex, Integer count, String sortBy, String sortOrder, String attrsList, String excludedAttrsList, String method, boolean fillMembersDisplay) {
    Response response;
    try {
        SearchRequest searchReq = new SearchRequest();
        response = prepareSearchRequest(searchReq.getSchemas(), filter, sortBy, sortOrder, startIndex, count, attrsList, excludedAttrsList, searchReq);
        if (response != null)
            return response;
        response = externalConstraintsService.applySearchCheck(searchReq, httpHeaders, uriInfo, method, groupResourceType);
        if (response != null)
            return response;
        PagedResult<BaseScimResource> resources = scim2GroupService.searchGroups(searchReq.getFilter(), translateSortByAttribute(GroupResource.class, searchReq.getSortBy()), SortOrder.getByValue(searchReq.getSortOrder()), searchReq.getStartIndex(), searchReq.getCount(), endpointUrl, usersUrl, getMaxCount(), fillMembersDisplay);
        String json = getListResponseSerialized(resources.getTotalEntriesCount(), searchReq.getStartIndex(), resources.getEntries(), searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 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 : Response(javax.ws.rs.core.Response) SearchRequest(io.jans.scim.model.scim2.SearchRequest) SCIMException(io.jans.scim.model.exception.SCIMException) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) URI(java.net.URI) GroupResource(io.jans.scim.model.scim2.group.GroupResource) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Aggregations

BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)12 Extension (io.jans.scim.model.scim2.extensions.Extension)12 ArrayList (java.util.ArrayList)12 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)12 Response (javax.ws.rs.core.Response)11 SCIMException (io.jans.scim.model.exception.SCIMException)10 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 URI (java.net.URI)8 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)7 ListResponse (io.jans.scim.model.scim2.ListResponse)6 URISyntaxException (java.net.URISyntaxException)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 SearchRequest (io.jans.scim.model.scim2.SearchRequest)5 UserResource (io.jans.scim.model.scim2.user.UserResource)5 PagedResult (io.jans.orm.model.PagedResult)4 Filter (io.jans.orm.search.filter.Filter)4 Attribute (io.jans.scim.model.scim2.annotations.Attribute)4 DefaultValue (javax.ws.rs.DefaultValue)4 GET (javax.ws.rs.GET)4 HeaderParam (javax.ws.rs.HeaderParam)4