日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apache ZooKeeper - 使用原生的API操作ZK_ACL权限

發布時間:2025/3/21 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache ZooKeeper - 使用原生的API操作ZK_ACL权限 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • Pre
  • Code
    • 創建world模式的節點
    • 使用授權模式創建節點
    • 使用授權模式獲取節點數據


Pre

Apache ZooKeeper - ZK的ACL權限控制( Access Control List )

Apache ZooKeeper - 使用原生的API操作ZK_CRUD


Code

創建world模式的節點

package com.artisan.zk.originalClient;import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Id; import org.apache.zookeeper.server.auth.DigestAuthenticationProvider; import org.junit.Test;import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List;/*** @author 小工匠* @version 1.0* @description: TODO* @date 2020/12/1 11:19* @mark: show me the code , change the world*/@Slf4j public class AclOperationStanAloneModeTest extends StandAloneBaseTest{private static final String NODE_NAME = "/artisan-acl-node";/*** 創建world模式的節點*/@SneakyThrows@Testpublic void testCreateNodeWithACL(){List<ACL>aclList = new ArrayList<>();ACL acl = new ACL();Id id = new Id();id.setId("anyone");id.setScheme("world");// 權限int perms = ZooDefs.Perms.ADMIN | ZooDefs.Perms.READ ;// 綁定acl.setId(id);acl.setPerms(perms);aclList.add(acl);String s = getZooKeeper().create(NODE_NAME, "artisan".getBytes(), aclList, CreateMode.PERSISTENT);log.info("path {} created " ,s);} }

登錄ZK Client查看數據


使用授權模式創建節點

/**** 使用授權模式創建節點*/@SneakyThrows@Testpublic void createWithAclTest2() {String namePWD = "artisan:artisanPWD";// 對連接添加授權信息getZooKeeper().addAuthInfo("digest",namePWD.getBytes());List<ACL> acLList = new ArrayList<ACL>();ACL acl = new ACL();Id id = new Id();id.setId(namePWD);id.setScheme("auth");int perms = ZooDefs.Perms.ADMIN | ZooDefs.Perms.READ |ZooDefs.Perms.WRITE;acl.setId(id);acl.setPerms(perms);acLList.add(acl);String s = getZooKeeper().create("/artisanNode2", "artisan".getBytes(), acLList, CreateMode.PERSISTENT);log.info("create path: {}",s);}

如果要手工查看 可以這兒樣

如果用代碼訪問 如下


使用授權模式獲取節點數據

@Testpublic void getDataWithAcl() throws KeeperException, InterruptedException {String namePWD = "artisan:artisanPWD";// 對連接添加授權信息getZooKeeper().addAuthInfo("digest",namePWD.getBytes());byte[] data = getZooKeeper().getData("/artisanNode2", false, null);log.info("GET_DATA : {}",new String(data));}public static void main(String[] args) throws NoSuchAlgorithmException {String sId = DigestAuthenticationProvider.generateDigest("artisan:artisanPWD");System.out.println(sId);// -Dzookeeper.DigestAuthenticationProvider.superDigest=artisan:d3gLrY2XgzvXZbJObw+wiWIQDko=}

是不是明白了???

總結

以上是生活随笔為你收集整理的Apache ZooKeeper - 使用原生的API操作ZK_ACL权限的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。