Search in sources :

Example 11 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class UserWebService method patchUser.

//  PATCH WEBSERVICES
@Path("/patch/{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "patch user", notes = "Update user (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = User.class)
public Response patchUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "User", required = true) ScimPatchUser user, @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 {
        User updatedUser = scim2UserService.patchUser(id, user);
        // Serialize to JSON
        String json = serializeToJson(updatedUser, attributesArray);
        URI location = new URI(updatedUser.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Failed to update user", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to update user", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 12 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class UserWebService method updateUser.

@Path("{id}")
@PUT
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@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 = "Update user", notes = "Update user (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = User.class)
public Response updateUser(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id, @ApiParam(value = "User", required = true) User user, @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 {
        User updatedUser = scim2UserService.updateUser(id, user);
        // Serialize to JSON
        String json = serializeToJson(updatedUser, attributesArray);
        URI location = new URI(updatedUser.getMeta().getLocation());
        return Response.ok(json).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Failed to update user", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (DuplicateEntryException ex) {
        log.error("DuplicateEntryException", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage());
    } catch (Exception ex) {
        log.error("Failed to update user", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) 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) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 13 with HeaderParam

use of javax.ws.rs.HeaderParam in project oxTrust by GluuFederation.

the class FidoDeviceWebService method deleteDevice.

@Path("{id}")
@DELETE
@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 = "Delete device", notes = "Delete device (https://tools.ietf.org/html/rfc7644#section-3.6)")
public Response deleteDevice(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @PathParam("id") String id) 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 {
        scim2FidoDeviceService.deleteFidoDevice(id);
        return Response.noContent().build();
    } catch (EntryPersistenceException epe) {
        log.error("Failed to delete device", epe);
        epe.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found");
    } catch (Exception e) {
        log.error("Failed to delete device", 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) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) 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) DELETE(javax.ws.rs.DELETE) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 14 with HeaderParam

use of javax.ws.rs.HeaderParam in project cdap by caskdata.

the class RouterAuditLookUp method createMatcher.

private int createMatcher() {
    List<Class<?>> handlerClasses;
    try {
        handlerClasses = getAllHandlerClasses();
    } catch (IOException e) {
        LOG.error("Failed to get all handler classes for audit logging: {}", e.getCause());
        return -1;
    }
    int count = 0;
    for (Class<?> handlerClass : handlerClasses) {
        Path classPath = handlerClass.getAnnotation(Path.class);
        String classPathStr = classPath == null ? "" : classPath.value();
        for (Method method : handlerClass.getMethods()) {
            Path methodPath = method.getAnnotation(Path.class);
            AuditPolicy auditPolicy = method.getAnnotation(AuditPolicy.class);
            HttpMethod httpMethod = getHttpMethod(method);
            if (methodPath == null || auditPolicy == null || httpMethod == null) {
                continue;
            }
            String methodPathStr = methodPath.value();
            String completePath = classPathStr.endsWith("/") || methodPathStr.startsWith("/") ? classPathStr + methodPathStr : classPathStr + "/" + methodPathStr;
            List<AuditDetail> auditContents = Arrays.asList(auditPolicy.value());
            List<String> headerNames = new ArrayList<>();
            if (auditContents.contains(AuditDetail.HEADERS)) {
                Annotation[][] annotations = method.getParameterAnnotations();
                for (Annotation[] annotationArr : annotations) {
                    if (annotationArr.length > 0) {
                        for (Annotation annotation : annotationArr) {
                            if (annotation instanceof HeaderParam) {
                                headerNames.add(((HeaderParam) annotation).value());
                            }
                        }
                    }
                }
            }
            AuditLogContent auditLogContent = new AuditLogContent(httpMethod, auditContents.contains(AuditDetail.REQUEST_BODY), auditContents.contains(AuditDetail.RESPONSE_BODY), headerNames);
            LOG.trace("Audit log lookup: bootstrapped with path: {}", completePath);
            patternMatcher.add(completePath, auditLogContent);
            count++;
        }
    }
    LOG.debug("Audit log lookup: bootstrapped with {} paths", count);
    return count;
}
Also used : Path(javax.ws.rs.Path) ClassPath(co.cask.cdap.common.internal.guava.ClassPath) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) AuditLogContent(co.cask.cdap.common.logging.AuditLogContent) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) AuditDetail(co.cask.cdap.common.security.AuditDetail) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod)

Example 15 with HeaderParam

use of javax.ws.rs.HeaderParam in project swagger-core by swagger-api.

the class DefaultParameterExtension method extractParameters.

@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ArrayList<Parameter>();
    }
    List<Parameter> parameters = new ArrayList<Parameter>();
    Parameter parameter = null;
    for (Annotation annotation : annotations) {
        if (annotation instanceof QueryParam) {
            QueryParam param = (QueryParam) annotation;
            QueryParameter qp = new QueryParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                qp.setProperty(schema);
            }
            parameter = qp;
        } else if (annotation instanceof PathParam) {
            PathParam param = (PathParam) annotation;
            PathParameter pp = new PathParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                pp.setProperty(schema);
            }
            parameter = pp;
        } else if (annotation instanceof HeaderParam) {
            HeaderParam param = (HeaderParam) annotation;
            HeaderParameter hp = new HeaderParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                hp.setProperty(schema);
            }
            parameter = hp;
        } else if (annotation instanceof CookieParam) {
            CookieParam param = (CookieParam) annotation;
            CookieParameter cp = new CookieParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                cp.setProperty(schema);
            }
            parameter = cp;
        } else if (annotation instanceof FormParam) {
            FormParam param = (FormParam) annotation;
            FormParameter fp = new FormParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                fp.setProperty(schema);
            }
            parameter = fp;
        } else {
            handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
        }
    }
    if (parameter != null) {
        parameters.add(parameter);
    }
    return parameters;
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) PathParameter(io.swagger.models.parameters.PathParameter) FormParameter(io.swagger.models.parameters.FormParameter) Annotation(java.lang.annotation.Annotation) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) PathParam(javax.ws.rs.PathParam) HeaderParameter(io.swagger.models.parameters.HeaderParameter) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) FormParam(javax.ws.rs.FormParam)

Aggregations

HeaderParam (javax.ws.rs.HeaderParam)34 DefaultValue (javax.ws.rs.DefaultValue)32 Produces (javax.ws.rs.Produces)30 URI (java.net.URI)25 Response (javax.ws.rs.core.Response)23 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)21 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)21 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)21 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)21 Path (javax.ws.rs.Path)20 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)19 GET (javax.ws.rs.GET)16 ArrayList (java.util.ArrayList)11 Consumes (javax.ws.rs.Consumes)9 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)9 POST (javax.ws.rs.POST)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)5 Meta (org.gluu.oxtrust.model.scim2.Meta)5 ScimPatchUser (org.gluu.oxtrust.model.scim2.ScimPatchUser)5 User (org.gluu.oxtrust.model.scim2.User)5