use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class UserWebService method updateUser.
/**
* This implementation differs from spec in the following aspects:
* - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
* empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
* operation should be used
*/
@Path("{id}")
@PUT
@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 updateUser(UserResource user, @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. updateUser");
// Check if the ids match in case the user coming has one
if (user.getId() != null && !user.getId().equals(id))
throw new SCIMException("Parameter id does not match with id attribute of User");
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, user, httpHeaders, uriInfo, HttpMethod.PUT, userResourceType);
if (response != null)
return response;
executeValidation(user, true);
if (StringUtils.isNotEmpty(user.getUserName())) {
checkUidExistence(user.getUserName(), id);
}
ScimResourceUtil.adjustPrimarySubAttributes(user);
UserResource updatedResource = scim2UserService.updateUser(person, user, endpointUrl);
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} catch (DuplicateEntryException e) {
log.error(e.getMessage());
response = getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, e.getMessage());
} catch (SCIMException e) {
log.error("Validation check at updateUser returned: {}", e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
} catch (InvalidAttributeValueException e) {
log.error(e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
} catch (Exception e) {
log.error("Failure at updateUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class UserWebService method getUserById.
@Path("{id}")
@GET
@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.read" })
@RefAdjusted
public Response getUserById(@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. getUserById");
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, null, httpHeaders, uriInfo, HttpMethod.GET, userResourceType);
if (response != null)
return response;
UserResource user = scim2UserService.buildUserResource(person, endpointUrl);
String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
} catch (Exception e) {
log.error("Failure at getUserById method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class SpecialCharsTest method containabilityAll.
@SkipTest(databases = { "spanner", "couchbase" })
@Test
public void containabilityAll() {
// Builds a long "and" based clause
String filter = specialFilterLdapChars.stream().reduce("", (partial, next) -> partial + String.format(" and userName co \"%s\"", next));
SearchRequest sr = new SearchRequest();
// Drop beginning (namely " and ")
sr.setFilter(filter.substring(4));
sr.setAttributes("userName");
// Search users whose usernames contain ALL the chars
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
List<UserResource> resources = response.readEntity(ListResponse.class).getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());
String userName = resources.get(0).getUserName();
assertEquals(resources.size(), 1);
assertTrue(Stream.of(SPECIAL_CHARS).allMatch(userName::contains));
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class GroupAssignUserTest method assignToGroup.
@Test(dependsOnMethods = "createUsers")
public void assignToGroup() {
Set<Member> buddies = friends.stream().map(buddy -> {
Member m = new Member();
m.setValue(buddy.getId());
m.setDisplay(buddy.getDisplayName());
return m;
}).collect(Collectors.toSet());
GroupResource gr = new GroupResource();
gr.setDisplayName("3 best demented buddies");
gr.setMembers(buddies);
logger.info("Assigning users to new group...");
Response response = client.createGroup(gr, null, null);
assertEquals(response.getStatus(), CREATED.getStatusCode());
group = response.readEntity(GroupResource.class);
// Verify the sanitarium is completely booked
assertTrue(group.getMembers().stream().map(Member::getValue).collect(Collectors.toSet()).equals(friends.stream().map(UserResource::getId).collect(Collectors.toSet())));
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class GroupAssignUserTest method verifyGroupsAttribute.
@Test(dependsOnMethods = "assignToSecondGroup")
public void verifyGroupsAttribute() {
// Refresh the user instances so getGroups() can be called
// builds a filter string
StringBuilder filter = new StringBuilder();
friends.forEach(buddy -> filter.append(String.format(" or id eq \"%s\"", buddy.getId())));
// builds a search request
SearchRequest sr = new SearchRequest();
sr.setFilter(filter.substring(4));
// Retrieve only the first 3
sr.setCount(3);
// Performs the query
logger.info("Issuing query with filter: {}", sr.getFilter());
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
logger.info("Verifying groups and users consistency...");
List<BaseScimResource> buddies = response.readEntity(ListResponse.class).getResources();
assertEquals(buddies.size(), 3);
// Verify all mad belong to group, and one of them, additionally to group2
buddies.stream().map(usrClass::cast).forEach(buddy -> {
Set<String> groupIds = buddy.getGroups().stream().map(Group::getValue).collect(Collectors.toSet());
assertTrue(groupIds.contains(group.getId()));
});
Optional<UserResource> usrOpt = buddies.stream().map(usrClass::cast).filter(buddy -> buddy.getGroups().size() > 1).findFirst();
assertTrue(usrOpt.isPresent());
user = usrOpt.get();
assertTrue(user.getGroups().stream().map(Group::getValue).collect(Collectors.toSet()).contains(group2.getId()));
}
Aggregations