hyperledger - 超级账本作曲家访问控制,允许在交易中创建
问题描述
这是我想要实现的:
我想允许用户(某种参与者)创建资产,但只在事务中进行,而在此事务之外,我想拒绝所有用户创建资产的权限。
我尝试使用规则 .acl 文件中的条件使用函数来解决它:
rule UserCanCreateAssetOnlyInTransaction {
description: "Deny all participants create access to all userWallets if not in transaction"
participant(p): "com.example.User"
operation: CREATE
resource(r): "com.example.UserAsset"
condition:(isInTransactionF())
action: ALLOW
}
然后在事务中创建变量 as var isInTransaction = true;
,并在logic.js
文件中添加:
/**
@returns {boolean} boolean true/false
*/
function isInTransactionF(){
if(isInTransaction){
return true;
}else{
return false;
}
}
它不起作用,当我调用创建访问权限应该工作的唯一事务时,它说用户没有创建访问权限来提交此事务。我想我做错了什么,有什么办法可以解决这个问题吗?
解决方案
在你的功能中实现你想要的 - 你会说:
/**
@returns {boolean} boolean true/false
*/
function isInTransactionF() {
var isInTransaction = true ; // Boolean
if(isInTransaction) {
// if( Boolean(isInTransaction)) { // alternative
return true;
} else{
return false;
}
}
然后,您当前的 ACL 就可以工作了。
我可以调用 console.log 来查看返回的结果
console.log("The return result is " + isInTransactionF() );` // true
限制参与者仅通过某个交易类创建资产 - 规则看起来像(即资产只能通过此类创建 - 假设没有其他资产创建规则,它应该在其他地方被隐式拒绝):
rule CreateAssetThruTxn {
description: "sample""
participant(p): "com.example.User"
operation: CREATE
resource(r): "com.example.UserAsset"
transaction(tx): "com.example.AssetCreate"
condition:(true)
action: ALLOW
}
如果您的 ACL 失败,那么您需要查看哪些其他 ACL 规则可能允许通过其他方式创建此资产,但我提供的规则将是控制它的常用方法(基于您在问题中提供的信息)
推荐阅读
- javascript - 如何使用 Javascript 关闭带有关闭按钮的超级菜单?
- php - php if else 程序,使用第一个“if”语句并忽略其余部分
- symfony - Symfony 4.3 - 无法自动装配引用类“Symfony\Component\Security\Core\Security”的服务参数
- c# - .NET WEB API2 从 JSON 输出中的子类中检索字段
- php - Laravel 5.8 - 未发送验证和欢迎电子邮件
- python - Robotarium 示例代码中的 ModuleNotFoundError
- javascript - 我如何让 kahootbot 多次加入?
- python - Python中是否有相当于R的save.image()函数?
- mysql - 如何从sql中的连接中提取原始表
- xml - 是否可以使用 ansible play book 自动编辑 xml 文件属性?