- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的身份验证过滤器:
@Secured
@Provider
@Priority(Priorities.AUTHENTICATION)
public class SecuredFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
String token = authorizationHeader.substring("Bearer".length()).trim();
// [...]
}
}
void abortWith(Response response)
Abort the filter chain with a response. This method breaks the filter chain processing and returns the provided response back to the client. The provided response goes through the chain of applicable response filters. Parameters: response - response to be sent back to the client.
最佳答案
我错过了“返回”关键字:
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
return;
}
This method breaks the filter chain processing and returns the provided response back to the client
关于rest - ContainerRequestContext abortWith() 不会中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45457652/
在我的 Jersey 应用程序中,我希望将一个 ContainerRequestContext 实例注入(inject)到各种对象中。如果对象是在请求上下文之外创建的,我希望注入(inject) nu
如何从 ContainerRequestContext 对象获取引用 URL。 请找到下面的代码片段, public void filter(ContainerRequestContext reque
这是我的身份验证过滤器: @Secured @Provider @Priority(Priorities.AUTHENTICATION) public class SecuredFilter impl
我使用 Jersey 2 来公开功能(restful API)。 我想在过滤器级别访问表单参数的地方,我们从 `ContainerRequestContext 访问 pathparam、querypa
我想为我的 REST API 端点应用授权过滤器,过滤器需要路径参数来进行过滤。这是我的端点和代码: 端点: curl --url 'localhost:80/reports/resources/or
我已经看过很多帖子,但似乎没有什么能像我喜欢的那样工作。 我想将一个对象从过滤器注入(inject)到 ContainerRequestContext 属性中,并稍后在其他类中检索它。 这是我的过滤器
我是 Spring 和 Jersey 新人。我正在尝试构建一个过滤器来检查请求是否具有正确的参数。这是我要检查的 json 部分: "request":{ "application":
我的请求中有以下 HTTP header ,我想从中提取 JSESSIONID: Accept=application/json Accept-Encoding=gzip deflate,Accept
我尝试使用 Mockito 模拟 ContainerRequestContext,但出现以下错误: java.lang.ClassFormatError: Absent Code attribute
我有一个 RESTful 端点,我通过自定义 ContainerRequestFilter 通过简单的授权检查来保护它。过滤器检查 HTTP session 中包含的所有信息是否正确,如果不正确,则执
我有一个过滤器,POST REST api 通过该过滤器,我想在过滤器中提取我的有效负载的以下部分。 { "foo": "bar", "hello": "world" } 过滤
我的代码是这样的: public void filter(ContainerRequestContext request) throws IOException { // can I get
我使用 IOUtils.toString(containerRequestContext.getEntityStream(),"UTF-8");获取实体流并使用 IOUtils 将其转换为字符串。但是
我是一名优秀的程序员,十分优秀!