use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebService method getGroupById.
@Path("{id}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getGroupById(@HeaderParam("Authorization") String authorization, @PathParam("id") String id) throws Exception {
Response authorizationResponse = processAuthorization(authorization);
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
GluuGroup gluuGroup = groupService.getGroupByInum(id);
if (gluuGroup == null) {
// sets HTTP status code 404 Not Found
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
}
ScimGroup group = copyUtils.copy(gluuGroup, null);
URI location = new URI("/Groups/" + id);
return Response.ok(group).location(location).build();
} catch (EntryPersistenceException ex) {
ex.printStackTrace();
return getErrorResponse("Resource " + id + " not found", Response.Status.NOT_FOUND.getStatusCode());
} catch (Exception ex) {
ex.printStackTrace();
return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class MemberService method removePerson.
public void removePerson(GluuCustomPerson person) {
// TODO: Do we realy need to remove group if owner is removed?
List<GluuGroup> groups = groupService.getAllGroups();
for (GluuGroup group : groups) {
if (StringHelper.equalsIgnoreCase(group.getOwner(), person.getDn())) {
groupService.removeGroup(group);
}
}
// Remove person
personService.removePerson(person);
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupService method countGroups.
/* (non-Javadoc)
* @see org.gluu.oxtrust.ldap.service.IGroupService#countGroups()
*/
@Override
public int countGroups() {
GluuGroup gluuGroup = new GluuGroup();
gluuGroup.setBaseDn(getDnForGroup(null));
return ldapEntryManager.countEntries(gluuGroup);
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class ServiceUtil method deleteUserFromGroup.
/**
* Delete a person from a group
*
* @return void
* @throws Exception
*/
public void deleteUserFromGroup(GluuCustomPerson person, String dn) throws Exception {
List<String> groups = person.getMemberOf();
for (String oneGroup : groups) {
GluuGroup aGroup = groupService.getGroupByDn(oneGroup);
List<String> groupMembers = aGroup.getMembers();
List<String> tempGroupMembers = new ArrayList<String>();
if (groupMembers != null && !groupMembers.isEmpty()) {
for (String aMember : groupMembers) {
tempGroupMembers.add(aMember);
}
}
for (String oneMember : tempGroupMembers) {
if (oneMember.equalsIgnoreCase(dn)) {
tempGroupMembers.remove(oneMember);
break;
}
}
List<String> cleanGroupMembers = new ArrayList<String>();
for (String aMember : tempGroupMembers) {
cleanGroupMembers.add(aMember);
}
aGroup.setMembers(cleanGroupMembers);
if (aGroup.getMembers() != null && aGroup.getMembers().isEmpty()) {
// Reset to no members
aGroup.setMembers(null);
}
groupService.updateGroup(aGroup);
}
}
use of org.gluu.oxtrust.model.GluuGroup 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;
}
Aggregations