Search in sources :

Example 31 with ApiOperation

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

the class ResourceSetRegistrationWS method getResourceSetList.

/**
     * Gets resource set lists.
     * ATTENTION: "scope" is parameter added by gluu to have additional filtering.
     * There is no such parameter in UMA specification.
     *
     * @param authorization authorization
     * @param scope         scope of resource set for additional filtering, can blank string.
     * @return resource set ids.
     */
@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "Lists all previously registered resource set identifiers for this user using the GET method.", notes = "Lists all previously registered resource set identifiers for this user using the GET method. The authorization server MUST return the list in the form of a JSON array of {rsid} string values.\n" + "\n" + "The resource server uses this method as a first step in checking whether its understanding of protected resources is in full synchronization with the authorization server's understanding.", response = ResourceSet.class)
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized") })
public List<String> getResourceSetList(@HeaderParam("Authorization") String authorization, @QueryParam("scope") @ApiParam(value = "Scope uri", required = false) String scope) {
    try {
        log.trace("Getting list of resource set descriptions.");
        final AuthorizationGrant authorizationGrant = umaValidationService.assertHasProtectionScope(authorization);
        final String clientDn = authorizationGrant.getClientDn();
        final List<org.xdi.oxauth.model.uma.persistence.ResourceSet> ldapResourceSets = resourceSetService.getResourceSetsByAssociatedClient(clientDn);
        final List<String> result = new ArrayList<String>(ldapResourceSets.size());
        for (org.xdi.oxauth.model.uma.persistence.ResourceSet ldapResourceSet : ldapResourceSets) {
            // if scope parameter is not null then filter by it, otherwise just add to result
            if (StringUtils.isNotBlank(scope)) {
                final List<String> scopeUrlsByDns = umaScopeService.getScopeUrlsByDns(ldapResourceSet.getScopes());
                if (scopeUrlsByDns != null && scopeUrlsByDns.contains(scope)) {
                    result.add(ldapResourceSet.getId());
                }
            } else {
                result.add(ldapResourceSet.getId());
            }
        }
        return result;
    } catch (Exception ex) {
        log.error("Exception happened on getResourceSetList()", ex);
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
    }
    errorResponseFactory.throwUmaInternalErrorException();
    // redundant but required by java
    return Lists.newArrayList();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebApplicationException(javax.ws.rs.WebApplicationException) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 32 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 33 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 34 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)

Example 35 with ApiOperation

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

the class FidoDeviceWebService method getDeviceById.

@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 device by id", notes = "Returns a device by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = FidoDevice.class)
public Response getDeviceById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam("userId") final String userId, @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 baseDn = fidoDeviceService.getDnForFidoDevice(userId, id);
        log.info("##### baseDn = " + baseDn);
        String filterString = "id eq \"" + id + "\"";
        VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
        List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
        if (gluuCustomFidoDevices == null || gluuCustomFidoDevices.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 ");
        }
        GluuCustomFidoDevice gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
        FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
        // Serialize to JSON
        String json = serializeToJson(fidoDevice, attributesArray);
        URI uriLocation = new URI(fidoDevice.getMeta().getLocation());
        return Response.ok(json).location(uriLocation).build();
    } catch (EntryPersistenceException epe) {
        log.error("Error in getDeviceById", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception e) {
        log.error("Error in getDeviceById", 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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (com.wordnik.swagger.annotations.ApiOperation)61 Produces (javax.ws.rs.Produces)49 Response (javax.ws.rs.core.Response)36 DefaultValue (javax.ws.rs.DefaultValue)35 HeaderParam (javax.ws.rs.HeaderParam)35 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)34 URI (java.net.URI)31 Path (javax.ws.rs.Path)30 Consumes (javax.ws.rs.Consumes)21 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)21 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)19 ListViewResponse (org.gluu.persist.model.ListViewResponse)19 GET (javax.ws.rs.GET)17 POST (javax.ws.rs.POST)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)15 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)15 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)14 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)14