Search in sources :

Example 16 with Resource

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

the class GroupWebService method deleteGroup.

@Path("{id}")
@DELETE
@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 = "Delete group", notes = "Delete group (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id) 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 {
        scim2GroupService.deleteGroup(id);
        return Response.noContent().build();
    } catch (EntryPersistenceException ex) {
        log.error("Failed to delete group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, "Resource " + id + " not found");
    } catch (Exception ex) {
        log.error("Failed to delete group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) 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)

Example 17 with Resource

use of org.gluu.oxtrust.model.scim2.Resource 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);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) 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) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 18 with Resource

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

the class GroupWebService method updateGroup.

@Path("{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "Update group", notes = "Update group (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = Group.class)
public Response updateGroup(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "Group", required = true) Group group, @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 {
        Group updatedGroup = scim2GroupService.updateGroup(id, group);
        // Serialize to JSON
        String json = serializeToJson(updatedGroup, attributesArray);
        URI location = new URI(updatedGroup.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Failed to update group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to update group", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 19 with Resource

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

the class UserWebService method searchUsersPost.

@Path("/.search")
@POST
@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 users POST /.search", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchUsersPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN UserWebService.searchUsersPost()...");
        // Authorization check is done in searchUsers()
        Response response = searchUsers(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Users/.search");
        log.info("LEAVING UserWebService.searchUsersPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in searchUsersPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception ex) {
        log.error("Error in searchUsersPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 20 with Resource

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

the class Scim2FidoDeviceService method updateFidoDevice.

public FidoDevice updateFidoDevice(String id, FidoDevice fidoDevice) throws Exception {
    GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(fidoDevice.getUserId(), id);
    if (gluuCustomFidoDevice == null) {
        throw new EntryPersistenceException("Scim2FidoDeviceService.updateFidoDevice(): Resource " + id + " not found");
    }
    GluuCustomFidoDevice updatedGluuCustomFidoDevice = copyUtils2.updateGluuCustomFidoDevice(fidoDevice, gluuCustomFidoDevice);
    log.info(" Setting meta: update device ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuCustomFidoDevice.setMetaLastModified(dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuCustomFidoDevice.getMetaLocation() == null || (updatedGluuCustomFidoDevice.getMetaLocation() != null && updatedGluuCustomFidoDevice.getMetaLocation().isEmpty())) {
        String relativeLocation = "/scim/v2/FidoDevices/" + id;
        updatedGluuCustomFidoDevice.setMetaLocation(relativeLocation);
    }
    fidoDeviceService.updateGluuCustomFidoDevice(gluuCustomFidoDevice);
    FidoDevice updatedFidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
    return updatedFidoDevice;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Aggregations

EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)18 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)17 DefaultValue (javax.ws.rs.DefaultValue)15 HeaderParam (javax.ws.rs.HeaderParam)15 Produces (javax.ws.rs.Produces)15 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)15 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)13 Path (javax.ws.rs.Path)13 Response (javax.ws.rs.core.Response)13 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)13 URI (java.net.URI)12 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)7 User (org.gluu.oxtrust.model.scim2.User)6 GET (javax.ws.rs.GET)5 Date (java.util.Date)4 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 Group (org.gluu.oxtrust.model.scim2.Group)4