restlet学习心得—— Guard&Filter

我感觉既然是学习知识没有必要首先一开始就将Spring框架结合进来,这样不利于进一步更深的理解。

 

今天继续看了一下restlet的相关知识,感觉有必要写一下关于Guard&Filter的相关知识。关于Guard具体是什么以及Filter和restlet中有什么区别,可以参考本站ajax的博客:http://ajaxcn.iteye.com

我现在要讲一下如何在application中配置Guard,在createRoot方法中加入一下代码创建一个Guard的对象:

MapVerifier verifier = new MapVerifier();
        verifier.getSecrets().put("JZB", "password".toCharArray());


ChallengeGuard challengeGuard =
                new ChallengeGuard(getContext(), ChallengeScheme.HTTP_BASIC, "JZB");
        challengeGuard.getAuthenticator().setVerifier(verifier);

其中ChallengeGuard是派生于Guard的类

然后把他challengeGuard的next方法中传入正常的路由router

challengeGuard.setNext(router);
return challengeGuard; 

 以后,challengeGuard将会对所有的改router下的resources请求进行验证。

对于Filer来说类似

Filer myFilter = new MyFilter(getContext);
myFilter.setNext(router);
return myFilter;

 然后就是要自定义一个filter

public class MyFilter extends Filter{
     //write you method or overwrite its parent
}
 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值