1
我試圖實現使用的Restlet一個RESTful API,並發現任何東西比的基礎性作用和授權人的方法更很少。我在數據庫中存儲了用戶可以訪問的路由和方法。我現在遇到的問題是如何在授權人中獲取路徑。這是我需要收集的資源嗎?以及我應該如何路由到授權人?我發佈了迄今爲止我所看到的如何在我的授權者獲取路徑或資源。任何信息的讚賞,我看過書籍和許多通用的例子,並沒有找到安靜的東西,我正在尋找。創建的Restlet授權人細粒度授權
我的路由應用:
public class MyRoutingApp extends org.restlet.Application {
@Override
public synchronized Restlet createInboundRoot() {
Context context = getContext();
Router router = new Router(context);
router.attach("/user", Users.class);
router.attach("/post", Posts.class);
router.attach("/comment", Comments.class);
ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
context, ChallengeScheme.HTTP_BASIC, "My test realm");
//create Verifier to ensure that the user is authenicated
MyVerifier verifier = new MySecretVerifier();
//grab user Roles and add them to the request
MyEnroler enroler = new MyEnroler();
authenticator.setVerifier(verifier);
authenticator.setEnroler(enroler);
//Looks up if user can be allowed to resource
MyAuthorizer authorizer = new MyAuthorizer();
authorizer.setNext(router);
authenticator.setNext(authorizer);
return authenticator;
}
}
我的授權人:。
public class MyAuthorizer extends Authorizer {
@Override
protected boolean authorize(Request request, Response response) {
//has the security roles and user from verifier and enroler
ClientInfo info = request.getClientInfo();
//get http method
Method method = request.getMethod();
//need to get the route or resource user is attempting to access
//allow or disallow access based on roles and method
}
}
否則,這種結構適合的授權人應如何設置?我在一些地方使用兩臺路由器,所以我不確定是否有足夠的空間,或者這是否符合我的預期。 – ars265 2013-05-15 11:49:03
你的鏈接結構看起來不錯。如果需要,您可以使用級聯路由器共享一個通用授權者。 – 2013-05-16 15:02:44
由於我的授權人被附加在Authenticator之後,這是否意味着每個請求都會在請求被路由之前通過並授權?我想它的設置方式我認爲它已經共享授權人。 – ars265 2013-05-16 15:11:54