之前稍微了解过Client Identity Chaincode Library,这几天正好开始实际应用。

虽然了解过,还是发现了不少之前理解的不足,也踩了不少坑。

先列出官方介绍: https://github.com/hyperledger/fabric/blob/release-1.1/core/chaincode/lib/cid/README.md

1,首先要给注册的user添加attrs,但是在ca 数据库中看不到,chaincode 层也查不到

查看CA的log,并没有报错,user也成功enroll,

chaincode层查找fabric 默认的attrs,则可以查到。然后意识到,需要在ca-server-config.yaml中添加需要的attrs。

2,在chaincode中 import http://github.com/hyperledger/fabric/core/chaincode/lib/cid,compile的时候总是说找不到 github.com/hyperledger/fabric/core/chaincode/lib/cid

错误消息说的很明确,但是由于对go语言及扩展知识理解不做,踩了不少坑。

shim包可以引入成功,但是并不知道shim包在哪里,也不知道应该怎么引入新包。于是系统中搜索shim,但是找不到结果。

上网查找,很确认这里是正解:https://stackoverflow.com/questions/49560104/cannot-find-package-cid-in-goroot-or-gopath

但是还是不是很明白,最后参考abac的例子和govendor的文档,才搞定

下面是一些关键代码:

ca-config.yaml

registry:
# Maximum number of times a password/secret can be reused for enrollment
# (default: -1, which means there is no limit)
maxenrollments: -1 # Contains identity information which is used when LDAP is disabled
identities:
- name: admin
pass: adminpw
type: client
affiliation: ""
attrs:
hf.Registrar.Roles: "peer,orderer,client,user"
hf.Registrar.DelegateRoles: "peer,orderer,client,user"
hf.Revoker: true
hf.IntermediateCA: true
hf.GenCRL: true
hf.Registrar.Attributes: "*"
hf.AffiliationMgr: true
permissions: "*"

  

node js

			let secret = await caClient.register({
enrollmentID: username,
affiliation: userOrg.toLowerCase() + '.department1',
attrs:[{name:"hf.Registrar.Attributes",value:"query",ecert:true},
{name:"permissions",value:"query",ecert:true}]
//attrs:reg_attr
}, adminUserObj);

  

chaincode

// Get the client ID object
id, err := cid.New(stub) fmt.Println("client ID object:")
fmt.Println(id)
if err != nil {
return shim.Error(err.Error())
}
mspid, err := id.GetMSPID() fmt.Println("mspid:")
fmt.Println(mspid)
if err != nil {
return shim.Error(err.Error())
} cert, err := cid.GetX509Certificate(stub)
fmt.Println("cert:")
fmt.Printf("%+v\n", cert)
fmt.Println("cert.Extensions :")
fmt.Printf("%+v\n", cert.Extensions)
fmt.Println("cert.Subject.CommonName:")
fmt.Println(cert.Subject.CommonName) val, ok, err := cid.GetAttributeValue(stub, "hf.Registrar.Attributes")
if err != nil {
return shim.Error(err.Error())
}
if !ok {
return shim.Error("The client identity does not possess the attribute:hf.Registrar.Attributes")
}
fmt.Println("hf.Registrar.Attributes:")
fmt.Println(val) val, ok, err = cid.GetAttributeValue(stub, "permissions")
if err != nil {
return shim.Error(err.Error())
}
if !ok {
return shim.Error("The client identity does not possess the attribute:permissions")
}
fmt.Println("permissions:")
fmt.Println(val)

  

