Search in sources :

Example 1 with FidoDeviceResource

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

the class FidoDeviceWebService method searchDevices.

private ListViewResponse<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url) throws Exception {
    Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "oxId=*", FidoDeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
    ListViewResponse<GluuCustomFidoDevice> list = ldapEntryManager.findListViewResponse(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, startIndex, count, getMaxCount(), sortBy, sortOrder, null);
    List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
    for (GluuCustomFidoDevice device : list.getResult()) {
        FidoDeviceResource scimDev = new FidoDeviceResource();
        transferAttributesToFidoResource(device, scimDev, url, getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
    ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
    result.setResult(resources);
    result.setTotalResults(list.getTotalResults());
    return result;
}
Also used : GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) Filter(org.gluu.search.filter.Filter) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList)

Example 2 with FidoDeviceResource

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

the class FidoDeviceWebService method transferAttributesToFidoResource.

private void transferAttributesToFidoResource(GluuCustomFidoDevice fidoDevice, FidoDeviceResource res, String url, String userId) {
    res.setId(fidoDevice.getId());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    meta.setCreated(DateUtil.generalizedToISOStringDate(fidoDevice.getCreationDate()));
    meta.setLastModified(fidoDevice.getMetaLastModified());
    meta.setLocation(fidoDevice.getMetaLocation());
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + fidoDevice.getId());
    res.setMeta(meta);
    // Set values in order of appearance in FidoDeviceResource class
    res.setUserId(userId);
    res.setCreationDate(meta.getCreated());
    res.setApplication(fidoDevice.getApplication());
    res.setCounter(fidoDevice.getCounter());
    res.setDeviceData(fidoDevice.getDeviceData());
    res.setDeviceHashCode(fidoDevice.getDeviceHashCode());
    res.setDeviceKeyHandle(fidoDevice.getDeviceKeyHandle());
    res.setDeviceRegistrationConf(fidoDevice.getDeviceRegistrationConf());
    res.setLastAccessTime(DateUtil.generalizedToISOStringDate(fidoDevice.getLastAccessTime()));
    res.setStatus(fidoDevice.getStatus());
    res.setDisplayName(fidoDevice.getDisplayName());
    res.setDescription(fidoDevice.getDescription());
    res.setNickname(fidoDevice.getNickname());
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta)

Example 3 with FidoDeviceResource

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

the class BulkWebService method execute.

private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
    Response response = null;
    String idCreated = null;
    try {
        if (ws == userWS)
            switch(verb) {
                case PUT:
                    UserResource user = mapper.readValue(data, UserResource.class);
                    response = userWS.updateUser(user, fragment, "id", null);
                    break;
                case DELETE:
                    response = userWS.deleteUser(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = userWS.patchUser(pr, fragment, "id", null);
                    break;
                case POST:
                    user = mapper.readValue(data, UserResource.class);
                    response = userWS.createUser(user, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        user = mapper.readValue(response.getEntity().toString(), UserResource.class);
                        idCreated = user.getId();
                    }
                    break;
            }
        else if (ws == groupWS)
            switch(verb) {
                case PUT:
                    GroupResource group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.updateGroup(group, fragment, "id", null);
                    break;
                case DELETE:
                    response = groupWS.deleteGroup(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = groupWS.patchGroup(pr, fragment, "id", null);
                    break;
                case POST:
                    group = mapper.readValue(data, GroupResource.class);
                    response = groupWS.createGroup(group, "id", null);
                    if (CREATED.getStatusCode() == response.getStatus()) {
                        group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
                        idCreated = group.getId();
                    }
                    break;
            }
        else if (ws == fidoDeviceWS)
            switch(verb) {
                case PUT:
                    FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
                    response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
                    break;
                case DELETE:
                    response = fidoDeviceWS.deleteDevice(fragment);
                    break;
                case PATCH:
                    PatchRequest pr = mapper.readValue(data, PatchRequest.class);
                    response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
                    break;
                case POST:
                    response = fidoDeviceWS.createDevice();
                    break;
            }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return new Pair<Response, String>(response, idCreated);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Example 4 with FidoDeviceResource

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

the class FidoDeviceWebService method updateDevice.

@Path("{id}")
@PUT
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Update device", response = FidoDeviceResource.class)
public Response updateDevice(FidoDeviceResource fidoDeviceResource, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateDevice");
        String userId = fidoDeviceResource.getUserId();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            throw new SCIMException("Resource " + id + " not found");
        FidoDeviceResource updatedResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
        long now = System.currentTimeMillis();
        updatedResource.getMeta().setLastModified(ISODateTimeFormat.dateTime().withZoneUTC().print(now));
        updatedResource = (FidoDeviceResource) ScimResourceUtil.transferToResourceReplace(fidoDeviceResource, updatedResource, extService.getResourceExtensions(updatedResource.getClass()));
        transferAttributesToDevice(updatedResource, device);
        fidoDeviceService.updateGluuCustomFidoDevice(device);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 5 with FidoDeviceResource

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

the class FidoDeviceWebService method getDeviceById.

@Path("{id}")
@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Find device by id", notes = "Returns a device by id as path param", response = FidoDeviceResource.class)
public Response getDeviceById(@PathParam("id") String id, @QueryParam("userId") String userId, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. getDeviceById");
        FidoDeviceResource fidoResource = new FidoDeviceResource();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            throw new SCIMException("Resource " + id + " not found");
        transferAttributesToFidoResource(device, fidoResource, endpointUrl, userId);
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } catch (SCIMException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at getDeviceById method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

FidoDeviceResource (org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource)4 Response (javax.ws.rs.core.Response)3 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)3 ListViewResponse (org.gluu.persist.model.ListViewResponse)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 URI (java.net.URI)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 DefaultValue (javax.ws.rs.DefaultValue)2 HeaderParam (javax.ws.rs.HeaderParam)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)2 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)2 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)2 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)2 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 BaseScimResource (org.gluu.oxtrust.model.scim2.BaseScimResource)1