2013-05-11 67 views
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 
    } 
} 

回答

2

目标资源的URI是通过请求#getResouceRef可用()getRemainingPart()。

+0

否则,这种结构适合的授权人应如何设置?我在一些地方使用两台路由器,所以我不确定是否有足够的空间,或者这是否符合我的预期。 – ars265 2013-05-15 11:49:03

+0

你的链接结构看起来不错。如果需要,您可以使用级联路由器共享一个通用授权者。 – 2013-05-16 15:02:44

+0

由于我的授权人被附加在Authenticator之后,这是否意味着每个请求都会在请求被路由之前通过并授权?我想它的设置方式我认为它已经共享授权人。 – ars265 2013-05-16 15:11:54