Search in sources :

Example 6 with ScimGroup

use of org.gluu.oxtrust.model.scim.ScimGroup 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());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with ScimGroup

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

the class GroupWebService method searchGroups.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @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 = 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(detail, Response.Status.BAD_REQUEST.getStatusCode());
        } else {
            log.info(" Searching groups from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuGroup> gluuGroups = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuGroup> groupList = groupService.getAllGroupsList();
            GluuGroupList groupsList = new GluuGroupList();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
            log.info(" setting schema");
            groupsList.setSchemas(schema);
            // Set total
            groupsList.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuGroups != null && !gluuGroups.isEmpty()) {
                for (GluuGroup gluuGroup : gluuGroups) {
                    ScimGroup group = copyUtils.copy(gluuGroup, null);
                    log.info(" group to be added displayName : " + group.getDisplayName());
                    groupsList.getResources().add(group);
                    log.info(" group added? : " + groupsList.getResources().contains(group));
                }
                // Set the rest of results info
                groupsList.setItemsPerPage(vlvResponse.getItemsPerPage());
                groupsList.setStartIndex(vlvResponse.getStartIndex());
            }
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Groups");
            // Serialize to JSON
            ObjectMapper mapper = new ObjectMapper();
            mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
            SimpleModule customScimFilterModule = new SimpleModule("CustomScim1GroupFilterModule", new Version(1, 0, 0, ""));
            GluuGroupListSerializer serializer = new GluuGroupListSerializer();
            serializer.setAttributesArray(attributesArray);
            customScimFilterModule.addSerializer(ScimGroup.class, serializer);
            mapper.registerModule(customScimFilterModule);
            String json = mapper.writeValueAsString(groupsList);
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchGroups", ex);
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GluuGroupListSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.GluuGroupListSerializer) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuGroupList(org.gluu.oxtrust.model.GluuGroupList) Version(org.codehaus.jackson.Version) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)6 Produces (javax.ws.rs.Produces)5 Response (javax.ws.rs.core.Response)5 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)5 URI (java.net.URI)4 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)4 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)4 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)3 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 IOException (java.io.IOException)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashSet (java.util.HashSet)1 DefaultValue (javax.ws.rs.DefaultValue)1 HeaderParam (javax.ws.rs.HeaderParam)1