Java 有没有为请求定制FilterChain的方法(JAX-RS)
我在Java后端工作,运行wildfly服务器。对于每个资源,应该像对用户进行身份验证一样执行筛选器。一些过滤器应该被跳过,我在问自己是否有一种编程方式来定义自己的过滤器链 到目前为止,我在第一个过滤器中设置了一个上下文属性(executeAuthorizationFilter),在下一个过滤器中设置了一个检查Java 有没有为请求定制FilterChain的方法(JAX-RS),java,rest,jax-rs,Java,Rest,Jax Rs,我在Java后端工作,运行wildfly服务器。对于每个资源,应该像对用户进行身份验证一样执行筛选器。一些过滤器应该被跳过,我在问自己是否有一种编程方式来定义自己的过滤器链 到目前为止,我在第一个过滤器中设置了一个上下文属性(executeAuthorizationFilter),在下一个过滤器中设置了一个检查 @Provider @Priority(1100) public class AuthenticationFilter implements ContainerR
@Provider
@Priority(1100)
public class AuthenticationFilter implements ContainerRequestFilter {
@Context
private ResourceInfo resourceInfo;
@Override
public void filter(ContainerRequestContext context) throws IOException {
// Next filter should be skipped in case - next filter has check on this prop
if(resourceInfo.getResourceMethod().getAnnotation(PermitAll.class) != null) {
context.setProperty("executeAuthorizationFilter", false);
} else {
//check if token is valid
String jwtToken = context.getHeaderString(JWTTokenHelper.tokenName);
boolean isTokenValid = false;
try {
// TODO check for validation and exp
isTokenValid = JWTTokenHelper.validateUserToken(jwtToken);
} catch (NullPointerException exception) {
context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
if(!isTokenValid) {
context.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
}
}
}
这不是美,根据下面的过滤器,它可能是一团乱。你知道如何实现动态过滤链吗