Search in sources :

Example 6 with FidoDevice

use of org.gluu.oxtrust.model.scim2.fido.FidoDevice 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)

Example 7 with FidoDevice

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

the class FidoDeviceWebService method updateDevice.

@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 device", notes = "Update device (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = FidoDevice.class)
public Response updateDevice(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "FidoDevice", required = true) FidoDevice fidoDevice, @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 (!id.equalsIgnoreCase(fidoDevice.getId())) {
            String detail = "Path param id does not match with device id";
            return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_VALUE, detail);
        } else {
            FidoDevice updatedFidoDevice = scim2FidoDeviceService.updateFidoDevice(id, fidoDevice);
            // Serialize to JSON
            String json = serializeToJson(updatedFidoDevice, attributesArray);
            URI location = new URI(updatedFidoDevice.getMeta().getLocation());
            return Response.ok(json).location(location).build();
        }
    } catch (EntryPersistenceException epe) {
        log.error("Failed to update device", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException dee) {
        log.error("DuplicateEntryException", dee);
        dee.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, dee.getMessage());
    } catch (Exception e) {
        log.error("Failed to update device", e);
        e.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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) 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 8 with FidoDevice

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

the class FidoDeviceWebService method getDeviceById.

@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 device by id", notes = "Returns a device by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = FidoDevice.class)
public Response getDeviceById(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @QueryParam("userId") final String userId, @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 baseDn = fidoDeviceService.getDnForFidoDevice(userId, id);
        log.info("##### baseDn = " + baseDn);
        String filterString = "id eq \"" + id + "\"";
        VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
        List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, 1, 1, "id", SortOrder.ASCENDING.getValue(), vlvResponse, attributesArray);
        if (gluuCustomFidoDevices == null || gluuCustomFidoDevices.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 ");
        }
        GluuCustomFidoDevice gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
        FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
        // Serialize to JSON
        String json = serializeToJson(fidoDevice, attributesArray);
        URI uriLocation = new URI(fidoDevice.getMeta().getLocation());
        return Response.ok(json).location(uriLocation).build();
    } catch (EntryPersistenceException epe) {
        log.error("Error in getDeviceById", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception e) {
        log.error("Error in getDeviceById", e);
        e.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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) 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 9 with FidoDevice

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

the class FidoDeviceWebService method searchDevices.

@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 devices", notes = "Returns a list of devices (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchDevices(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @QueryParam("userId") final String userId, @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 devices from LDAP ");
            String baseDn = fidoDeviceService.getDnForFidoDevice(userId, null);
            log.info("##### baseDn = " + baseDn);
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuCustomFidoDevice> gluuCustomFidoDevices = search(baseDn, GluuCustomFidoDevice.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            ListResponse devicesListResponse = new ListResponse();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.LIST_RESPONSE_SCHEMA_ID);
            log.info(" setting schema");
            devicesListResponse.setSchemas(schema);
            // Set total
            devicesListResponse.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty()) {
                for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
                    FidoDevice fidoDevice = copyUtils2.copy(gluuCustomFidoDevice, new FidoDevice());
                    devicesListResponse.getResources().add(fidoDevice);
                }
                // Set the rest of results info
                devicesListResponse.setItemsPerPage(vlvResponse.getItemsPerPage());
                devicesListResponse.setStartIndex(vlvResponse.getStartIndex());
            }
            // Serialize to JSON
            String json = serializeToJson(devicesListResponse, attributesArray);
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices");
            return Response.ok(json).location(location).build();
        }
    } catch (Exception e) {
        log.error("Error in searchDevices", e);
        e.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, 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) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) 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 10 with FidoDevice

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

the class ResourceTypeWS method getResourceTypeFidoDevice.

@Path("FidoDevice")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeFidoDevice(@HeaderParam("Authorization") String authorization) throws Exception {
    ResourceType fidoDeviceResourceType = new ResourceType();
    fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
    fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
    fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
    Meta fidoDeviceMeta = new Meta();
    fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    fidoDeviceMeta.setResourceType("ResourceType");
    fidoDeviceResourceType.setMeta(fidoDeviceMeta);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    return Response.ok(fidoDeviceResourceType).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) 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)

Aggregations

FidoDevice (org.gluu.oxtrust.model.scim2.fido.FidoDevice)6 URI (java.net.URI)5 DefaultValue (javax.ws.rs.DefaultValue)5 HeaderParam (javax.ws.rs.HeaderParam)5 Produces (javax.ws.rs.Produces)5 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)5 GET (javax.ws.rs.GET)4 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)4 Meta (org.gluu.oxtrust.model.scim2.Meta)4 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)4 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 Path (javax.ws.rs.Path)3 Response (javax.ws.rs.core.Response)3 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1