use of org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
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
@RefAdjusted
@ApiOperation(value = "Update group", notes = "Update group (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = GroupResource.class)
public Response updateGroup(@ApiParam(value = "Group", required = true) 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");
GroupResource updatedResource = scim2GroupService.updateGroup(id, group, endpointUrl, userWebService.getEndpointUrl());
String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
} 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 org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
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
@RefAdjusted
@ApiOperation(value = "PATCH operation", notes = "https://tools.ietf.org/html/rfc7644#section-3.5.2", response = GroupResource.class)
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");
String usersUrl = userWebService.getEndpointUrl();
GroupResource group = new GroupResource();
// group is not null (check associated decorator method)
GluuGroup gluuGroup = groupService.getGroupByInum(id);
// Fill group instance with all info from gluuGroup
scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, endpointUrl, usersUrl);
// Apply patches one by one in sequence
for (PatchOperation po : request.getOperations()) group = (GroupResource) scim2PatchService.applyPatchOperation(group, po);
// Throws exception if final representation does not pass overall validation
log.debug("patchGroup. Revising final resource representation still passes validations");
executeDefaultValidation(group);
// Update timestamp
String now = ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis());
group.getMeta().setLastModified(now);
// Replaces the information found in gluuGroup with the contents of group
scim2GroupService.replaceGroupInfo(gluuGroup, group, endpointUrl, usersUrl);
String json = resourceSerializer.serialize(group, attrsList, excludedAttrsList);
response = Response.ok(new URI(group.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 patchGroup method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
use of org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
the class Scim2GroupService method transferAttributesToGroupResource.
public void transferAttributesToGroupResource(GluuGroup gluuGroup, GroupResource res, String groupsUrl, String usersUrl) {
res.setId(gluuGroup.getInum());
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(gluuGroup.getAttribute("oxTrustMetaCreated"));
meta.setLastModified(gluuGroup.getAttribute("oxTrustMetaLastModified"));
meta.setLocation(gluuGroup.getAttribute("oxTrustMetaLocation"));
if (meta.getLocation() == null)
meta.setLocation(groupsUrl + "/" + gluuGroup.getInum());
res.setMeta(meta);
res.setDisplayName(gluuGroup.getDisplayName());
// Transfer members from GluuGroup to GroupResource
List<String> memberDNs = gluuGroup.getMembers();
if (memberDNs != null) {
Set<Member> members = new HashSet<Member>();
for (String dn : memberDNs) {
GluuCustomPerson person = null;
try {
person = personService.getPersonByDn(dn);
} catch (Exception e) {
log.warn("Wrong member entry {} found in group {}", dn, gluuGroup.getDisplayName());
}
if (person != null) {
Member aMember = new Member();
aMember.setValue(person.getInum());
aMember.setRef(usersUrl + "/" + person.getInum());
aMember.setType(ScimResourceUtil.getType(UserResource.class));
aMember.setDisplay(person.getDisplayName());
members.add(aMember);
}
}
res.setMembers(members);
}
}
use of org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
the class Scim2GroupService method searchGroups.
public ListViewResponse<BaseScimResource> searchGroups(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String groupsUrl, String usersUrl, int maxCount) throws Exception {
Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", GroupResource.class);
log.info("Executing search for groups using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
ListViewResponse<GluuGroup> list = ldapEntryManager.findListViewResponse(groupService.getDnForGroup(null), GluuGroup.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
for (GluuGroup group : list.getResult()) {
GroupResource scimGroup = new GroupResource();
transferAttributesToGroupResource(group, scimGroup, groupsUrl, usersUrl);
// TODO: Delete this IF in the future - added for backwards compatibility with SCIM-Client <= 3.1.2.
if (scimGroup.getMembers() == null)
scimGroup.setMembers(new HashSet<Member>());
resources.add(scimGroup);
}
log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
result.setResult(resources);
result.setTotalResults(list.getTotalResults());
return result;
}
use of org.gluu.oxtrust.model.scim2.group.GroupResource in project oxTrust by GluuFederation.
the class Scim2GroupService method updateGroup.
public GroupResource updateGroup(String id, GroupResource group, String groupsUrl, String usersUrl) throws Exception {
// This is never null (see decorator involved)
GluuGroup gluuGroup = groupService.getGroupByInum(id);
GroupResource tmpGroup = new GroupResource();
transferAttributesToGroupResource(gluuGroup, tmpGroup, groupsUrl, usersUrl);
long now = System.currentTimeMillis();
tmpGroup.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
tmpGroup = (GroupResource) ScimResourceUtil.transferToResourceReplace(group, tmpGroup, extService.getResourceExtensions(group.getClass()));
replaceGroupInfo(gluuGroup, tmpGroup, groupsUrl, usersUrl);
return tmpGroup;
}
Aggregations