Search in sources :

Example 1 with Schema

use of io.jans.scim.model.scim2.annotations.Schema 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 2 with Schema

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

the class ResourceTypeWS method fillResourceType.

private void fillResourceType(ResourceType rt, Schema schemaAnnot, String endpointUrl, String location, List<SchemaExtensionHolder> schemaExtensions) {
    rt.setId(schemaAnnot.name());
    rt.setName(schemaAnnot.name());
    rt.setDescription(schemaAnnot.description());
    rt.setEndpoint(endpointUrl.substring(appConfiguration.getBaseEndpoint().length()));
    rt.setSchema(schemaAnnot.id());
    rt.setSchemaExtensions(schemaExtensions);
    Meta rtMeta = new Meta();
    rtMeta.setLocation(location);
    rtMeta.setResourceType("ResourceType");
    rt.setMeta(rtMeta);
}
Also used : Meta(io.jans.scim.model.scim2.Meta)

Example 3 with Schema

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

the class BaseScimWebService method prepareSearchRequest.

protected Response prepareSearchRequest(List<String> schemas, String filter, String sortBy, String sortOrder, Integer startIndex, Integer count, String attrsList, String excludedAttrsList, SearchRequest request) {
    Response response = null;
    if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(SEARCH_REQUEST_SCHEMA_ID)) {
        count = count == null ? getMaxCount() : count;
        // Per spec, a negative value SHALL be interpreted as "0" for count
        if (count < 0) {
            count = 0;
        }
        if (count <= getMaxCount()) {
            // SCIM searches are 1 indexed
            startIndex = (startIndex == null || startIndex < 1) ? 1 : startIndex;
            if (StringUtils.isEmpty(sortOrder) || !sortOrder.equals(SortOrder.DESCENDING.getValue())) {
                sortOrder = SortOrder.ASCENDING.getValue();
            }
            request.setSchemas(schemas);
            request.setAttributes(attrsList);
            request.setExcludedAttributes(excludedAttrsList);
            request.setFilter(filter);
            request.setSortBy(sortBy);
            request.setSortOrder(sortOrder);
            request.setStartIndex(startIndex);
            request.setCount(count);
        } else {
            response = getErrorResponse(BAD_REQUEST, ErrorScimType.TOO_MANY, "Maximum number of results per page is " + getMaxCount());
        }
    } else {
        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
    }
    return response;
}
Also used : ErrorResponse(io.jans.scim.model.scim2.ErrorResponse) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse)

Example 4 with Schema

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

the class BaseScimWebService method inspectPatchRequest.

protected Response inspectPatchRequest(PatchRequest patch, Class<? extends BaseScimResource> cls) {
    Response response = null;
    List<String> schemas = patch.getSchemas();
    if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(PATCH_REQUEST_SCHEMA_ID)) {
        List<PatchOperation> ops = patch.getOperations();
        if (ops != null) {
            // Adjust paths if they came prefixed
            String defSchema = ScimResourceUtil.getDefaultSchemaUrn(cls);
            List<String> urns = extService.getUrnsOfExtensions(cls);
            urns.add(defSchema);
            for (PatchOperation op : ops) {
                if (op.getPath() != null)
                    op.setPath(ScimResourceUtil.adjustNotationInPath(op.getPath(), defSchema, urns));
            }
            for (PatchOperation op : ops) {
                if (op.getType() == null)
                    response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Operation '" + op.getOperation() + "' not recognized");
                else {
                    String path = op.getPath();
                    if (StringUtils.isEmpty(path) && op.getType().equals(PatchOperationType.REMOVE))
                        response = getErrorResponse(BAD_REQUEST, ErrorScimType.NO_TARGET, "Path attribute is required for remove operation");
                    else if (op.getValue() == null && !op.getType().equals(PatchOperationType.REMOVE))
                        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Value attribute is required for operations other than remove");
                }
                if (response != null)
                    break;
            }
        } else
            response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Patch request MUST contain the attribute 'Operations'");
    } else
        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
    log.info("inspectPatchRequest. Preprocessing of patch request {}", response == null ? "passed" : "failed");
    return response;
}
Also used : ErrorResponse(io.jans.scim.model.scim2.ErrorResponse) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation)

