目前只介绍digest 方式添加授权,其他后续添加
- zookeeper客户端授权添加
addauth digest username:password #添加sheme访问权限
- 代码增加digest 访问授权
List<ACL> acls = new ArrayList<ACL>(2);
Id id1 = new Id("digest", DigestAuthenticationProvider.generateDigest("admin:admin123"));
ACL acl1 = new ACL(ZooDefs.Perms.ALL, id1);
Id id2 = new Id("digest", DigestAuthenticationProvider.generateDigest("guest:guest123"));
ACL acl2 = new ACL(ZooDefs.Perms.READ, id2);
acls.add(acl1);
acls.add(acl2);
ZooKeeper zk = new ZooKeeper("127.0.0.1:2181", 10000, new Watcher() {@Override
public void process(WatchedEvent watchedEvent) {
System.out.println(watchedEvent.toString());}});
zk.create("/test", new byte[0], acls, CreateMode.PERSISTENT);