Search in sources :

Example 16 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class GroupWebService method searchGroups.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int 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 = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
        } else {
            log.info(" Searching groups from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuGroup> gluuGroups = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuGroup> groupList = groupService.getAllGroupsList();
            GluuGroupList groupsList = new GluuGroupList();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
            log.info(" setting schema");
            groupsList.setSchemas(schema);
            // Set total
            groupsList.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuGroups != null && !gluuGroups.isEmpty()) {
                for (GluuGroup gluuGroup : gluuGroups) {
                    ScimGroup group = copyUtils.copy(gluuGroup, null);
                    log.info(" group to be added displayName : " + group.getDisplayName());
                    groupsList.getResources().add(group);
                    log.info(" group added? : " + groupsList.getResources().contains(group));
                }
                // Set the rest of results info
                groupsList.setItemsPerPage(vlvResponse.getItemsPerPage());
                groupsList.setStartIndex(vlvResponse.getStartIndex());
            }
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Groups");
            // Serialize to JSON
            ObjectMapper mapper = new ObjectMapper();
            mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
            SimpleModule customScimFilterModule = new SimpleModule("CustomScim1GroupFilterModule", new Version(1, 0, 0, ""));
            GluuGroupListSerializer serializer = new GluuGroupListSerializer();
            serializer.setAttributesArray(attributesArray);
            customScimFilterModule.addSerializer(ScimGroup.class, serializer);
            mapper.registerModule(customScimFilterModule);
            String json = mapper.writeValueAsString(groupsList);
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchGroups", ex);
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GluuGroupListSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.GluuGroupListSerializer) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuGroupList(org.gluu.oxtrust.model.GluuGroupList) Version(org.codehaus.jackson.Version) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class UserWebService method searchPersons.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchPersons(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int 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 = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
        } else {
            log.info(" Searching persons 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);
            GluuCustomPersonList personsList = new GluuCustomPersonList();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
            log.info(" setting schema");
            personsList.setSchemas(schema);
            // Set total
            personsList.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
                for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
                    ScimPerson person = copyUtils.copy(gluuPerson, null);
                    log.info(" person to be added id : " + person.getUserName());
                    personsList.getResources().add(person);
                    log.info(" person added? : " + personsList.getResources().contains(person));
                }
                // Set the rest of results info
                personsList.setItemsPerPage(vlvResponse.getItemsPerPage());
                personsList.setStartIndex(vlvResponse.getStartIndex());
            }
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Users");
            // Serialize to JSON
            ObjectMapper mapper = new ObjectMapper();
            mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
            SimpleModule customScimFilterModule = new SimpleModule("CustomScim1PersonFilterModule", new Version(1, 0, 0, ""));
            GluuCustomPersonListSerializer serializer = new GluuCustomPersonListSerializer();
            serializer.setAttributesArray(attributesArray);
            customScimFilterModule.addSerializer(ScimPerson.class, serializer);
            mapper.registerModule(customScimFilterModule);
            String json = mapper.writeValueAsString(personsList);
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchPersons", ex);
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuCustomPersonListSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.GluuCustomPersonListSerializer) 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) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Version(org.codehaus.jackson.Version) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) GluuCustomPersonList(org.gluu.oxtrust.model.GluuCustomPersonList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class UserWebService method getUserById.

@Path("{id}")
@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 = "Find user by id", notes = "Returns a user by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = User.class)
public Response getUserById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @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 {
        String filterString = "id eq \"" + id + "\"";
        VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
        List<GluuCustomPerson> personList = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
        if (personList == null || personList.isEmpty() || vlvResponse.getTotalResults() == 0) {
            // sets HTTP status code 404 Not Found
            return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
        } else {
            log.info(" Resource " + id + " found ");
        }
        GluuCustomPerson gluuPerson = personList.get(0);
        User user = copyUtils2.copy(gluuPerson, null);
        // Serialize to JSON
        String json = serializeToJson(user, attributesArray);
        URI location = new URI(user.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in getUserById", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception ex) {
        log.error("Error in getUserById", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, 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) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) 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) 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) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 19 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class UserWebService method createUser.

@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "Create user", notes = "Create user (https://tools.ietf.org/html/rfc7644#section-3.3)", response = User.class)
public Response createUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "User", required = true) User user, @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 {
        User createdUser = scim2UserService.createUser(user);
        // Serialize to JSON
        String json = serializeToJson(createdUser, attributesArray);
        URI location = new URI(createdUser.getMeta().getLocation());
        // Return HTTP response with status code 201 Created
        return Response.created(location).entity(json).build();
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (PersonRequiredFieldsException ex) {
        log.error("PersonRequiredFieldsException: ", ex);
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to create user", ex.getMessage());
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, 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) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) 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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 20 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevicesPost.

@Path("/.search")
@POST
@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 devices POST /.search", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchDevicesPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN FidoDeviceWebService.searchDevicesPost()...");
        // Authorization check is done in searchDevices()
        Response response = searchDevices(authorization, token, userId, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/.search");
        log.info("LEAVING FidoDeviceWebService.searchDevicesPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException epe) {
        log.error("Error in searchDevicesPost", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception e) {
        log.error("Error in searchDevicesPost", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

HeaderParam (javax.ws.rs.HeaderParam)34 DefaultValue (javax.ws.rs.DefaultValue)32 Produces (javax.ws.rs.Produces)30 URI (java.net.URI)25 Response (javax.ws.rs.core.Response)23 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)21 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)21 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)21 Path (javax.ws.rs.Path)20 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)19 GET (javax.ws.rs.GET)16 ArrayList (java.util.ArrayList)11 Consumes (javax.ws.rs.Consumes)9 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)9 POST (javax.ws.rs.POST)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)5 Meta (org.gluu.oxtrust.model.scim2.Meta)5 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)5 User (org.gluu.oxtrust.model.scim2.User)5