Search in sources :

Example 16 with Validations

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

the class GroupWebService method patchGroup.

@Path("{id}")
@PATCH
@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/groups.write" })
@RefAdjusted
public Response patchGroup(PatchRequest request, @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. patchGroup");
        response = inspectPatchRequest(request, GroupResource.class);
        if (response != null)
            return response;
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        if (gluuGroup == null)
            return notFoundResponse(id, groupResourceType);
        response = externalConstraintsService.applyEntityCheck(gluuGroup, request, httpHeaders, uriInfo, HttpMethod.PATCH, groupResourceType);
        if (response != null)
            return response;
        boolean skipValidation = isMembersValidationSkipped();
        boolean displayExcluded = isDisplayExcluded(skipValidation, attrsList, excludedAttrsList);
        GroupResource group = new GroupResource();
        // Fill group instance with all info from gluuGroup
        scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, !skipValidation, endpointUrl, usersUrl);
        GroupResource original = (GroupResource) ScimResourceUtil.clone(group);
        Predicate<String> p = skipValidation ? selectionFilterSkipPredicate : (filter -> false);
        // Apply patches one by one in sequence
        for (PatchOperation po : request.getOperations()) {
            group = (GroupResource) scim2PatchService.applyPatchOperation(group, po, p);
        }
        log.debug("patchGroup. Revising final resource representation still passes validations");
        // Throws exception if final representation does not pass overall validation
        executeValidation(group);
        checkDisplayNameExistence(group.getDisplayName(), id);
        // Update timestamp
        group.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        if (!displayExcluded) {
            scim2GroupService.restoreMembersDisplay(original, group);
        }
        // Replaces the information found in gluuGroup with the contents of group
        scim2GroupService.replaceGroupInfo(gluuGroup, group, skipValidation, !displayExcluded, endpointUrl, usersUrl);
        String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
        response = Response.ok(new URI(group.getMeta().getLocation())).entity(json).build();
    } catch (DuplicateEntryException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (SCIMException e) {
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_SYNTAX, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at patchGroup method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Produces(javax.ws.rs.Produces) QUERY_PARAM_FILTER(io.jans.scim.model.scim2.Constants.QUERY_PARAM_FILTER) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) QUERY_PARAM_SORT_ORDER(io.jans.scim.model.scim2.Constants.QUERY_PARAM_SORT_ORDER) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) MediaType(javax.ws.rs.core.MediaType) SCIMException(io.jans.scim.model.exception.SCIMException) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) GluuGroup(io.jans.scim.model.GluuGroup) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) SortOrder(io.jans.orm.model.SortOrder) Predicate(java.util.function.Predicate) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) QUERY_PARAM_EXCLUDED_ATTRS(io.jans.scim.model.scim2.Constants.QUERY_PARAM_EXCLUDED_ATTRS) GroupResource(io.jans.scim.model.scim2.group.GroupResource) List(java.util.List) Response(javax.ws.rs.core.Response) ErrorScimType(io.jans.scim.model.scim2.ErrorScimType) Scim2PatchService(io.jans.scim.service.scim2.Scim2PatchService) PostConstruct(javax.annotation.PostConstruct) QUERY_PARAM_START_INDEX(io.jans.scim.model.scim2.Constants.QUERY_PARAM_START_INDEX) QUERY_PARAM_SORT_BY(io.jans.scim.model.scim2.Constants.QUERY_PARAM_SORT_BY) GroupService(io.jans.scim.service.GroupService) PathParam(javax.ws.rs.PathParam) QUERY_PARAM_COUNT(io.jans.scim.model.scim2.Constants.QUERY_PARAM_COUNT) GET(javax.ws.rs.GET) QUERY_PARAM_ATTRIBUTES(io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) DateUtil(io.jans.scim.model.scim2.util.DateUtil) HttpMethod(javax.ws.rs.HttpMethod) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) Inject(javax.inject.Inject) Named(javax.inject.Named) POST(javax.ws.rs.POST) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) UTF8_CHARSET_FRAGMENT(io.jans.scim.model.scim2.Constants.UTF8_CHARSET_FRAGMENT) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) GROUP_OVERHEAD_BYPASS_PARAM(io.jans.scim.model.scim2.Constants.GROUP_OVERHEAD_BYPASS_PARAM) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SearchRequest(io.jans.scim.model.scim2.SearchRequest) PagedResult(io.jans.orm.model.PagedResult) MEDIA_TYPE_SCIM_JSON(io.jans.scim.model.scim2.Constants.MEDIA_TYPE_SCIM_JSON) Scim2GroupService(io.jans.scim.service.scim2.Scim2GroupService) PUT(javax.ws.rs.PUT) GluuGroup(io.jans.scim.model.GluuGroup) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) GroupResource(io.jans.scim.model.scim2.group.GroupResource) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Response(javax.ws.rs.core.Response) SCIMException(io.jans.scim.model.exception.SCIMException) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) 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)