Fabric的权限管理:Attribute-Based Access Control的更多相关文章

  1. [认证授权] 6.Permission Based Access Control

    在前面5篇博客中介绍了OAuth2和OIDC(OpenId Connect),其作用是授权和认证.那么当我们得到OAuth2的Access Token或者OIDC的Id Token之后,我们的资源服务 ...

  2. Azure ARM (16) 基于角色的访问控制 (Role Based Access Control, RBAC) - 使用默认的Role

    <Windows Azure Platform 系列文章目录> 今天上午刚刚和客户沟通过,趁热打铁写一篇Blog. 熟悉Microsoft Azure平台的读者都知道,在老的Classic ...

  3. Azure RBAC(Roles Based Access Control)正式上线了

    期盼已久的Azure RBAC(Roles Based Access Control)正式上线了. 在非常多情况下.客户须要对各种类型的用户加以区分,以便做出适当的授权决定.基于角色的訪问控制 (RB ...

  4. Risk Adaptive Information Flow Based Access Control

    Systems and methods are provided to manage risk associated with access to information within a given ...

  5. Custom Roles Based Access Control (RBAC) in ASP.NET MVC Applications - Part 1 (Framework Introduction)

    https://www.codeproject.com/Articles/875547/Custom-Roles-Based-Access-Control-RBAC-in-ASP-NET Introd ...

  6. Linux VFS Extended Attribute And Access Control Table

    catalog . 简介 . 扩展属性 . 访问控制表 . 小结 0. 简介 许多文件系统都提供了一些特性,扩展了VFS层提供的标准功能,虚拟文件系统不可能为所有特性都提供具体的数据结构.超出标准的U ...

  7. 基于角色的权限控制系统(role-based access control)

    role-based access control(rbac),指对于不同角色的用户,拥有不同的权限 .用户对应一个角色,一个角色拥有若干权限,形成用户-角色-权限的关系,如下图所示.当一个用户进行访 ...

  8. 概念 : 用户>角色>权限 的管理(Role-Based Access Control)

    RBAC 用户管理规范 概念:每个user有多个accounts,每个account 有一个account binding,有多个roles和多个tasks 举个例子:某个用户现在manager,这是 ...

  9. Azure ARM (17) 基于角色的访问控制 (Role Based Access Control, RBAC) - 自定义Role

    <Windows Azure Platform 系列文章目录> 在上面一篇博客中,笔者介绍了如何在RBAC里面,设置默认的Role. 这里笔者将介绍如何使用自定的Role. 主要内容有: ...

随机推荐

  1. 将string转为同名类名,方法名。(c#反射)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stri ...

  2. 图的遍历——DFS(矩形空间)

    首先,这里的图不是指的我们一般所说的图结构,而是大小为M*N的矩形区域(也可以看成是一个矩阵).而关于矩形区域的遍历问题经常出现,如“寻找矩阵中的路径”.“找到矩形区域的某个特殊点”等等之类的题目,在 ...

  3. centos下vi的用法大全

    vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的任何版本,vi编辑器是完全相 ...

  4. centos7-软件安装-mysql5.7

    mysql5.7新增特点: 最新版本的mysql5.7相比较于mysql5.6,新添加了一个特点:允许日期类型字段添加数值精确到毫秒位数,比如`create_date` datetime(3) DEF ...

  5. PP.io的三个阶段,“强中心”——“弱中心”——“去中心”

    什么是PP.io? PP.io是我和Bill发起的存储项目,目的在于为开发者提供一个去中心化的存储和分发平台,能做到更便宜,更高速,更隐私. 当然做去中心化存储的项目也有好几个,FileCoin,Si ...

  6. 代码管理工具libgit2sharp与sharpsvn

    在使用libgit2sharp 开发时出现: LibGit2Sharp.LibGit2SharpException: too many redirects or authentication repl ...

  7. 安卓打开远程调试(免root)

    首先用数据线连接adb,在pc端执行: adb tcpip 5555 然后就能拔掉数据线了. pc执行这个: adb connect 172.19.208.2 就能连接上

  8. svn Mac

    将已有项目放到svn服务端 svn import 已有项目地址 服务端地址 -m '注释必须填写' 例子 svn import /Applications/Emma/workspace/tansun/ ...

  9. 学习笔记:ECharts

    (Highcharts 167K:  ECharts 354K: jqChart 240K),如果用于网络,Highchart最小 ECharts (Enterprise Charts 商业产品图表库 ...

  10. 001之IP基础对话框

    在TCP/IP协议中,建立连接的两个进程(客户端和服务器)各自用一个socket(IP地址+TCP/UDP端口号)标识.在MFC中流式套接字(SOCK_STREAM)和数据报套接字(SOCK_DGRA ...