更改执行CDI拦截和ContainerRequestFilter

时间:2015-07-03 09:46:05

标签: java security java-ee jax-rs deltaspike

我正在使用Deltaspike SecurityInterceptor 来使用 @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 并且用户未经过身份验证的问题。

有没有办法改变执行顺序?

我的beans.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>

1 个答案:

答案 0 :(得分:0)

来自javaee7文档:

  

If an application uses more than one interceptor, the interceptors are invoked in the order specified in the beans.xml file.

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

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