我试图实现使用的Restlet一个RESTful API,并发现任何东西比的基础性作用和授权人的方法更很少。 我已经存储在数据库中的用户可以访问这些路线路线和方法。 我遇到现在的问题是如何获得的授权者的路径。 难道我需要采集的资源? 而究竟如何我应该路由到授权? 我已是我迄今为止的期待如何在我的授权人获取的路径或资源。 任何信息表示赞赏,我已经看了,虽然书籍和许多普通的例子,并没有发现什么安静我要找的。
我的路由应用:
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
}
}