Search in sources :

Example 1 with GluuCustomFidoDevice

use of io.jans.scim.model.fido.GluuCustomFidoDevice in project jans by JanssenProject.

the class FidoDeviceWebService method searchDevices.

private PagedResult<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count) throws Exception {
    Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("jansId"), FidoDeviceResource.class);
    log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}', userId '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count, userId);
    // Currently, searching with SUB scope in Couchbase requires some help (beyond use of baseDN)
    if (StringUtils.isNotEmpty(userId)) {
        ldapFilter = Filter.createANDFilter(ldapFilter, Filter.createEqualityFilter("personInum", userId));
    }
    PagedResult<GluuCustomFidoDevice> list;
    try {
        list = entryManager.findPagedEntries(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, getMaxCount());
    } catch (Exception e) {
        log.info("Returning an empty listViewReponse");
        log.error(e.getMessage(), e);
        list = new PagedResult<>();
        list.setEntries(new ArrayList<>());
    }
    List<BaseScimResource> resources = new ArrayList<>();
    for (GluuCustomFidoDevice device : list.getEntries()) {
        FidoDeviceResource scimDev = new FidoDeviceResource();
        transferAttributesToFidoResource(device, scimDev, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        resources.add(scimDev);
    }
    log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
    PagedResult<BaseScimResource> result = new PagedResult<>();
    result.setEntries(resources);
    result.setTotalEntriesCount(list.getTotalEntriesCount());
    return result;
}
Also used : GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) Filter(io.jans.orm.search.filter.Filter) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) PagedResult(io.jans.orm.model.PagedResult)

Example 2 with GluuCustomFidoDevice

use of io.jans.scim.model.fido.GluuCustomFidoDevice in project jans by JanssenProject.

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(scopes = { "https://jans.io/scim/fido.write" })
@RefAdjusted
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");
        // remove externalId, no place to store it in LDAP
        fidoDeviceResource.setExternalId(null);
        if (fidoDeviceResource.getId() != null && !fidoDeviceResource.getId().equals(id))
            throw new SCIMException("Parameter id does not match id attribute of Device");
        String userId = fidoDeviceResource.getUserId();
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, fidoDeviceResource, httpHeaders, uriInfo, HttpMethod.PUT, fidoResourceType);
        if (response != null)
            return response;
        executeValidation(fidoDeviceResource, true);
        FidoDeviceResource updatedResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, updatedResource, endpointUrl, userId);
        updatedResource.getMeta().setLastModified(DateUtil.millisToISOString(System.currentTimeMillis()));
        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("Validation check error: {}", e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, 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 : Response(javax.ws.rs.core.Response) SCIMException(io.jans.scim.model.exception.SCIMException) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ProtectedApi(io.jans.scim.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 3 with GluuCustomFidoDevice

use of io.jans.scim.model.fido.GluuCustomFidoDevice in project jans by JanssenProject.

the class FidoDeviceWebService method deleteDevice.

@Path("{id}")
@DELETE
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi(scopes = { "https://jans.io/scim/fido.write" })
public Response deleteDevice(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteDevice");
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.DELETE, fidoResourceType);
        if (response != null)
            return response;
        fidoDeviceService.removeGluuCustomFidoDevice(device);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteDevice method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) 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) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Example 4 with GluuCustomFidoDevice

use of io.jans.scim.model.fido.GluuCustomFidoDevice in project jans by JanssenProject.

the class FidoDeviceService method getGluuCustomFidoDeviceById.

public GluuCustomFidoDevice getGluuCustomFidoDeviceById(String userId, String id) {
    GluuCustomFidoDevice gluuCustomFidoDevice = null;
    try {
        String dn = getDnForFidoDevice(userId, id);
        if (StringUtils.isNotEmpty(userId))
            gluuCustomFidoDevice = ldapEntryManager.find(GluuCustomFidoDevice.class, dn);
        else {
            Filter filter = Filter.createEqualityFilter("jansId", id);
            gluuCustomFidoDevice = ldapEntryManager.findEntries(dn, GluuCustomFidoDevice.class, filter).get(0);
        }
    } catch (Exception e) {
        log.error("Failed to find device by id " + id, e);
    }
    return gluuCustomFidoDevice;
}
Also used : GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) Filter(io.jans.orm.search.filter.Filter)

Example 5 with GluuCustomFidoDevice

use of io.jans.scim.model.fido.GluuCustomFidoDevice in project jans by JanssenProject.

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(scopes = { "https://jans.io/scim/fido.read" })
@RefAdjusted
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");
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(userId, id);
        if (device == null)
            return notFoundResponse(id, fidoResourceType);
        response = externalConstraintsService.applyEntityCheck(device, null, httpHeaders, uriInfo, HttpMethod.GET, fidoResourceType);
        if (response != null)
            return response;
        FidoDeviceResource fidoResource = new FidoDeviceResource();
        transferAttributesToFidoResource(device, fidoResource, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
        String json = resourceSerializer.serialize(fidoResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(fidoResource.getMeta().getLocation())).entity(json).build();
    } 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 : Response(javax.ws.rs.core.Response) GluuCustomFidoDevice(io.jans.scim.model.fido.GluuCustomFidoDevice) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) SCIMException(io.jans.scim.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(io.jans.scim.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(io.jans.scim.service.filter.ProtectedApi)

Aggregations

GluuCustomFidoDevice (io.jans.scim.model.fido.GluuCustomFidoDevice)6 SCIMException (io.jans.scim.model.exception.SCIMException)4 URISyntaxException (java.net.URISyntaxException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 FidoDeviceResource (io.jans.scim.model.scim2.fido.FidoDeviceResource)3 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)3 DefaultValue (javax.ws.rs.DefaultValue)3 HeaderParam (javax.ws.rs.HeaderParam)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 Filter (io.jans.orm.search.filter.Filter)2 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)2 URI (java.net.URI)2 PagedResult (io.jans.orm.model.PagedResult)1 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1