Search in sources :

Example 11 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class PassportRestWebService method getPassportConfig.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@ProtectedApi
public Response getPassportConfig() {
    PassportConfigResponse passportConfigResponse = new PassportConfigResponse();
    Map<String, Map> strategies = new HashMap<String, Map>();
    LdapOxPassportConfiguration ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
    if (ldapOxPassportConfiguration != null) {
        for (org.xdi.model.passport.PassportConfiguration passportConfiguration : ldapOxPassportConfiguration.getPassportConfigurations()) {
            if (passportConfiguration != null) {
                Map<String, String> map = new HashMap<String, String>();
                List<SimpleExtendedCustomProperty> passList = passportConfiguration.getFieldset();
                if (passList != null) {
                    for (SimpleExtendedCustomProperty fieldset : passList) {
                        map.put(fieldset.getValue1(), fieldset.getValue2());
                    }
                }
                strategies.put(passportConfiguration.getStrategy(), map);
            }
        }
    }
    passportConfigResponse.setPassportStrategies(strategies);
    String passportConfigResponseJson;
    try {
        passportConfigResponseJson = jsonService.objectToPerttyJson(passportConfigResponse);
    } catch (IOException ex) {
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Failed to prepare configuration");
    }
    return Response.status(Response.Status.OK).entity(passportConfigResponseJson).build();
}
Also used : LdapOxPassportConfiguration(org.xdi.config.oxtrust.LdapOxPassportConfiguration) HashMap(java.util.HashMap) IOException(java.io.IOException) SimpleExtendedCustomProperty(org.xdi.model.SimpleExtendedCustomProperty) PassportConfigResponse(org.gluu.oxtrust.model.passport.PassportConfigResponse) HashMap(java.util.HashMap) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 12 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

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
@ApiOperation(value = "Delete device")
public Response deleteDevice(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteDevice");
        // No need to check id being non-null. fidoDeviceService will give null if null is provided
        GluuCustomFidoDevice device = fidoDeviceService.getGluuCustomFidoDeviceById(null, id);
        if (device != null) {
            fidoDeviceService.removeGluuCustomFidoDevice(device);
            response = Response.noContent().build();
        } else
            response = getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } 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 : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) SCIMException(org.gluu.oxtrust.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) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 13 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi 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 14 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi 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)

Example 15 with ProtectedApi

use of org.gluu.oxtrust.service.filter.ProtectedApi in project oxTrust by GluuFederation.

the class GroupWebService method deleteGroup.

@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
@ApiOperation(value = "Delete group", notes = "Delete group (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteGroup(@PathParam("id") String id) {
    Response response;
    try {
        log.debug("Executing web service method. deleteGroup");
        // group cannot be null (check associated decorator method)
        GluuGroup gr = groupService.getGroupByInum(id);
        scim2GroupService.deleteGroup(gr);
        response = Response.noContent().build();
    } catch (Exception e) {
        log.error("Failure at deleteGroup 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) GluuGroup(org.gluu.oxtrust.model.GluuGroup) SCIMException(org.gluu.oxtrust.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) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)23 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Response (javax.ws.rs.core.Response)21 DefaultValue (javax.ws.rs.DefaultValue)20 HeaderParam (javax.ws.rs.HeaderParam)20 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)20 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)19 ListViewResponse (org.gluu.persist.model.ListViewResponse)19 URI (java.net.URI)17 RefAdjusted (org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted)17 Path (javax.ws.rs.Path)14 Consumes (javax.ws.rs.Consumes)11 GET (javax.ws.rs.GET)7 POST (javax.ws.rs.POST)5 GroupResource (org.gluu.oxtrust.model.scim2.group.GroupResource)4 UserResource (org.gluu.oxtrust.model.scim2.user.UserResource)4 ArrayList (java.util.ArrayList)3 DELETE (javax.ws.rs.DELETE)3