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;
}
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);
}
}
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());
}
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);
}
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());
}
Aggregations