【问题标题】:Participant does not have create access to resource参与者没有资源的创建访问权限
【发布时间】:2017-06-26 22:26:10
【问题描述】:

我正在使用超级账本作曲家制作商业模型,其中我有银行作为参与者,客户作为资产。银行定义如下:

participant Bank identified by bankId {
o String bankId
o String name
o String code
}

客户看起来像这样:

asset Customer identified by aadhaarId {
o String aadhaarId
o String panId
o String firstName
o String lastName
o String contactNo
o String residence
o String accountNumber
o AccountType accountType
o String creationDate  
--> Bank bank
}

我希望参与者(银行)只能更新属于它的那些客户,并且我想创建一个交易来执行此操作。所以我创建了以下事务:

transaction updateCustomer identified by transactionId {
o String transactionId  
--> Customer customer
o Customer newDetails
}

并在.acl文件中定义如下规则:

rule bankCanUpdateItsCutomersViaTransaction {
description: "Allow a participant to update it's own resources"
participant(p): "org.acme.sample.Bank"
operation: UPDATE
resource(r): "org.acme.sample.updateCustomer"
condition: (p.getIdentifier() == r.customer.bank.getIdentifier())
action: ALLOW
}

为了测试这一点,我创建了一个参与者(除了已经提供的管理员)并创建了一个与该参与者链接的客户。我在这背后有一个事务处理器功能,它只是更新客户资产注册表。 但是当我尝试执行 updateCustomer 事务时,我收到一条错误消息,指出参与者没有对资源的 CREATE 访问权限。即使我在 .acl 文件中将操作更改为 CREATE,问题仍然存在。我认为问题出在条件部分,但我无法纠正。

我有一个类似的创建客户的交易如下:

transaction createCustomer identified by transactionId {
o String transactionId
o Customer newCustomer 
}

规则如下:

rule bankCanCreateItsCutomersViaTransaction {    
description: "Allow a participant to create it's own resources"
participant(p): "org.acme.sample.Bank"
operation: CREATE
resource(r): "org.acme.sample.createCustomer"
condition: (p.getIdentifier() == r.newCustomer.bank.getIdentifier())
action: ALLOW
}

这个 createCustomer 事务背后有一个简单的事务处理器函数,它只是将 newCustomer 添加到客户资产注册表中。这工作得很好,但 updateCustomer 事务不工作。 任何帮助将非常感激。谢谢:)

【问题讨论】:

    标签: access-control hyperledger hyperledger-composer


    【解决方案1】:

    使用此规则,您允许银行更新交易。您应该尝试将资源 updateCustomer 替换为 Customer,以便银行可以更新资产:

    resource(r): "org.acme.sample.Customer"
    

    此外,您可能应该添加一条规则,授予银行创建 updateCustomer 交易的权利:

    rule bankCanCreateTransaction {
        description: "..."
        participant: "org.acme.sample.Bank"
        operation: CREATE
        resource: "org.acme.sample.updateCustomer"
        action: ALLOW
    }
    

    【讨论】:

    • 您所说的实际上是有道理的,但是 createCustomer Transaction 工作正常(我刚刚在问题中更新了它)。如果我将条件更改为条件 :(true) 那么它会更新客户。所以我认为问题出在我写条件的方式上。我可以按照我在规则中的方式从 updateCustomer 事务中访问客户吗?
    【解决方案2】:

    我采取了其他方法,而不是在规则中检查客户是否属于该银行,而是在交易处理器功能中检查。所以我的 updateCustomer 规则如下所示:

    rule bankCanInvokeUpdateCustomer {
    description: "Allow a bank to invoke updateCustomer transaction"
    participant: "org.acme.sample.Bank"
    operation: CREATE
    resource: "org.acme.sample.updateCustomer"
    action: ALLOW 
    }
    

    我检查了银行如下:

    var currentParticipant = getCurrentParticipant();
    var currentBank = currentParticipant["$identifier"];
    var actualBank = tx.customer.bank.bankId;
    if( actualBank != currentBank) 
       throw new Error('You can not update someone else\'s customer');
    

    上述代码通过getCurrentParticipant()函数获取当前参与者,然后将银行标识符与客户开户的银行进行匹配,如果不相同,则in抛出错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 2013-08-18
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多