我使用的認證/授權機制構建其餘服務作爲本教程中描述:http://howtodoinjava.com/2013/06/26/jax-rs-resteasy-basic-authentication-and-authorization-tutorial/什麼是Resteasy 3.X PreProcessInterceptor的正確替換?
基本上它使用PreProcessInterceptor界面掃描的目標方法,其描述了所需的角色訪問註解(從javax.annotation.security封裝)該方法。由於這裏的身份驗證器是一個攔截器,因此它可以取消目標方法調用,並在需要時返回401(未授權)。
這裏的問題是,在當前的RestEasy版本(3.0.1)中不推薦使用org.jboss.resteasy.spi.interception.PreProcessInterceptor接口,並且在嘗試使用標準實現相同的行爲時遇到問題JAX-RS接口。
我使用javax.ws.rs.ext.ReaderInterceptor接口來攔截調用。但不知何故,服務器從來不會調用它:攔截器只是被忽略。
我註冊的攔截器/資源相同的方式,我與前PreProcessInterceptor做,並使用相同的@Provider和@ServerInterceptor註釋:
ServerApplication:
public class ServerApplication extends javax.ws.rs.core.Application {
private final HashSet<Object> singletons = new LinkedHashSet<Object>();
public ServerApplication() {
singletons.add(new SecurityInterceptor());
singletons.add(...); //add each of my rest resources
}
@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
return set;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
SecurityInterceptor:
@Provider
@ServerInterceptor
public class SecurityInterceptor implements javax.ws.rs.ext.ReaderInterceptor {
@Override
public Object aroundReadFrom(ReaderInterceptorContext context){
//code that is never called... so lonely here...
}
}
有關如何解決此問題的任何見解?
謝謝。
更新了另一篇文章中的完整示例:http://howtodoinjava.com/2013/07/25/jax-rs-2-0-resteasy-3-0-2-final-security-tutorial/ – lokesh