Search in sources :

Example 6 with QUERY_PARAM_EXCLUDED_ATTRS

use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS 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 7 with QUERY_PARAM_EXCLUDED_ATTRS

use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS 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 8 with QUERY_PARAM_EXCLUDED_ATTRS

use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS in project jans by JanssenProject.

the class ReferenceURIInterceptor method manage.

@AroundInvoke
public Object manage(InvocationContext ctx) throws Exception {
    Object[] params = ctx.getParameters();
    Annotation[][] annotations = ctx.getMethod().getParameterAnnotations();
    for (int i = 0; i < annotations.length; i++) {
        // Iterate over annotations found at every parameter
        for (Annotation annotation : annotations[i]) {
            if (annotation instanceof QueryParam) {
                String paramName = ((QueryParam) annotation).value();
                if ((paramName.equals(QUERY_PARAM_FILTER) || paramName.equals(QUERY_PARAM_ATTRIBUTES) || paramName.equals(QUERY_PARAM_EXCLUDED_ATTRS))) {
                    log.trace("Removing '$' char (if any) from {} param", paramName);
                    params[i] = dropDollar(params[i]);
                }
            }
        }
        if (params[i] != null && params[i] instanceof SearchRequest) {
            log.trace("Removing '$' char (if any) from SearchRequest object");
            SearchRequest sr = (SearchRequest) params[i];
            sr.setAttributes(dropDollar(sr.getAttributesStr()));
            sr.setExcludedAttributes(dropDollar(sr.getExcludedAttributesStr()));
            sr.setFilter(dropDollar(sr.getFilter()));
        }
    }
    log.debug("ReferenceURIInterceptor. manage exit");
    return ctx.proceed();
}
Also used : SearchRequest(io.jans.scim.model.scim2.SearchRequest) QueryParam(javax.ws.rs.QueryParam) Annotation(java.lang.annotation.Annotation) AroundInvoke(javax.interceptor.AroundInvoke)

Example 9 with QUERY_PARAM_EXCLUDED_ATTRS

use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS in project jans by JanssenProject.

the class FidoDeviceWebService method getDeviceById.

@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/fido.read" })
@RefAdjusted
public Response getDeviceById(@PathParam("id") String id, @QueryParam("userId") String userId, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getDeviceById");
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.GET, fidoResourceType);
        if (response != null)
            return response;
        FidoDeviceResource fidoResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, fidoResource, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getDeviceById 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) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 10 with QUERY_PARAM_EXCLUDED_ATTRS

use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS in project jans by JanssenProject.

the class Fido2DeviceWebService method getF2DeviceById.

@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/fido2.read" })
@RefAdjusted
public Response getF2DeviceById(@PathParam("id") String id, @QueryParam("userId") String userId, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getF2DeviceById");
        GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fido2ResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.GET, fido2ResourceType);
        if (response != null)
            return response;
        Fido2DeviceResource fidoResource = new Fido2DeviceResource();
        transferAttributesToFido2Resource(device, fidoResource, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } catch (Exception e) {
        log.error("Failure at getF2DeviceById 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) URI(java.net.URI) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Aggregations

SCIMException (io.jans.scim.model.exception.SCIMException)10 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)10 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)10 URI (java.net.URI)10 URISyntaxException (java.net.URISyntaxException)10 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)10 DefaultValue (javax.ws.rs.DefaultValue)10 HeaderParam (javax.ws.rs.HeaderParam)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 Response (javax.ws.rs.core.Response)10 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)6 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)5 PUT (javax.ws.rs.PUT)5 GluuGroup (io.jans.scim.model.GluuGroup)3 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)3 GroupResource (io.jans.scim.model.scim2.group.GroupResource)3 UserResource (io.jans.scim.model.scim2.user.UserResource)3 GluuFido2Device (io.jans.scim.model.GluuFido2Device)2