Search in sources :

Example 16 with ApiOperation

use of com.wordnik.swagger.annotations.ApiOperation in project oxTrust by GluuFederation.

the class ScimConfigurationWS method getConfiguration.

@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Provides configuration data as json document. It contains options and endpoints supported by the SCIM server.", response = UmaConfiguration.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Failed to build SCIM configuration json object.") })
public Response getConfiguration() {
    try {
        final String baseEndpointUri = appConfiguration.getBaseEndpoint();
        final List<ScimConfiguration> cl = new ArrayList<ScimConfiguration>();
        //            cl.setScimConfigurationList(new ArrayList<ScimConfiguration>());
        // SCIM 1.0
        final ScimConfiguration c1 = new ScimConfiguration();
        c1.setVersion("1.0");
        c1.setAuthorizationSupported(new String[] { "uma" });
        c1.setUserEndpoint(baseEndpointUri + "/scim/v1/Users");
        c1.setUserSearchEndpoint(baseEndpointUri + "/scim/v1/Users/Search");
        c1.setGroupEndpoint(baseEndpointUri + "/scim/v1/Groups");
        c1.setBulkEndpoint(baseEndpointUri + "/scim/v1/Bulk");
        cl.add(c1);
        // SCIM 2.0
        final ScimConfiguration c2 = new ScimConfiguration();
        c2.setVersion("2.0");
        c2.setAuthorizationSupported(new String[] { "uma" });
        c2.setUserEndpoint(baseEndpointUri + "/scim/v2/Users");
        c2.setUserSearchEndpoint(baseEndpointUri + "/scim/v2/Users/Search");
        c2.setGroupEndpoint(baseEndpointUri + "/scim/v2/Groups");
        c2.setBulkEndpoint(baseEndpointUri + "/scim/v2/Bulk");
        c2.setServiceProviderEndpoint(baseEndpointUri + "/scim/v2/ServiceProviderConfig");
        c2.setResourceTypesEndpoint(baseEndpointUri + "/scim/v2/ResourceTypes");
        cl.add(c2);
        // Convert manually to avoid possible conflicts between resteasy providers, e.g. jettison, jackson
        final String entity = jsonService.objectToPerttyJson(cl);
        log.trace("SCIM configuration: {}", entity);
        return Response.ok(entity).build();
    } catch (Throwable ex) {
        log.error(ex.getMessage(), ex);
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to generate SCIM configuration").build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) ScimConfiguration(org.gluu.oxtrust.model.scim.ScimConfiguration) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 17 with ApiOperation

use of com.wordnik.swagger.annotations.ApiOperation 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 18 with ApiOperation

use of com.wordnik.swagger.annotations.ApiOperation 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 19 with ApiOperation

use of com.wordnik.swagger.annotations.ApiOperation 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)

Example 20 with ApiOperation

use of com.wordnik.swagger.annotations.ApiOperation in project oxTrust by GluuFederation.

the class FidoDeviceWebService method updateDevice.

@Path("{id}")
@PUT
@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 = "Update device", notes = "Update device (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = FidoDevice.class)
public Response updateDevice(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "FidoDevice", required = true) FidoDevice fidoDevice, @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 {
        if (!id.equalsIgnoreCase(fidoDevice.getId())) {
            String detail = "Path param id does not match with device id";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, detail);
        } else {
            FidoDevice updatedFidoDevice = scim2FidoDeviceService.updateFidoDevice(id, fidoDevice);
            // Serialize to JSON
            String json = serializeToJson(updatedFidoDevice, attributesArray);
            URI location = new URI(updatedFidoDevice.getMeta().getLocation());
            return Response.ok(json).location(location).build();
        }
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update device", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException dee) {
        log.error("DuplicateEntryException", dee);
        dee.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, dee.getMessage());
    } catch (Exception e) {
        log.error("Failed to update device", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, 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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Aggregations

ApiOperation (com.wordnik.swagger.annotations.ApiOperation)41 Produces (javax.ws.rs.Produces)30 DefaultValue (javax.ws.rs.DefaultValue)19 HeaderParam (javax.ws.rs.HeaderParam)19 Response (javax.ws.rs.core.Response)19 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)19 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)19 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)18 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)18 Path (javax.ws.rs.Path)17 URI (java.net.URI)16 GET (javax.ws.rs.GET)13 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 POST (javax.ws.rs.POST)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)9 Consumes (javax.ws.rs.Consumes)8 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)8