Search in sources :

Example 16 with RefAdjusted

use of io.jans.scim.service.scim2.interceptor.RefAdjusted in project jans by JanssenProject.

the class UserWebService method createUser.

@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/users.write" })
@RefAdjusted
public Response createUser(UserResource user, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. createUser");
        executeValidation(user);
        checkUidExistence(user.getUserName());
        assignMetaInformation(user);
        ScimResourceUtil.adjustPrimarySubAttributes(user);
        ScimCustomPerson person = scim2UserService.preCreateUser(user);
        response = externalConstraintsService.applyEntityCheck(person, user, httpHeaders, uriInfo, HttpMethod.POST, userResourceType);
        if (response != null)
            return response;
        scim2UserService.createUser(person, user, endpointUrl);
        String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
        response = Response.created(new URI(user.getMeta().getLocation())).entity(json).build();
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at createUser returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at createUser 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) ScimCustomPerson(io.jans.scim.model.scim.ScimCustomPerson) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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 17 with RefAdjusted

use of io.jans.scim.service.scim2.interceptor.RefAdjusted in project jans by JanssenProject.

the class UserWebService method updateUser.

/**
 * This implementation differs from spec in the following aspects:
 * - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
 * empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
 * operation should be used
 */
@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/users.write" })
@RefAdjusted
public Response updateUser(UserResource user, @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. updateUser");
        // Check if the ids match in case the user coming has one
        if (user.getId() != null && !user.getId().equals(id))
            throw new SCIMException("Parameter id does not match with id attribute of User");
        ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
        if (person == null)
            return notFoundResponse(id, userResourceType);
        response = externalConstraintsService.applyEntityCheck(person, user, httpHeaders, uriInfo, HttpMethod.PUT, userResourceType);
        if (response != null)
            return response;
        executeValidation(user, true);
        if (StringUtils.isNotEmpty(user.getUserName())) {
            checkUidExistence(user.getUserName(), id);
        }
        ScimResourceUtil.adjustPrimarySubAttributes(user);
        UserResource updatedResource = scim2UserService.updateUser(person, user, endpointUrl);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at updateUser returned: {}", 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 updateUser 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) ScimCustomPerson(io.jans.scim.model.scim.ScimCustomPerson) UserResource(io.jans.scim.model.scim2.user.UserResource) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) 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 18 with RefAdjusted

use of io.jans.scim.service.scim2.interceptor.RefAdjusted in project jans by JanssenProject.

the class UserWebService method searchUsersPost.

@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/users.read" })
@RefAdjusted
public Response searchUsersPost(SearchRequest searchRequest) {
    log.debug("Executing web service method. searchUsersPost");
    Response response = doSearch(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 19 with RefAdjusted

use of io.jans.scim.service.scim2.interceptor.RefAdjusted in project jans by JanssenProject.

the class UserWebService method getUserById.

@Path("{id}")
@GET
@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/users.read" })
@RefAdjusted
public Response getUserById(@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. getUserById");
        ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
        if (person == null)
            return notFoundResponse(id, userResourceType);
        response = externalConstraintsService.applyEntityCheck(person, null, httpHeaders, uriInfo, HttpMethod.GET, userResourceType);
        if (response != null)
            return response;
        UserResource user = scim2UserService.buildUserResource(person, endpointUrl);
        String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
        response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getUserById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ScimCustomPerson(io.jans.scim.model.scim.ScimCustomPerson) UserResource(io.jans.scim.model.scim2.user.UserResource) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 20 with RefAdjusted

use of io.jans.scim.service.scim2.interceptor.RefAdjusted in project oxTrust by GluuFederation.

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
@RefAdjusted
@ApiOperation(value = "Update device", response = FidoDeviceResource.class)
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");
        String userId = fidoDeviceResource.getUserId();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            throw new SCIMException("Resource " + id + " not found");
        FidoDeviceResource updatedResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
        long now = System.currentTimeMillis();
        updatedResource.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
        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(e.getMessage());
        response = getErrorResponse(Response.Status.NOT_FOUND, 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 : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Aggregations

URI (java.net.URI)34 Response (javax.ws.rs.core.Response)34 DefaultValue (javax.ws.rs.DefaultValue)33 HeaderParam (javax.ws.rs.HeaderParam)33 Produces (javax.ws.rs.Produces)33 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)28 Path (javax.ws.rs.Path)25 Consumes (javax.ws.rs.Consumes)23 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)17 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)17 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)17 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)17 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 URISyntaxException (java.net.URISyntaxException)16 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)16 ListViewResponse (org.gluu.persist.model.ListViewResponse)16 POST (javax.ws.rs.POST)13 SCIMException (io.jans.scim.model.exception.SCIMException)12 GET (javax.ws.rs.GET)11