Search in sources :

Example 6 with GluuCustomFidoDevice

use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice 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 7 with GluuCustomFidoDevice

use of org.gluu.oxtrust.model.fido.GluuCustomFidoDevice 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 8 with GluuCustomFidoDevice

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

the class Scim2FidoDeviceService method deleteFidoDevice.

public void deleteFidoDevice(String id) throws Exception {
    GluuCustomFidoDevice gluuCustomFidoDevice = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
    if (gluuCustomFidoDevice == null) {
        throw new EntryPersistenceException("Scim2FidoDeviceService.deleteFidoDevice(): Resource " + id + " not found");
    }
    fidoDeviceService.removeGluuCustomFidoDevice(gluuCustomFidoDevice);
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Aggregations

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