更改执行CDI Interceptors和ContainerRequestFilter的顺序



我正在使用DeltaspikeSecurityInterceptor来授权带有@LoggedIn注释的方法。

同时,我正在ContainerRequestFilter中使用令牌对用户进行身份验证。

@Inject
AuthenticationService authenticationService;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    String authToken = requestContext.getHeaderString(AUTH_TOKEN);
    try {
        authenticationService.authenticateWithToken(authToken);
    } catch (LoginException e) {
        log.info(e.getMessage());
    }
}

我遇到的问题是,容器首先执行SecurityInterceptor,然后执行ContainerRequestFilter并且用户未通过身份验证。

有什么办法可以改变执行顺序吗?

Mybeans.xml:

<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
    <class>org.apache.deltaspike.security.impl.extension.SecurityInterceptor</class>
</interceptors>

来自javaee7文档:

如果应用程序使用多个拦截器,则会按照beans.xml文件中指定的顺序调用拦截器。

但是拦截器和过滤器没有任何执行相关性,过滤器作用于web请求,拦截器是CDI对象,我认为任何运行时执行依赖都是设计错误。

拦截器注释在哪里?哪个班?

相关内容

  • 没有找到相关文章

最新更新