Search in sources :

Example 11 with SCIMException

use of org.gluu.oxtrust.model.exception.SCIMException in project oxTrust by GluuFederation.

the class ScimFilterParserService method checkParsingErrors.

private void checkParsingErrors(ScimFilterErrorListener errorListener) throws SCIMException {
    String outputErr = errorListener.getOutput();
    String symbolErr = errorListener.getSymbol();
    if (StringUtils.isNotEmpty(outputErr) || StringUtils.isNotEmpty(symbolErr))
        throw new SCIMException(String.format("Error parsing filter (symbol='%s'; message='%s')", symbolErr, outputErr));
}
Also used : SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 12 with SCIMException

use of org.gluu.oxtrust.model.exception.SCIMException in project oxTrust by GluuFederation.

the class Scim2PatchService method applyPatchOperation.

public BaseScimResource applyPatchOperation(BaseScimResource resource, PatchOperation operation) throws Exception {
    BaseScimResource result = null;
    Map<String, Object> genericMap = null;
    PatchOperationType opType = operation.getType();
    Class<? extends BaseScimResource> clazz = resource.getClass();
    String path = operation.getPath();
    log.debug("applyPatchOperation of type {}", opType);
    // Determine if operation is with value filter
    if (StringUtils.isNotEmpty(path) && !operation.getType().equals(PatchOperationType.ADD)) {
        Pair<Boolean, String> pair = validateBracketedPath(path);
        if (pair.getFirst()) {
            String valSelFilter = pair.getSecond();
            if (valSelFilter == null)
                throw new SCIMException("Unexpected syntax in value selection filter");
            else {
                int i = path.indexOf("[");
                String attribute = path.substring(0, i);
                i = path.lastIndexOf("].");
                String subAttribute = i == -1 ? "" : path.substring(i + 2);
                // Abort earlier
                return applyPatchOperationWithValueFilter(resource, operation, valSelFilter, attribute, subAttribute);
            }
        }
    }
    if (!opType.equals(PatchOperationType.REMOVE)) {
        Object value = operation.getValue();
        List<String> extensionUrns = extService.getUrnsOfExtensions(clazz);
        if (value instanceof Map)
            genericMap = IntrospectUtil.strObjMap(value);
        else {
            // It's an atomic value or an array
            if (StringUtils.isEmpty(path))
                throw new SCIMException("Value(s) supplied for resource not parseable");
            // Create a simple map and trim the last part of path
            String[] subPaths = ScimResourceUtil.splitPath(path, extensionUrns);
            genericMap = Collections.singletonMap(subPaths[subPaths.length - 1], value);
            if (subPaths.length == 1)
                path = "";
            else
                path = path.substring(0, path.lastIndexOf("."));
        }
        if (StringUtils.isNotEmpty(path)) {
            // Visit backwards creating a composite map
            String[] subPaths = ScimResourceUtil.splitPath(path, extensionUrns);
            for (int i = subPaths.length - 1; i >= 0; i--) {
                // Create a string consisting of all subpaths until the i-th
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j <= i; j++) sb.append(subPaths[j]).append(".");
                Attribute annot = IntrospectUtil.getFieldAnnotation(sb.substring(0, sb.length() - 1), clazz, Attribute.class);
                boolean multivalued = !(annot == null || annot.multiValueClass().equals(NullType.class));
                Map<String, Object> genericBiggerMap = new HashMap<String, Object>();
                genericBiggerMap.put(subPaths[i], multivalued ? Collections.singletonList(genericMap) : genericMap);
                genericMap = genericBiggerMap;
            }
        }
        log.debug("applyPatchOperation. Generating a ScimResource from generic map: {}", genericMap.toString());
    }
    // Try parse genericMap as an instance of the resource
    ObjectMapper mapper = new ObjectMapper();
    BaseScimResource alter = opType.equals(PatchOperationType.REMOVE) ? resource : mapper.convertValue(genericMap, clazz);
    List<Extension> extensions = extService.getResourceExtensions(clazz);
    switch(operation.getType()) {
        case REPLACE:
            result = ScimResourceUtil.transferToResourceReplace(alter, resource, extensions);
            break;
        case ADD:
            result = ScimResourceUtil.transferToResourceAdd(alter, resource, extensions);
            break;
        case REMOVE:
            result = ScimResourceUtil.deleteFromResource(alter, operation.getPath(), extensions);
            break;
    }
    return result;
}
Also used : PatchOperationType(org.gluu.oxtrust.model.scim2.patch.PatchOperationType) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) NullType(javax.lang.model.type.NullType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 13 with SCIMException

use of org.gluu.oxtrust.model.exception.SCIMException in project oxTrust by GluuFederation.

the class FidoDeviceWebServiceDecorator method updateDevice.

public Response updateDevice(FidoDeviceResource fidoDevice, String id, String attrsList, String excludedAttrsList) {
    Response response;
    try {
        // remove externalId, no place to store it in LDAP
        fidoDevice.setExternalId(null);
        if (fidoDevice.getId() != null && !fidoDevice.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        response = validateExistenceOfDevice(fidoDevice.getUserId(), id);
        if (response == null) {
            executeValidation(fidoDevice, true);
            response = service.updateDevice(fidoDevice, id, attrsList, excludedAttrsList);
        }
    } catch (SCIMException e) {
        log.error("Validation check at updateDevice returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 14 with SCIMException

use of org.gluu.oxtrust.model.exception.SCIMException in project oxTrust by GluuFederation.

the class GroupWebServiceDecorator method createGroup.

public Response createGroup(GroupResource group, String attrsList, String excludedAttrsList) {
    Response response;
    try {
        // empty externalId, no place to store it in LDAP
        group.setExternalId(null);
        executeDefaultValidation(group);
        checkDisplayNameExistence(group.getDisplayName());
        assignMetaInformation(group);
        // Proceed with actual implementation of createGroup method
        response = service.createGroup(group, attrsList, excludedAttrsList);
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at createGroup returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Example 15 with SCIMException

use of org.gluu.oxtrust.model.exception.SCIMException in project oxTrust by GluuFederation.

the class GroupWebServiceDecorator method updateGroup.

public Response updateGroup(GroupResource group, String id, String attrsList, String excludedAttrsList) {
    Response response;
    try {
        // empty externalId, no place to store it in LDAP
        group.setExternalId(null);
        // Check if the ids match in case the group coming has one
        if (group.getId() != null && !group.getId().equals(id))
            throw new SCIMException("Parameter id does not match with id attribute of Group");
        response = validateExistenceOfGroup(id);
        if (response == null) {
            executeValidation(group, true);
            if (StringUtils.isNotEmpty(group.getDisplayName()))
                checkDisplayNameExistence(group.getDisplayName(), id);
            // Proceed with actual implementation of updateGroup method
            response = service.updateGroup(group, id, attrsList, excludedAttrsList);
        }
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (SCIMException e) {
        log.error("Validation check at updateGroup returned: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException)

Aggregations

SCIMException (org.gluu.oxtrust.model.exception.SCIMException)20 Response (javax.ws.rs.core.Response)12 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 URI (java.net.URI)7 DefaultValue (javax.ws.rs.DefaultValue)7 HeaderParam (javax.ws.rs.HeaderParam)7 Produces (javax.ws.rs.Produces)7 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)7 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)7 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)7 ListViewResponse (org.gluu.persist.model.ListViewResponse)7 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)4 DuplicateEntryException (org.gluu.persist.exception.operation.DuplicateEntryException)4 Consumes (javax.ws.rs.Consumes)3 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)3 Extension (org.gluu.oxtrust.model.scim2.extensions.Extension)3 FidoDeviceResource (org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource)3