Search in sources :

Example 1 with Schema

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

the class SchemaWebService method listSchemas.

/**
     * Retrieves the complete schema.
     *
     * @param authorization
     * @return
     * @throws Exception
     */
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listSchemas(@HeaderParam("Authorization") String authorization) throws Exception {
    log.info(" listSchemas() ");
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    List<SchemaType> schemaTypes = SchemaTypeMapping.getSchemaInstances();
    List<Resource> resources = new ArrayList<Resource>();
    SchemaTypeLoadingFactory factory = new SchemaTypeLoadingFactory();
    for (SchemaType schemaType : schemaTypes) {
        factory.load(appConfiguration, schemaType);
        resources.add(schemaType);
    }
    listResponse.setResources(resources);
    listResponse.setTotalResults(schemaTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas");
    // Serialize to JSON
    String json = serialize(listResponse);
    return Response.ok(json).location(location).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) SchemaTypeLoadingFactory(org.gluu.oxtrust.service.scim2.schema.SchemaTypeLoadingFactory) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) URI(java.net.URI) SchemaType(org.gluu.oxtrust.model.scim2.schema.SchemaType) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Schema

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

the class UserWebService method searchUsers.

@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) Integer count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        count = (count == null) ? getMaxCount() : count;
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
        } else {
            log.info(" Searching users from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuCustomPerson> gluuCustomPersons = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuCustomPerson> personList = personService.findAllPersons(null);
            ListResponse usersListResponse = new ListResponse();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
            log.info(" setting schema");
            usersListResponse.setSchemas(schema);
            // Set total
            usersListResponse.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
                for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
                    User user = copyUtils2.copy(gluuPerson, null);
                    log.info(" user to be added id : " + user.getUserName());
                    usersListResponse.getResources().add(user);
                    log.info(" user added? : " + usersListResponse.getResources().contains(user));
                }
                // Set the rest of results info
                usersListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
                usersListResponse.setStartIndex(vlvResponse.getStartIndex());
            }
            // Serialize to JSON
            String json = serializeToJson(usersListResponse, attributesArray);
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Users");
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchUsers", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 3 with Schema

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

the class UserDeserializer method deserialize.

@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    log.info(" deserialize() ");
    try {
        JsonNode rootNode = jsonParser.readValueAsTree();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
        User user = mapper.readValue(rootNode.toString(), User.class);
        if (user.getSchemas() == null) {
            throw new IllegalArgumentException("Required field \"schemas\" is null or missing.");
        } else if (!user.getSchemas().contains(Constants.USER_CORE_SCHEMA_ID)) {
            throw new IllegalArgumentException("User Core schema is required.");
        } else if (user.getSchemas().contains(Constants.USER_EXT_SCHEMA_ID)) {
            JsonNode userExtensionNode = rootNode.get(Constants.USER_EXT_SCHEMA_ID);
            if (userExtensionNode != null) {
                ExtensionDeserializer deserializer = new ExtensionDeserializer();
                deserializer.setId(Constants.USER_EXT_SCHEMA_ID);
                SimpleModule deserializerModule = new SimpleModule("ExtensionDeserializerModule", new Version(1, 0, 0, ""));
                deserializerModule.addDeserializer(Extension.class, deserializer);
                mapper.registerModule(deserializerModule);
                Extension extension = mapper.readValue(userExtensionNode.toString(), Extension.class);
                user.addExtension(extension);
            } else {
                throw new IllegalArgumentException("User Extension schema is indicated, but value body is absent.");
            }
        }
        return user;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.Extension) User(org.gluu.oxtrust.model.scim2.User) Version(org.codehaus.jackson.Version) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) IOException(java.io.IOException)

Example 4 with Schema

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

the class FidoDeviceCoreLoadingStrategy 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("FidoDeviceCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeFidoDeviceSerializer serializer = new SchemaTypeFidoDeviceSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(FidoDevice.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyFidoDevice());
    return serializer.getSchemaType();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaTypeFidoDeviceSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeFidoDeviceSerializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 5 with Schema

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

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()) {
            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 : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.gluu.oxtrust.model.scim2.ErrorResponse)

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