Example 5 with Schema

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

the class Scim2GroupService method transferAttributesToGroup.

private void transferAttributesToGroup(GroupResource res, GluuGroup group, boolean skipMembersValidation, boolean fillMembersDisplay, String usersUrl) {
    // externalId (so jansExtId) not part of LDAP schema
    group.setAttribute("jansMetaCreated", res.getMeta().getCreated());
    group.setAttribute("jansMetaLastMod", res.getMeta().getLastModified());
    // When creating group, location will be set again when having an inum
    group.setAttribute("jansMetaLocation", res.getMeta().getLocation());
    group.setDisplayName(res.getDisplayName());
    group.setStatus(GluuStatus.ACTIVE);
    group.setOrganization(organizationService.getDnForOrganization());
    Set<Member> members = res.getMembers();
    if (members != null && members.size() > 0) {
        Set<String> groupMembers = group.getMembers().stream().map(userPersistenceHelper::getUserInumFromDN).collect(Collectors.toCollection(HashSet::new));
        List<String> listMembers = new ArrayList<>();
        List<Member> invalidMembers = new ArrayList<>();
        // Add the members, and complement the $refs and users' display names in res
        for (Member member : members) {
            GluuCustomPerson person;
            // it's not null as it is required in GroupResource
            String inum = member.getValue();
            // we make database lookups
            if (!skipMembersValidation && !groupMembers.contains(inum)) {
                person = personService.getPersonByInum(inum);
                if (person != null && fillMembersDisplay) {
                    member.setDisplay(person.getDisplayName());
                }
            } else {
                person = new GluuCustomPerson();
                person.setDn(personService.getDnForPerson(inum));
            }
            if (person == null) {
                log.info("Member identified by {} does not exist. Ignored", inum);
                invalidMembers.add(member);
            } else {
                member.setRef(usersUrl + "/" + inum);
                member.setType(ScimResourceUtil.getType(UserResource.class));
                if (skipMembersValidation) {
                    // In overhead bypass mode, display names must not be returned
                    member.setDisplay(null);
                }
                listMembers.add(person.getDn());
            }
        }
        group.setMembers(listMembers);
        members.removeAll(invalidMembers);
        if (members.isEmpty()) {
            res.setMembers(null);
        }
    } else {
        group.setMembers(new ArrayList<>());
    }
}
Also used : GluuCustomPerson(io.jans.scim.model.GluuCustomPerson) ArrayList(java.util.ArrayList) UserResource(io.jans.scim.model.scim2.user.UserResource) Member(io.jans.scim.model.scim2.group.Member)

Aggregations

ListResponse (io.jans.scim.model.scim2.ListResponse)5 Response (javax.ws.rs.core.Response)4 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)3 ArrayList (java.util.ArrayList)3 SCIMException (io.jans.scim.model.exception.SCIMException)2 ErrorResponse (io.jans.scim.model.scim2.ErrorResponse)2 Meta (io.jans.scim.model.scim2.Meta)2 Extension (io.jans.scim.model.scim2.extensions.Extension)2 SchemaAttribute (io.jans.scim.model.scim2.provider.schema.SchemaAttribute)2 SchemaResource (io.jans.scim.model.scim2.provider.schema.SchemaResource)2 UserResource (io.jans.scim.model.scim2.user.UserResource)2 Field (java.lang.reflect.Field)2 NullType (javax.lang.model.type.NullType)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 GluuCustomPerson (io.jans.scim.model.GluuCustomPerson)1 USER_EXT_SCHEMA_ID (io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID)1 Attribute (io.jans.scim.model.scim2.annotations.Attribute)1 Schema (io.jans.scim.model.scim2.annotations.Schema)1 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)1