Zookeeper权限控制

该博客演示了如何使用Zookeeper进行权限控制,通过ZkClient实现数据的创建、读取、更新和删除,并展示了不同授权信息(正确、错误、无)对操作的影响。主要涉及授权类型为'digest'。
摘要由CSDN通过智能技术生成

 

  1. package org.I0Itec.zkclient; 
  2.  
  3. import java.util.ArrayList; 
  4. import java.util.List; 
  5.  
  6. import org.apache.zookeeper.WatchedEvent; 
  7. import org.apache.zookeeper.Watcher; 
  8. import org.apache.zookeeper.ZooDefs.Ids; 
  9. import org.apache.zookeeper.data.ACL; 
  10.  
  11. /** 
  12. * Description: ZooKeepre ACL权限控制 测试 
  13. * @author nileader / nileader@gmail.com 
  14. * @Date Feb 2, 2012 
  15. */ 
  16. public class DemoAuth implements Watcher { 
  17.  
  18. final static String SERVER_LIST = “127.0.0.1:4711″; 
  19.  
  20. final static String PATH = “/yinshi_auth_test”; 
  21. final static String PATH_DEL = “/yinshi_auth_test/will_be_del”; 
  22.  
  23. final static String authentication_type = “digest”; 
  24.  
  25. final static String correctAuthentication = “taokeeper:true”; 
  26. final static String badAuthentication = “taokeeper:errorCode”; 
  27.  
  28. static ZkClient zkClient = null
  29.  
  30. public static void main( String[] args ) throws Exception { 
  31.  
  32. List< ACL > acls = new ArrayList< ACL >( 1 ); 
  33. for ( ACL ids_acl : Ids.CREATOR_ALL_ACL ) { 
  34. acls.add( ids_acl ); 
  35.  
  36. try { 
  37. zkClient = new ZkClient( SERVER_LIST, 50000); 
  38. zkClient.addAuthInfo( authentication_type, correctAuthentication.getBytes() ); 
  39. catch ( Exception e ) { 
  40. // TODO Auto-generated catch block 
  41. e.printStackTrace(); 
  42.  
  43. try { 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值