2015-09-20 42 views
0

我正在應用引擎上使用RESTlet和JAX-RS製作後端API。我想在每個請求之前調用一個方法來檢查用戶是否已通過身份驗證(必須通過HTTP對外部API進行查詢),然後繼續或停止依賴。RESTlet + JAX-RS身份驗證中間件

我該怎麼做?

感謝, 丹尼爾

回答

1

可謂是非常簡單的。

創建身份驗證器的一個子類(http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Authenticator.html?is-external=true)並使用自定義身份驗證和任何其他需要的函數實現authenticate()。

例如,

public class MyAuthenticator extends Authenticator { 

public MyAuthenticator(Context context) { 
    super(context); 
} 

@Override 
protected boolean authenticate(Request request, Response response) { 
    // do your custom authentication here and return true or false depending on result 
}