Search in sources :

Example 46 with GluuGroup

use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.

the class GroupWebService method deleteGroup.

@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
@ApiOperation(value = "Delete group", notes = "Delete group (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteGroup(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteGroup");
        // group cannot be null (check associated decorator method)
        GluuGroup gr = groupService.getGroupByInum(id);
        scim2GroupService.deleteGroup(gr);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteGroup method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuGroup(org.gluu.oxtrust.model.GluuGroup) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 47 with GluuGroup

use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.

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
@RefAdjusted
@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 = GroupResource.class)
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");
        GroupResource group = new GroupResource();
        // gluuGroup is not null (check associated decorator method)
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        scim2GroupService.transferAttributesToGroupResource(gluuGroup, group, endpointUrl, userWebService.getEndpointUrl());
        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;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 48 with GluuGroup

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);
                    countRemoved++;
                } catch (EntryPersistenceException ex) {
                    System.out.println("Failed to remove group: " + ex.getMessage());
                }
            }
        }
    }
    System.out.println("Removed Persons: " + countRemoved);
}
Also used : EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Parameters(org.testng.annotations.Parameters)

Example 49 with GluuGroup

use of org.gluu.oxtrust.model.GluuGroup in project oxTrust by GluuFederation.

the class GroupService method generateInumForNewGroup.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.gluu.oxtrust.ldap.service.IGroupService#generateInumForNewGroup()
	 */
@Override
public String generateInumForNewGroup() throws Exception {
    GluuGroup group = new GluuGroup();
    String newInum = null;
    String newDn = null;
    do {
        newInum = generateInumForNewGroupImpl();
        newDn = getDnForGroup(newInum);
        group.setDn(newDn);
    } while (persistenceEntryManager.contains(newDn, GluuCustomPerson.class));
    return newInum;
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 50 with GluuGroup

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(identity.getUser().getDn());
    this.group.setOrganization(organizationService.getOrganization().getDn());
    this.group.setStatus(GluuStatus.ACTIVE);
    try {
        this.members = getMemberDisplayNameEntiries();
    } catch (BasePersistenceException ex) {
        log.error("Failed to prepare lists", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new group");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Aggregations

GluuGroup (org.gluu.oxtrust.model.GluuGroup)56 ArrayList (java.util.ArrayList)15 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)13 Produces (javax.ws.rs.Produces)11 Response (javax.ws.rs.core.Response)11 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)11 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)10 Operation (io.swagger.v3.oas.annotations.Operation)7 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)7 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)6 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)6 DefaultValue (javax.ws.rs.DefaultValue)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 Group (org.gluu.oxtrust.model.scim2.Group)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Consumes (javax.ws.rs.Consumes)4