Search in sources :

Example 1 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class BaseScimWebService method executeValidation.

protected void executeValidation(BaseScimResource resource, boolean skipRequired) throws SCIMException {
    ResourceValidator rv = new ResourceValidator(resource, extService.getResourceExtensions(resource.getClass()));
    if (!skipRequired) {
        rv.validateRequiredAttributes();
        rv.validateSchemasAttribute();
    }
    rv.validateValidableAttributes();
    // By section 7 of RFC 7643, we are not forced to constrain attribute values when they have a list of canonical values associated
    // rv.validateCanonicalizedAttributes();
    rv.validateExtendedAttributes();
}
Also used : ResourceValidator(org.gluu.oxtrust.model.scim2.util.ResourceValidator)

Example 2 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class BaseScimWebService method inspectPatchRequest.

protected Response inspectPatchRequest(PatchRequest patch, Class<? extends BaseScimResource> cls) {
    Response response = null;
    List<String> schemas = patch.getSchemas();
    if (schemas != null && schemas.size() == 1 && schemas.get(0).equals(PATCH_REQUEST_SCHEMA_ID)) {
        List<PatchOperation> ops = patch.getOperations();
        if (ops != null) {
            // Adjust paths if they came prefixed
            String defSchema = ScimResourceUtil.getDefaultSchemaUrn(cls);
            List<String> urns = extService.getUrnsOfExtensions(cls);
            urns.add(defSchema);
            for (PatchOperation op : ops) {
                if (op.getPath() != null)
                    op.setPath(ScimResourceUtil.adjustNotationInPath(op.getPath(), defSchema, urns));
            }
            for (PatchOperation op : ops) {
                if (op.getType() == null)
                    response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Operation '" + op.getOperation() + "' not recognized");
                else {
                    String path = op.getPath();
                    if (StringUtils.isEmpty(path) && op.getType().equals(PatchOperationType.REMOVE))
                        response = getErrorResponse(BAD_REQUEST, ErrorScimType.NO_TARGET, "Path attribute is required for remove operation");
                    else if (op.getValue() == null && !op.getType().equals(PatchOperationType.REMOVE))
                        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Value attribute is required for operations other than remove");
                }
                if (response != null)
                    break;
            }
        } else
            response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Patch request MUST contain the attribute 'Operations'");
    } else
        response = getErrorResponse(BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, "Wrong schema(s) supplied in Search Request");
    log.info("inspectPatchRequest. Preprocessing of patch request {}", response == null ? "passed" : "failed");
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.gluu.oxtrust.model.scim2.ErrorResponse) PatchOperation(org.gluu.oxtrust.model.scim2.patch.PatchOperation)

Example 3 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class BaseScimWebService method getListResponseSerialized.

String getListResponseSerialized(int total, int startIndex, List<BaseScimResource> resources, String attrsList, String excludedAttrsList, boolean ignoreResults) throws IOException {
    ListResponse listResponse = new ListResponse(startIndex, resources.size(), total);
    listResponse.setResources(resources);
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
    module.addSerializer(ListResponse.class, new ListResponseJsonSerializer(resourceSerializer, attrsList, excludedAttrsList, ignoreResults));
    mapper.registerModule(module);
    return mapper.writeValueAsString(listResponse);
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ListResponseJsonSerializer(org.gluu.oxtrust.service.scim2.serialization.ListResponseJsonSerializer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 4 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevices.

private ListViewResponse<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "oxId=*", FidoDeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuCustomFidoDevice> list = ldapEntryManager.findListViewResponse(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, startIndex, count, getMaxCount(), sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuCustomFidoDevice device : list.getResult()) {
        FidoDeviceResource scimDev = new FidoDeviceResource();
        transferAttributesToFidoResource(device, scimDev, url, getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
    ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
    result.setResult(resources);
    result.setTotalResults(list.getTotalResults());
    return result;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) Filter(org.gluu.search.filter.Filter) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList)

Example 5 with BaseScimResource

use of org.gluu.oxtrust.model.scim2.BaseScimResource in project oxTrust by GluuFederation.

the class FidoDeviceWebService method searchDevices.

@GET
@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 = "Search devices", notes = "Returns a list of devices", response = ListResponse.class)
public Response searchDevices(@QueryParam("userId") String userId, @QueryParam(QUERY_PARAM_FILTER) String filter, @QueryParam(QUERY_PARAM_START_INDEX) Integer startIndex, @QueryParam(QUERY_PARAM_COUNT) Integer count, @QueryParam(QUERY_PARAM_SORT_BY) String sortBy, @QueryParam(QUERY_PARAM_SORT_ORDER) String sortOrder, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. searchDevices");
        sortBy = translateSortByAttribute(FidoDeviceResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = searchDevices(userId, filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl);
        String json = getListResponseSerialized(resources.getTotalResults(), startIndex, resources.getResult(), attrsList, excludedAttrsList, count == 0);
        response = Response.ok(json).location(new URI(endpointUrl)).build();
    } catch (SCIMException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at searchDevices 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) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)12 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)9 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)7 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)6 ExtensionField (org.gluu.oxtrust.model.scim2.extensions.ExtensionField)6 ListViewResponse (org.gluu.persist.model.ListViewResponse)6 Response (javax.ws.rs.core.Response)5 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 DefaultValue (javax.ws.rs.DefaultValue)3 GET (javax.ws.rs.GET)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)3 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)3