ZooKeeeper has the following built in schemes:
ZooKeeper有如下几种内置的Schemes
world has a single id, anyone, that represents anyone.
代表所有人都能够访问auth doesn‘t use any id, represents any authenticated user.
不需要Id,通过auth的用户都能够访问digest uses a username:password string to generate MD5 hash which is then used as an ACL ID identity. Authentication is done by sending the username:password in clear text. When used in the ACL the expression will be the username:base64 encoded SHA1 password digest.
通过用户名密码方式的auth验证,Id的格式为username:base64 encoded SHA1 password digesthost uses the client host name as an ACL ID identity. The ACL expression is a hostname suffix. For example, the ACL expression host:corp.com matches the ids host:host1.corp.com and host:host2.corp.com, but nothost:host1.store.com.
使用客户端的host name作为Acl的Idip uses the client host IP as an ACL ID identity. The ACL expression is of the form addr/bits where the most significant bits of addr are matched against the most significant bits of the client host IP.
使用客户端的Ip作为Acl的zookeeper目前支持下面一些权限:
Create a node with given path, data, acls and mode.
Arguments
String
- Path of the node.Buffer
- The data buffer, optional, defaults to null.Array
- An array of ACL objects,
optional, defaults to ACL.OPEN_ACL_UNSAFE
CreateMode
- The creation mode, optional, defaults to CreateMode.PERSISTENT
Function
- The callback function.new zookeeper.Id(‘ip‘, ‘127.0.0.1‘);
完整代码如下:
var zookeeper = require(‘node-zookeeper-client‘);
var id = new zookeeper.Id(‘ip‘, ‘192.168.1.123‘);
var client = zookeeper.createClient(‘192.168.1.100:2181‘);
var acl = new zookeeper.ACL(zookeeper.Permission.ADMIN, id);
client.create(‘/test‘, new Buffer(‘test‘), [acl], zookeeper.CreateMode.PERSISTENT, function (err, path) {
//handler callback
});
如何有客户端想访问/test节点,则需要通过上面的访问控制,具体代码如下:
var zookeeper = require(‘node-zookeeper-client‘);
var client = zookeeper.createClient(‘192.168.1.100:2181‘);
zookeeper.addAuthInfo(‘ip‘, new Buffer(‘192.168.1.123‘));
client.getData(‘/test‘, null, function() {
//handler callback
});
Zookeeper ACL(使用node-zookeeper-client),布布扣,bubuko.com
Zookeeper ACL(使用node-zookeeper-client)
原文地址:http://blog.csdn.net/sweetvvck/article/details/38262475