- package org.I0Itec.zkclient;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.zookeeper.WatchedEvent;
- import org.apache.zookeeper.Watcher;
- import org.apache.zookeeper.ZooDefs.Ids;
- import org.apache.zookeeper.data.ACL;
- /**
- * Description: ZooKeepre ACL权限控制 测试
- * @author nileader / nileader@gmail.com
- * @Date Feb 2, 2012
- */
- public class DemoAuth implements Watcher {
- final static String SERVER_LIST = “127.0.0.1:4711″;
- final static String PATH = “/yinshi_auth_test”;
- final static String PATH_DEL = “/yinshi_auth_test/will_be_del”;
- final static String authentication_type = “digest”;
- final static String correctAuthentication = “taokeeper:true”;
- final static String badAuthentication = “taokeeper:errorCode”;
- static ZkClient zkClient = null;
- public static void main( String[] args ) throws Exception {
- List< ACL > acls = new ArrayList< ACL >( 1 );
- for ( ACL ids_acl : Ids.CREATOR_ALL_ACL ) {
- acls.add( ids_acl );
- }
- try {
- zkClient = new ZkClient( SERVER_LIST, 50000);
- zkClient.addAuthInfo( authentication_type, correctAuthentication.getBytes() );
- } catch ( Exception e ) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {