标签:使用 1.4 client admin otto sed ant san efault
当中,Scheme表示使用何种方式来进行訪问控制。Id代表用户。Permission表示有什么权限。
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.
使用client的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.
使用client的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)
标签:使用 1.4 client admin otto sed ant san efault
原文地址:http://www.cnblogs.com/ljbguanli/p/6835383.html