Search in sources :

Example 1 with ProtectedApi

use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.

the class FidoDeviceWebService method searchDevicesPost.

@Path(SEARCH_SUFFIX)
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido.read" })
@RefAdjusted
public Response searchDevicesPost(SearchRequest searchRequest, @QueryParam("userId") String userId) {
    log.debug("Executing web service method. searchDevicesPost");
    Response response = doSearchDevices(userId, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), HttpMethod.POST);
    URI uri = null;
    try {
        uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    }
    return Response.fromResponse(response).location(uri).build();
}
Also used : Response(javax.ws.rs.core.Response) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 2 with ProtectedApi

use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.

the class FidoDeviceWebService method updateDevice.

@Path("{id}")
@PUT
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido.write" })
@RefAdjusted
public Response updateDevice(FidoDeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateDevice");
        // remove externalId, no place to store it in LDAP
        fidoDeviceResource.setExternalId(null);
        if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        String userId = fidoDeviceResource.getUserId();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fidoResourceType);
        if (response != null)
            return response;
        executeValidation(fidoDeviceResource, true);
        FidoDeviceResource updatedResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
        updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        updatedResource = (FidoDeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
        transferAttributesToDevice(updatedResource, device);
        fidoDeviceService.updateGluuCustomFidoDevice(device);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error("Validation check error: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(io.jans.scim.model.exception.SCIMException) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 3 with ProtectedApi

use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.

the class FidoDeviceWebService method deleteDevice.

@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido.write" })
public Response deleteDevice(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteDevice");
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.DELETE, fidoResourceType);
        if (response != null)
            return response;
        fidoDeviceService.removeGluuCustomFidoDevice(device);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 4 with ProtectedApi

use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.

the class Fido2DeviceWebService method updateF2Device.

@Path("{id}")
@PUT
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido2.write" })
@RefAdjusted
public Response updateF2Device(Fido2DeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateDevice");
        // remove externalId, no place to store it in LDAP
        fidoDeviceResource.setExternalId(null);
        if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        String userId = fidoDeviceResource.getUserId();
        GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fido2ResourceType);
        response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fido2ResourceType);
        if (response != null)
            return response;
        executeValidation(fidoDeviceResource, true);
        Fido2DeviceResource updatedResource = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, updatedResource, endpointUrl, userId);
        updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        updatedResource = (Fido2DeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
        transferAttributesToDevice(updatedResource, device);
        fidoDeviceService.updateFido2Device(device);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error("Validation check error: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) SCIMException(io.jans.scim.model.exception.SCIMException) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 5 with ProtectedApi

use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.

the class Fido2DeviceWebService method deleteF2Device.

@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido2.write" })
public Response deleteF2Device(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteDevice");
        GluuFido2Device device = fidoDeviceService.getFido2DeviceById(null, id);
        if (device == null)
            return notFoundResponse(id, fido2ResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.DELETE, fido2ResourceType);
        if (response != null)
            return response;
        fidoDeviceService.removeFido2Device(device);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GluuFido2Device(io.jans.scim.model.GluuFido2Device) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Aggregations

ProtectedApi (io.jans.scim.service.filter.ProtectedApi)23 Produces (javax.ws.rs.Produces)23 Response (javax.ws.rs.core.Response)23 DefaultValue (javax.ws.rs.DefaultValue)22 HeaderParam (javax.ws.rs.HeaderParam)22 URISyntaxException (java.net.URISyntaxException)20 Path (javax.ws.rs.Path)18 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)17 URI (java.net.URI)17 SCIMException (io.jans.scim.model.exception.SCIMException)16 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)16 Consumes (javax.ws.rs.Consumes)14 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)10 POST (javax.ws.rs.POST)8 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)6 GET (javax.ws.rs.GET)6 GluuGroup (io.jans.scim.model.GluuGroup)5 DELETE (javax.ws.rs.DELETE)5 PUT (javax.ws.rs.PUT)5 GluuFido2Device (io.jans.scim.model.GluuFido2Device)3