Example 17 with Validations

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

the class Scim2UserService method transferExtendedAttributesToPerson.

/**
 * Takes all extended attributes found in the SCIM resource and copies them to a
 * ScimCustomPerson This method is called after validations take place (see
 * associated decorator for User Service), so all inputs are OK and can go
 * straight to LDAP with no runtime surprises
 *
 * @param resource
 *            A SCIM resource used as origin of data
 * @param person
 *            a ScimCustomPerson used as destination
 */
private void transferExtendedAttributesToPerson(BaseScimResource resource, ScimCustomPerson person) {
    try {
        // Gets all the extended attributes for this resource
        Map<String, Object> extendedAttrs = resource.getCustomAttributes();
        // Iterates over all extensions this type of resource might have
        for (Extension extension : extService.getResourceExtensions(resource.getClass())) {
            Object val = extendedAttrs.get(extension.getUrn());
            if (val != null) {
                // Obtains the attribute/value(s) pairs in the current extension
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(val);
                for (String attribute : attrsMap.keySet()) {
                    Object value = attrsMap.get(attribute);
                    if (value == null) {
                        // Attribute was unassigned in this resource: drop it from destination too
                        log.debug("transferExtendedAttributesToPerson. Flushing attribute {}", attribute);
                        person.setAttribute(attribute, (String) null);
                    } else {
                        ExtensionField field = extension.getFields().get(attribute);
                        if (field.isMultiValued()) {
                            person.setCustomAttribute(attribute, extService.getAttributeValues(field, (Collection) value, ldapBackend));
                        } else {
                            person.setCustomAttribute(attribute, extService.getAttributeValue(field, value, ldapBackend));
                        }
                        log.debug("transferExtendedAttributesToPerson. Setting attribute '{}' with values {}", attribute, person.getTypedAttribute(attribute).getDisplayValue());
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Collection(java.util.Collection) WebApplicationException(javax.ws.rs.WebApplicationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 18 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testJavaToJson.

@Test
public void testJavaToJson() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertTrue(validations.getValidation().isEmpty());
}
Also used : Validations(io.atlasmap.v2.Validations) Test(org.junit.jupiter.api.Test) AtlasMappingBaseTest(io.atlasmap.itests.validation.AtlasMappingBaseTest)

Example 19 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testMappingNameEmpty.

@Test
public void testMappingNameEmpty() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertFalse(validations.getValidation().isEmpty());
    boolean found = false;
    for (Validation v : validations.getValidation()) {
        if ("Mapping name must not be null nor empty".equals(v.getMessage())) {
            found = true;
            assertEquals(ValidationStatus.ERROR, v.getStatus());
            assertEquals(ValidationScope.ALL, v.getScope());
        }
    }
    assertTrue(found);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.jupiter.api.Test) AtlasMappingBaseTest(io.atlasmap.itests.validation.AtlasMappingBaseTest)

Example 20 with Validations

use of io.jans.scim.model.scim2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testJavaToXml.

@Test
public void testJavaToXml() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertTrue(validations.getValidation().isEmpty());
}
Also used : Validations(io.atlasmap.v2.Validations) Test(org.junit.jupiter.api.Test) AtlasMappingBaseTest(io.atlasmap.itests.validation.AtlasMappingBaseTest)

Aggregations

Validations (io.atlasmap.v2.Validations)26 Test (org.junit.jupiter.api.Test)11 Validation (io.atlasmap.v2.Validation)9 Test (org.junit.Test)9 AtlasMappingBaseTest (io.atlasmap.itests.validation.AtlasMappingBaseTest)8 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 AtlasSession (io.atlasmap.api.AtlasSession)5 AtlasContext (io.atlasmap.api.AtlasContext)4 SCIMException (io.jans.scim.model.exception.SCIMException)4 Audits (io.atlasmap.v2.Audits)3 File (java.io.File)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 AtlasValidationException (io.atlasmap.api.AtlasValidationException)2 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)2 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)1 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)1 Head (io.atlasmap.spi.AtlasInternalSession.Head)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1