use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES in project jans by JanssenProject.
the class FidoDeviceWebService method updateDevice.
@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/fido.write" })
@RefAdjusted
public Response updateDevice(FidoDeviceResource fidoDeviceResource, @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. updateDevice");
// remove externalId, no place to store it in LDAP
fidoDeviceResource.setExternalId(null);
if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
throw new SCIMException("Parameter id does not match id attribute of Device");
String userId = fidoDeviceResource.getUserId();
GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
if (device == null)
return notFoundResponse(id, fidoResourceType);
response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fidoResourceType);
if (response != null)
return response;
executeValidation(fidoDeviceResource, true);
FidoDeviceResource updatedResource = new FidoDeviceResource();
transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
updatedResource = (FidoDeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
transferAttributesToDevice(updatedResource, device);
fidoDeviceService.updateGluuCustomFidoDevice(device);
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} catch (SCIMException e) {
log.error("Validation check error: {}", 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 updateDevice method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES in project jans by JanssenProject.
the class Fido2DeviceWebService method updateF2Device.
@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/fido2.write" })
@RefAdjusted
public Response updateF2Device(Fido2DeviceResource fidoDeviceResource, @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. updateDevice");
// remove externalId, no place to store it in LDAP
fidoDeviceResource.setExternalId(null);
if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
throw new SCIMException("Parameter id does not match id attribute of Device");
String userId = fidoDeviceResource.getUserId();
GluuFido2Device device = fidoDeviceService.getFido2DeviceById(userId, id);
if (device == null)
return notFoundResponse(id, fido2ResourceType);
response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fido2ResourceType);
if (response != null)
return response;
executeValidation(fidoDeviceResource, true);
Fido2DeviceResource updatedResource = new Fido2DeviceResource();
transferAttributesToFido2Resource(device, updatedResource, endpointUrl, userId);
updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
updatedResource = (Fido2DeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
transferAttributesToDevice(updatedResource, device);
fidoDeviceService.updateFido2Device(device);
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} catch (SCIMException e) {
log.error("Validation check error: {}", 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 updateDevice method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES 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.Constants.QUERY_PARAM_ATTRIBUTES in project jans by JanssenProject.
the class GroupWebService method updateGroup.
/**
* 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/groups.write" })
@RefAdjusted
public Response updateGroup(GroupResource group, @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. updateGroup");
// empty externalId, no place to store it in LDAP
group.setExternalId(null);
// Check if the ids match in case the group coming has one
if (group.getId() != null && !group.getId().equals(id))
throw new SCIMException("Parameter id does not match with id attribute of Group");
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null)
return notFoundResponse(id, groupResourceType);
response = externalConstraintsService.applyEntityCheck(gluuGroup, group, httpHeaders, uriInfo, HttpMethod.PUT, groupResourceType);
if (response != null)
return response;
executeValidation(group, true);
if (StringUtils.isNotEmpty(group.getDisplayName())) {
checkDisplayNameExistence(group.getDisplayName(), id);
}
boolean skipValidation = isMembersValidationSkipped();
boolean displayExcluded = isDisplayExcluded(skipValidation, attrsList, excludedAttrsList);
GroupResource updatedResource = scim2GroupService.updateGroup(gluuGroup, group, skipValidation, !displayExcluded, endpointUrl, usersUrl);
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 updateGroup 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 updateGroup method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of io.jans.scim.model.scim2.Constants.QUERY_PARAM_ATTRIBUTES in project jans by JanssenProject.
the class GroupWebService method getGroupById.
@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/groups.read" })
@RefAdjusted
public Response getGroupById(@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. getGroupById");
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null)
return notFoundResponse(id, groupResourceType);
response = externalConstraintsService.applyEntityCheck(gluuGroup, null, httpHeaders, uriInfo, HttpMethod.GET, groupResourceType);
if (response != null)
return response;
boolean displayExcluded = isDisplayExcluded(false, attrsList, excludedAttrsList);
GroupResource group = scim2GroupService.buildGroupResource(gluuGroup, !displayExcluded, endpointUrl, usersUrl);
String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
response = Response.ok(new URI(group.getMeta().getLocation())).entity(json).build();
} catch (Exception e) {
log.error("Failure at getGroupById method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations