use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.
the class PatchReplaceUserTest method jsonNoPathPatch2.
@Parameters({ "user_patchreplace_2" })
@Test(dependsOnMethods = "jsonNoPathPatch1")
public void jsonNoPathPatch2(String patchRequest) {
Response response = client.patchUser(patchRequest, user.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
UserResource other = response.readEntity(usrClass);
assertNotEquals(user.getName().getHonorificPrefix(), other.getName().getHonorificPrefix());
assertNotEquals(user.getName().getHonorificSuffix(), other.getName().getHonorificSuffix());
assertNotEquals(user.getName().getFormatted(), other.getName().getFormatted());
// Verify change in the streetAddress
Address adr = other.getAddresses().get(0);
assertNotEquals(user.getAddresses().get(0).getStreetAddress(), adr.getStreetAddress());
// Verify other attributes were nulled
assertNull(adr.getPostalCode());
assertNull(adr.getRegion());
// Verify change in number of phone numbers
assertNotEquals(user.getPhoneNumbers().size(), other.getPhoneNumbers().size());
// Verify new user has different phone numbers
String phone = user.getPhoneNumbers().get(0).getValue();
assertTrue(other.getPhoneNumbers().stream().map(PhoneNumber::getValue).noneMatch(phone::equals));
// Verify x509Certs disappeared
assertNull(other.getX509Certificates());
// Verify "roles" are still there intact
assertEquals(user.getRoles().size(), other.getRoles().size());
assertEquals(user.getRoles().get(0).getValue(), other.getRoles().get(0).getValue());
user = other;
}
use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.
the class GroupsBulkTest method bulkObject.
@Test(dependsOnMethods = "bulkJson")
public void bulkObject() {
logger.info("Sending a bulk with a patch to insert admin user into group");
// Creates a patch request consisting of adding the admin user to the group created
PatchOperation po = new PatchOperation();
po.setOperation("add");
po.setPath("members.value");
po.setValue(getAdminId());
PatchRequest pr = new PatchRequest();
pr.setOperations(Collections.singletonList(po));
// Creates the bulk operation associated to the patch request
BulkOperation bop = new BulkOperation();
bop.setMethod("PATCH");
bop.setPath("/Groups/" + groupId);
bop.setData(mapper.convertValue(pr, new TypeReference<Map<String, Object>>() {
}));
BulkRequest breq = new BulkRequest();
breq.setOperations(Collections.singletonList(bop));
// Send bulk and check success of processing
Response response = client.processBulkOperations(breq);
assertEquals(response.getStatus(), Status.OK.getStatusCode());
BulkResponse bres = response.readEntity(BulkResponse.class);
assertSuccessfulOps(bres.getOperations());
}
use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.
the class PairwiseIdentifiersTest method queryAndRemoval.
@Test
public void queryAndRemoval() throws Exception {
// Get a list (of at most 1 user) who has a persisted pairwise identifier
Response response = client.searchUsers("pairwiseIdentifiers pr", null, 1, null, null, "pairwiseIdentifiers, id", null);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse lr = response.readEntity(ListResponse.class);
// If the list is empty do nothing (successful test)
if (lr.getItemsPerPage() > 0) {
UserResource user = (UserResource) lr.getResources().get(0);
assertNotNull(user.getPairwiseIdentifiers());
// Prepare the removal of the user's PPIDs
PatchOperation operation = new PatchOperation();
operation.setOperation("remove");
operation.setPath("pairwiseIdentitifers");
PatchRequest pr = new PatchRequest();
pr.setOperations(Collections.singletonList(operation));
response = client.patchUser(pr, user.getId(), "pairwiseIdentifiers", null);
assertEquals(response.getStatus(), OK.getStatusCode());
// Ensure they are not there anymore.
user = response.readEntity(UserResource.class);
assertNull(user.getPairwiseIdentifiers());
// This test does not guarantee the ou=pairwiseIdentifiers sub-branch disappears... only the jsPPID LDAP attribute
}
}
use of io.jans.scim.model.scim2.patch.PatchRequest in project jans by JanssenProject.
the class UserWebService method patchUser.
@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/users.write" })
@RefAdjusted
public Response patchUser(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. patchUser");
response = inspectPatchRequest(request, UserResource.class);
if (response != null)
return response;
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, request, httpHeaders, uriInfo, HttpMethod.PATCH, userResourceType);
if (response != null)
return response;
UserResource user = new UserResource();
// Fill user instance with all info from person
scim2UserService.transferAttributesToUserResource(person, user, endpointUrl);
// Apply patches one by one in sequence
for (PatchOperation po : request.getOperations()) {
// Handle special case: https://github.com/GluuFederation/oxTrust/issues/800
if (po.getType().equals(REMOVE) && po.getPath().equals("pairwiseIdentifiers")) {
// If this block weren't here, the implementation will throw error because read-only attribute cannot be altered
person.setPpid(null);
user.setPairwiseIdentifiers(null);
scim2UserService.removePPIDsBranch(person.getDn());
} else {
user = (UserResource) scim2PatchService.applyPatchOperation(user, po);
}
}
// Throws exception if final representation does not pass overall validation
log.debug("patchUser. Revising final resource representation still passes validations");
executeValidation(user);
ScimResourceUtil.adjustPrimarySubAttributes(user);
// Update timestamp
user.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
// Replaces the information found in person with the contents of user
scim2UserService.replacePersonInfo(person, user, endpointUrl);
String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
} 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 patchUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations