首页 > 解决方案 > [Hyperledger-Composer] 不允许尝试在 InvalidRelationship 上获取财产所有者 - ACL 问题

问题描述

在玩 Hyperledger Composer 时出现以下错误。

{
  "$class": "org.property.registration.purchaseProperty",
  "propertyListing":
  "resource:org.property.registration.PropertyListing#PL001"
}

错误:不允许尝试获取 InvalidRelationship 上的财产所有者。由于 ID 为“Asset:org.property.registration.Property”的集合中 ID 为“1003”的对象不存在而创建了 InvalidRelationship;[原因=参与者 'org.property.registration.User#0001' 没有对资源 'org.property.registration.Property#1003' 的“读取”访问权限]

我正在尝试访问作为另一个资产属性列表一部分的资产属性。

asset Property identified by PID {
  o String PID
  o Integer marketPrice
  o DateTime regDate
  o String propertyType
  o String location
  o String status default= "Registered"
  --> User owner
} 
asset PropertyListing identified by PLID {
  o String PLID
  --> Property property
}

我正在尝试访问 PropertyListing 资产并更改其中的属性资产的状态。 (我想从其他用户发布的propertyListing购买房产)

const registry = await getAssetRegistry(tx.propertyListing.property.getFullyQualifiedType());
    await registry.update(tx.propertyListing.property);
 // Remove the property from propertyListing()
    const registry2 =  await getAssetRegistry(tx.propertyListing.getFullyQualifiedType());
    await registry2.remove(tx.propertyListing); 

我希望并且根据错误消息,这似乎是一些权限问题,阻止我购买其他用户的房产帖子。

// User can see all properties listed for sale
rule UserAccessAllSaleProperties {
    description: "Allow Users to access all properties listed for sale"
    participant: "org.property.registration.User"
    operation: ALL
    resource: "org.property.registration.PropertyListing"
    action: ALLOW
}

在这里,我想访问属于PropertyListing的属性。我正在尝试找出我可以使用的 ACL 的不足之处。仍在尝试。

欢迎各位大侠提出建议!!!

标签: hyperledger-fabricblockchainhyperledger-composerhyperledger-chaincodechaincode

解决方案


尝试,

rule UserAccessAllSaleProperties {
    description: "Allow Users to access all properties listed for sale"
    participant: "org.property.registration.**"
    operation: READ
    resource: "org.property.registration.PropertyListing"
    action: ALLOW
}

这将允许所有参与者仅“阅读”更适合您的应用程序的 PropertyListing 资产。如果您介绍任何未来的参与者,这将是有益的。(假设用户被定义为参与者而不是资产)。

我还建议将您的参与者和资产文件分开,因为您的应用程序很大。喜欢

org.property.registration.Property (-> Will only contain Assets)
org.property.registration.Participants (-> Will only contain Participants)

并将它们相互导入。

所以你的规则就像

rule UserAccessAllSaleProperties {
    description: "Allow Users to access all properties listed for sale"
    participant: "org.property.registration.Participants.**"
    operation: READ
    resource: "org.property.registration.PropertyListing"
    action: ALLOW
}

推荐阅读