use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class ServiceUtil method groupMembersAdder.
/**
* Adds a person to a group
*
* @return void
* @throws Exception
*/
public void groupMembersAdder(GluuCustomPerson gluuPerson, String dn) throws Exception {
List<String> groups = gluuPerson.getMemberOf();
for (String group : groups) {
GluuGroup oneGroup = groupService.getGroupByDn(group);
List<String> groupMembers = oneGroup.getMembers();
if ((groupMembers != null && !groupMembers.isEmpty()) && !isMemberExist(groupMembers, dn)) {
List<String> cleanGroupMembers = new ArrayList<String>();
cleanGroupMembers.add(dn);
for (String personDN : groupMembers) {
cleanGroupMembers.add(personDN);
}
oneGroup.setMembers(cleanGroupMembers);
groupService.updateGroup(oneGroup);
}
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class UpdateGroupAction method add.
public String add() throws Exception {
if (this.group != null) {
return OxTrustConstants.RESULT_SUCCESS;
}
this.update = false;
this.group = new GluuGroup();
this.group.setOwner(currentPerson.getDn());
this.group.setOrganization(organizationService.getOrganization().getDn());
try {
this.members = getMemberDisplayNameEntiries();
} catch (LdapMappingException ex) {
log.error("Failed to load person display names", ex);
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebService method getGroupById.
@Path("{id}")
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Find group by id", notes = "Returns a group by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.2.1)", response = Group.class)
public Response getGroupById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
String filterString = "id eq \"" + id + "\"";
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
if (groupList == null || groupList.isEmpty() || vlvResponse.getTotalResults() == 0) {
// sets HTTP status code 404 Not Found
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} else {
log.info(" Resource " + id + " found ");
}
GluuGroup gluuGroup = groupList.get(0);
Group group = copyUtils2.copy(gluuGroup, null);
// Serialize to JSON
String json = serializeToJson(group, attributesArray);
URI location = new URI(group.getMeta().getLocation());
return Response.ok(json).location(location).build();
} catch (EntryPersistenceException ex) {
log.error("Error in getGroupById", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
} catch (Exception ex) {
log.error("Error in getGroupById", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class GroupWebService method searchGroups.
@GET
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search groups", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
Response authorizationResponse;
if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
log.info(" ##### SCIM Test Mode is ACTIVE");
authorizationResponse = processTestModeAuthorization(token);
} else {
authorizationResponse = processAuthorization(authorization);
}
if (authorizationResponse != null) {
return authorizationResponse;
}
try {
if (count > getMaxCount()) {
String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.TOO_MANY, detail);
} else {
log.info(" Searching groups from LDAP ");
VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
List<GluuGroup> groupList = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
// List<GluuGroup> groupList = groupService.getAllGroupsList();
ListResponse groupsListResponse = new ListResponse();
List<String> schema = new ArrayList<String>();
schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
log.info(" setting schema");
groupsListResponse.setSchemas(schema);
// Set total
groupsListResponse.setTotalResults(vlvResponse.getTotalResults());
if (count > 0 && groupList != null && !groupList.isEmpty()) {
for (GluuGroup gluuGroup : groupList) {
Group group = copyUtils2.copy(gluuGroup, null);
log.info(" group to be added displayName : " + group.getDisplayName());
groupsListResponse.getResources().add(group);
log.info(" group added? : " + groupsListResponse.getResources().contains(group));
}
// Set the rest of results info
groupsListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
groupsListResponse.setStartIndex(vlvResponse.getStartIndex());
}
// Serialize to JSON
String json = serializeToJson(groupsListResponse, attributesArray);
URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups");
return Response.ok(json).location(location).build();
}
} catch (Exception ex) {
log.error("Error in searchGroups", ex);
ex.printStackTrace();
return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.
the class CleanUpTest method cleanUpGroups.
/**
* Test search
*
* @throws Exception
*/
@Test
@Parameters(value = "test.keep.persons")
public void cleanUpGroups(String usedGroups) throws Exception {
System.out.println("cleanup person Test initialted ");
assertNotNull(usedGroups);
List<String> usedGroupsList = Arrays.asList(StringHelper.split(usedGroups, ",", true, false));
System.out.println("Used Groups: " + usedGroupsList);
int groupsResultSetSize = 50;
int countResults = 0;
int countRemoved = 0;
boolean existsMoreGroups = true;
while (existsMoreGroups && countResults < 10000) {
List<GluuGroup> groups = groupsService.getAllGroups();
existsMoreGroups = groups.size() == groupsResultSetSize;
countResults += groups.size();
assertNotNull(groups);
System.out.println("Found groups: " + groups.size());
System.out.println("Total groups: " + countResults);
for (GluuGroup group : groups) {
// String clientId = person.getClientId();
if (!usedGroupsList.contains(group.getInum())) {
try {
groupsService.removeGroup(group);
} catch (EntryPersistenceException ex) {
System.out.println("Failed to remove person: " + ex.getMessage());
}
countRemoved++;
}
}
}
System.out.println("Removed Persons: " + countRemoved);
}
Aggregations