Search in sources :

Example 1 with GluuCustomFidoDevice

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

the class FidoDeviceService method searchFidoDevice.

private GluuCustomFidoDevice searchFidoDevice(Filter filter, String userId, String id) throws Exception {
    GluuCustomFidoDevice gluuCustomFidoDevice = null;
    VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
    List<GluuCustomFidoDevice> gluuCustomFidoDevices = ldapEntryManager.findEntriesVirtualListView(getDnForFidoDevice(userId, id), GluuCustomFidoDevice.class, filter, 1, 1, "oxId", SortOrder.ASCENDING, vlvResponse, null);
    if (gluuCustomFidoDevices != null && !gluuCustomFidoDevices.isEmpty() && vlvResponse.getTotalResults() > 0) {
        gluuCustomFidoDevice = gluuCustomFidoDevices.get(0);
    }
    return gluuCustomFidoDevice;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse)

Example 2 with GluuCustomFidoDevice

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

the class FidoDeviceService method getGluuCustomFidoDeviceById.

@Override
public GluuCustomFidoDevice getGluuCustomFidoDeviceById(String userId, String id) {
    GluuCustomFidoDevice gluuCustomFidoDevice = null;
    try {
        Filter filter = Filter.create("oxId=" + id);
        gluuCustomFidoDevice = searchFidoDevice(filter, userId, id);
    } catch (Exception e) {
        log.error("Failed to find device by id " + id, e);
    }
    return gluuCustomFidoDevice;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) Filter(com.unboundid.ldap.sdk.Filter)

Example 3 with GluuCustomFidoDevice

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

the class CopyUtils2 method updateGluuCustomFidoDevice.

public GluuCustomFidoDevice updateGluuCustomFidoDevice(FidoDevice source, GluuCustomFidoDevice destination) {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new GluuCustomFidoDevice();
    }
    // Only update displayName and description
    // All the other fields are not editable
    destination.setDisplayName(source.getDisplayName());
    destination.setDescription(source.getDescription());
    return destination;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)

Example 4 with GluuCustomFidoDevice

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

the class CopyUtils2 method copy.

public FidoDevice copy(GluuCustomFidoDevice source, FidoDevice destination) {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new FidoDevice();
    }
    destination.setId(source.getId());
    destination.setCreationDate(source.getCreationDate());
    destination.setApplication(source.getApplication());
    destination.setCounter(source.getCounter());
    destination.setDeviceData(source.getDeviceData());
    destination.setDeviceHashCode(source.getDeviceHashCode());
    destination.setDeviceKeyHandle(source.getDeviceKeyHandle());
    destination.setDeviceRegistrationConf(source.getDeviceRegistrationConf());
    destination.setLastAccessTime(source.getLastAccessTime());
    destination.setStatus(source.getStatus());
    destination.setDisplayName(source.getDisplayName());
    destination.setDescription(source.getDescription());
    if (source.getDn() != null) {
        String[] dnArray = source.getDn().split("\\,");
        for (String e : dnArray) {
            if (e.startsWith("inum=")) {
                String[] inumArray = e.split("\\=");
                if (inumArray.length > 1) {
                    destination.setUserId(inumArray[1]);
                }
            }
        }
    }
    Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
    if (source.getMetaVersion() != null) {
        meta.setVersion(source.getMetaVersion());
    }
    String location = source.getMetaLocation();
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/" + source.getId();
    }
    meta.setLocation(location);
    if (source.getCreationDate() != null && !source.getCreationDate().isEmpty()) {
        try {
            meta.setCreated(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getCreationDate()));
        } catch (Exception e) {
            log.error(" Date parse exception (OLD format)", e);
        }
    }
    if (source.getMetaLastModified() != null && !source.getMetaLastModified().isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getMetaLastModified(), DateTimeZone.UTC);
            meta.setLastModified(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            try {
                meta.setLastModified(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getMetaLastModified()));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    destination.setMeta(meta);
    return destination;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) FidoDevice(org.gluu.oxtrust.model.scim2.fido.FidoDevice) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) SimpleDateFormat(java.text.SimpleDateFormat) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DateTime(org.joda.time.DateTime)

Example 5 with GluuCustomFidoDevice

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

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