|
| 1 | +# Business Partner Group Policy |
| 2 | + |
| 3 | +## 1. Description |
| 4 | +This tutorial demonstrates the process of creating a business partner group and creating a policy that grants access to assets for this business partner group. |
| 5 | +For this tutorial, we assume `Alice` as a provider participant and `Bob` as consumer participant. |
| 6 | + |
| 7 | +## 2. Create Business Partner Group |
| 8 | +`Alice` adds his partner `Bob` (with BPN: `BPNL000000000002`) to a business partner group named `gold-partners`. |
| 9 | +> Note: If you are running MXD, you can skip this step as it has already been done. |
| 10 | +```shell |
| 11 | +curl --location 'http://localhost/alice/management/business-partner-groups' \ |
| 12 | +--header 'Content-Type: application/json' \ |
| 13 | +--header 'X-Api-Key: password' \ |
| 14 | +--data-raw '{ |
| 15 | + "@context": { |
| 16 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/" |
| 17 | + }, |
| 18 | + "@id": "BPNL000000000002", |
| 19 | + "tx:groups": [ |
| 20 | + "gold-partners" |
| 21 | + ] |
| 22 | +}' |
| 23 | +``` |
| 24 | +`Alice` can also update business partner group for `Bob`. |
| 25 | +```shell |
| 26 | +curl --location --request PUT 'http://localhost/alice/management/business-partner-groups' \ |
| 27 | +--header 'Content-Type: application/json' \ |
| 28 | +--header 'X-Api-Key: password' \ |
| 29 | +--data-raw '{ |
| 30 | + "@context": { |
| 31 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/" |
| 32 | + }, |
| 33 | + "@id": "BPNL000000000002", |
| 34 | + "tx:groups": [ |
| 35 | + "gold-partners", |
| 36 | + "platinum-partners" |
| 37 | + ] |
| 38 | +}' |
| 39 | +``` |
| 40 | + |
| 41 | +`Alice` can check which business partner groups, `Bob` is currently associated. |
| 42 | +```shell |
| 43 | +curl --location 'http://localhost/alice/management/business-partner-groups/BPNL000000000002' \ |
| 44 | +--header 'X-Api-Key: password' |
| 45 | +``` |
| 46 | +It should return a response similar to this. |
| 47 | +```json |
| 48 | +{ |
| 49 | + "@id": "BPNL000000000002", |
| 50 | + "tx:groups": [ |
| 51 | + "gold-partners", |
| 52 | + "platinum-partners" |
| 53 | + ], |
| 54 | + "@context": { |
| 55 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 56 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 57 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 58 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## 3. Create An Asset |
| 64 | +```shell |
| 65 | +curl --location 'http://localhost/alice/management/v3/assets' \ |
| 66 | +--header 'Content-Type: application/json' \ |
| 67 | +--header 'X-Api-Key: password' \ |
| 68 | +--data-raw '{ |
| 69 | + "@context": { |
| 70 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 71 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 72 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 73 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 74 | + }, |
| 75 | + "@id": "30", |
| 76 | + "properties": { |
| 77 | + "description": "Product EDC Demo Asset" |
| 78 | + }, |
| 79 | + "dataAddress": { |
| 80 | + "@type": "DataAddress", |
| 81 | + "type": "HttpData", |
| 82 | + "baseUrl": "https://jsonplaceholder.typicode.com/todos/30" |
| 83 | + } |
| 84 | +}' |
| 85 | +``` |
| 86 | + |
| 87 | +## 4. Create Policy |
| 88 | + |
| 89 | +### 4.1 Create Access Policy |
| 90 | +```shell |
| 91 | +curl --location 'http://localhost/alice/management/v2/policydefinitions' \ |
| 92 | +--header 'Content-Type: application/json' \ |
| 93 | +--header 'X-Api-Key: password' \ |
| 94 | +--data-raw '{ |
| 95 | + "@context": { |
| 96 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 97 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 98 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 99 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 100 | + }, |
| 101 | + "@type": "PolicyDefinitionRequestDto", |
| 102 | + "@id": "301", |
| 103 | + "policy": { |
| 104 | + "@type": "odrl:Set", |
| 105 | + "odrl:permission": [ |
| 106 | + { |
| 107 | + "odrl:action": "use", |
| 108 | + "odrl:constraint": { |
| 109 | + "@type": "LogicalConstraint", |
| 110 | + "odrl:or": [ |
| 111 | + { |
| 112 | + "@type": "Constraint", |
| 113 | + "odrl:leftOperand": "BpnCredential", |
| 114 | + "odrl:operator": { |
| 115 | + "@id": "odrl:eq" |
| 116 | + }, |
| 117 | + "odrl:rightOperand": "active" |
| 118 | + } |
| 119 | + ] |
| 120 | + } |
| 121 | + } |
| 122 | + ] |
| 123 | + } |
| 124 | +}' |
| 125 | +``` |
| 126 | +### 4.2 Create Business Partner Group Policy |
| 127 | +`Alice` creates a policy for `gold-partners` business partner group. This policy applies to all business partner in that group. |
| 128 | +```shell |
| 129 | +curl --location 'http://localhost/alice/management/v2/policydefinitions' \ |
| 130 | +--header 'Content-Type: application/json' \ |
| 131 | +--header 'X-Api-Key: password' \ |
| 132 | +--data-raw '{ |
| 133 | + "@context": { |
| 134 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 135 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 136 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 137 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 138 | + }, |
| 139 | + "@type": "PolicyDefinitionRequestDto", |
| 140 | + "@id": "302", |
| 141 | + "policy": { |
| 142 | + "@type": "odrl:Set", |
| 143 | + "odrl:permission": [ |
| 144 | + { |
| 145 | + "odrl:action": "use", |
| 146 | + "odrl:constraint": { |
| 147 | + "@type": "LogicalConstraint", |
| 148 | + "odrl:or": [ |
| 149 | + { |
| 150 | + "@type": "Constraint", |
| 151 | + "odrl:leftOperand": "https://w3id.org/tractusx/v0.0.1/ns/BusinessPartnerGroup", |
| 152 | + "odrl:operator": { |
| 153 | + "@id": "odrl:eq" |
| 154 | + }, |
| 155 | + "odrl:rightOperand": "gold-partners" |
| 156 | + } |
| 157 | + ] |
| 158 | + } |
| 159 | + } |
| 160 | + ] |
| 161 | + } |
| 162 | +}' |
| 163 | +``` |
| 164 | + |
| 165 | +## 5. Create Contract Definition |
| 166 | +```shell |
| 167 | +curl --location 'http://localhost/alice/management/v2/contractdefinitions' \ |
| 168 | +--header 'Content-Type: application/json' \ |
| 169 | +--header 'X-Api-Key: password' \ |
| 170 | +--data-raw '{ |
| 171 | + "@context": { |
| 172 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 173 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 174 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 175 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 176 | + }, |
| 177 | + "@id": "30", |
| 178 | + "@type": "ContractDefinition", |
| 179 | + "accessPolicyId": "301", |
| 180 | + "contractPolicyId": "302", |
| 181 | + "assetsSelector": { |
| 182 | + "@type": "CriterionDto", |
| 183 | + "operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", |
| 184 | + "operator": "=", |
| 185 | + "operandRight": "30" |
| 186 | + } |
| 187 | +}' |
| 188 | +``` |
| 189 | + |
| 190 | +## 6. Query Catalog |
| 191 | +Now let's verify whether Bob is able to access the assets or not via querying Alice's catalog. |
| 192 | +```shell |
| 193 | +curl --location 'http://localhost/bob/management/v2/catalog/request' \ |
| 194 | +--header 'Content-Type: application/json' \ |
| 195 | +--header 'X-Api-Key: password' \ |
| 196 | +--data-raw '{ |
| 197 | + "@context": { |
| 198 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", |
| 199 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", |
| 200 | + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", |
| 201 | + "odrl": "http://www.w3.org/ns/odrl/2/" |
| 202 | + }, |
| 203 | + "@type": "CatalogRequest", |
| 204 | + "counterPartyAddress": "http://alice-controlplane:8084/api/v1/dsp", |
| 205 | + "protocol": "dataspace-protocol-http", |
| 206 | + "querySpec": { |
| 207 | + "offset": 0, |
| 208 | + "limit": 50 |
| 209 | + } |
| 210 | +}' |
| 211 | +``` |
| 212 | + |
| 213 | +You should be able to find this asset (`id: 30`) in the list of catalog returned by `Alice`. |
| 214 | +```json |
| 215 | +{ |
| 216 | + "@id": "f6dcc216-9948-4807-8e56-6f867f9226f2", |
| 217 | + "@type": "dcat:Catalog", |
| 218 | + "dcat:dataset": [ |
| 219 | + { |
| 220 | + "@id": "30", |
| 221 | + "@type": "dcat:Dataset", |
| 222 | + "odrl:hasPolicy": { |
| 223 | + "@id": "MzA=:MzA=:OWNhYzMwM2QtOTYyNi00NzY3LTgxZTUtYWVkNDM4NzAwYmNj", |
| 224 | + "@type": "odrl:Set", |
| 225 | + "odrl:permission": { |
| 226 | + "odrl:target": "30", |
| 227 | + "odrl:action": { |
| 228 | + "odrl:type": "USE" |
| 229 | + }, |
| 230 | + "odrl:constraint": { |
| 231 | + "odrl:or": { |
| 232 | + "odrl:leftOperand": "https://w3id.org/tractusx/v0.0.1/ns/BusinessPartnerGroup", |
| 233 | + "odrl:operator": { |
| 234 | + "@id": "odrl:eq" |
| 235 | + }, |
| 236 | + "odrl:rightOperand": "gold-partners" |
| 237 | + } |
| 238 | + } |
| 239 | + }, |
| 240 | + "odrl:prohibition": [], |
| 241 | + "odrl:obligation": [], |
| 242 | + "odrl:target": { |
| 243 | + "@id": "30" |
| 244 | + } |
| 245 | + }, |
| 246 | + "dcat:distribution": [ |
| 247 | + { |
| 248 | + "@type": "dcat:Distribution", |
| 249 | + "dct:format": { |
| 250 | + "@id": "HttpProxy-PUSH" |
| 251 | + }, |
| 252 | + "dcat:accessService": "b7c41185-0c2f-42cd-b19d-2ef8e2b6b6a6" |
| 253 | + }, |
| 254 | + { |
| 255 | + "@type": "dcat:Distribution", |
| 256 | + "dct:format": { |
| 257 | + "@id": "HttpData-PULL" |
| 258 | + }, |
| 259 | + "dcat:accessService": "b7c41185-0c2f-42cd-b19d-2ef8e2b6b6a6" |
| 260 | + } |
| 261 | + ], |
| 262 | + "description": "Product EDC Demo Asset", |
| 263 | + "id": "30" |
| 264 | + } |
| 265 | + ], |
| 266 | + "dcat:service": { |
| 267 | + "@id": "b7c41185-0c2f-42cd-b19d-2ef8e2b6b6a6", |
| 268 | + "@type": "dcat:DataService", |
| 269 | + "dct:terms": "connector", |
| 270 | + "dct:endpointUrl": "http://alice-controlplane:8084/api/v1/dsp" |
| 271 | + }, |
| 272 | + "participantId": "BPNL000000000001", |
| 273 | + "@context": {} |
| 274 | +} |
| 275 | +``` |
| 276 | + |
| 277 | +## 7. References |
| 278 | +- [Business Partner Validation Extension](https://github.com/eclipse-tractusx/tractusx-edc/tree/main/edc-extensions/bpn-validation) |
| 279 | +- [Business Partner Group API Swagger Documentation](https://app.swaggerhub.com/apis/eclipse-tractusx-bot/tractusx-edc) |
| 280 | +- [EDC Management API Swagger Documentation](https://app.swaggerhub.com/apis/eclipse-edc-bot/management-api) |
0 commit comments