use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.
the class SearchResourcesWebService method search.
@POST
@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/all-resources.search" })
@RefAdjusted
public Response search(SearchRequest searchRequest) {
SearchRequest searchReq = new SearchRequest();
Response response = prepareSearchRequest(searchRequest.getSchemas(), searchRequest.getFilter(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), searchReq);
if (response == null) {
try {
List<JsonNode> resources = new ArrayList<>();
Pair<Integer, Integer> totals = computeResults(searchReq, resources);
ListResponseJsonSerializer custSerializer = new ListResponseJsonSerializer(resourceSerializer, searchReq.getAttributesStr(), searchReq.getExcludedAttributesStr(), searchReq.getCount() == 0);
if (resources.size() > 0)
custSerializer.setJsonResources(resources);
ObjectMapper objmapper = new ObjectMapper();
SimpleModule module = new SimpleModule("ListResponseModule", Version.unknownVersion());
module.addSerializer(ListResponse.class, custSerializer);
objmapper.registerModule(module);
// Provide to constructor original start index, and totals calculated in computeResults call
ListResponse listResponse = new ListResponse(searchReq.getStartIndex(), totals.getFirst(), totals.getSecond());
String json = objmapper.writeValueAsString(listResponse);
response = Response.ok(json).location(new URI(endpointUrl)).build();
} catch (Exception e) {
log.error("Failure at search method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
}
return response;
}
use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.
the class UserWebService method deleteUser.
@Path("{id}")
@DELETE
@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" })
public Response deleteUser(@PathParam("id") String id) {
Response response;
try {
log.debug("Executing web service method. deleteUser");
ScimCustomPerson person = userPersistenceHelper.getPersonByInum(id);
if (person == null)
return notFoundResponse(id, userResourceType);
response = externalConstraintsService.applyEntityCheck(person, null, httpHeaders, uriInfo, HttpMethod.DELETE, userResourceType);
if (response != null)
return response;
scim2UserService.deleteUser(person);
response = Response.noContent().build();
} catch (Exception e) {
log.error("Failure at deleteUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.service.filter.ProtectedApi in project jans by JanssenProject.
the class UserWebService method createUser.
@POST
@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 createUser(UserResource user, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
Response response;
try {
log.debug("Executing web service method. createUser");
executeValidation(user);
checkUidExistence(user.getUserName());
assignMetaInformation(user);
ScimResourceUtil.adjustPrimarySubAttributes(user);
ScimCustomPerson person = scim2UserService.preCreateUser(user);
response = externalConstraintsService.applyEntityCheck(person, user, httpHeaders, uriInfo, HttpMethod.POST, userResourceType);
if (response != null)
return response;
scim2UserService.createUser(person, user, endpointUrl);
String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
response = Response.created(new URI(user.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 createUser returned: {}", e.getMessage());
response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, e.getMessage());
} catch (Exception e) {
log.error("Failure at createUser method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.service.filter.ProtectedApi 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.service.filter.ProtectedApi in project jans by JanssenProject.
the class UserWebService method searchUsersPost.
@Path(SEARCH_SUFFIX)
@POST
@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.read" })
@RefAdjusted
public Response searchUsersPost(SearchRequest searchRequest) {
log.debug("Executing web service method. searchUsersPost");
Response response = doSearch(searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr(), HttpMethod.POST);
URI uri = null;
try {
uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
} catch (URISyntaxException e) {
log.error(e.getMessage(), e);
}
return Response.fromResponse(response).location(uri).build();
}
Aggregations