Skip to content

Commit 8434cbd

Browse files
committed
Added Partial DU methods
1 parent 32cf03d commit 8434cbd

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

DecisionUnit.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package HLF_ABAC
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-contract-api-go/contractapi"
7+
)
8+
9+
func getContext() *map[string]string {
10+
return nil
11+
}
12+
13+
func isValid(rule *Policy, UAPub *map[string]string, RAPub *map[string]string, RAPriv *map[string]string, EA *map[string]string, OP string) bool {
14+
return true
15+
}
16+
17+
func validateAccess(ctx contractapi.TransactionContextInterface, userIDHash string, resourceID string, operation string, collection string) (*Resource, error) {
18+
19+
if len(userIDHash) == 0 {
20+
return nil, fmt.Errorf("Please enter valid Subject ID")
21+
}
22+
23+
if len(resourceID) == 0 {
24+
return nil, fmt.Errorf("Please enter valid Object ID")
25+
}
26+
27+
userID, err := GetSubmittingClientIdentity(ctx)
28+
userPubKey, err := GetSubmittingClientPubKey(ctx)
29+
30+
// User Verification
31+
32+
UAPub := getUAPub(ctx, userID).Attributes
33+
RAPub := getRAPub(ctx, resourceID).Attributes
34+
RAPriv := getRAPriv(ctx, resourceID, collection).Attributes
35+
EA := getContext()
36+
37+
POL := getPolicySet(ctx)
38+
39+
for _, rule := range POL {
40+
if !isValid(rule, UAPub, RAPub, RAPriv, EA, operation) {
41+
continue
42+
}
43+
44+
return getResource(ctx, resourceID, collection), nil
45+
}
46+
47+
return nil, fmt.Errorf("Access Denied")
48+
}

Owner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func updateRAPub(ctx contractapi.TransactionContextInterface, resourceID string,
9999
Attributes: attrsmap,
100100
}
101101

102-
resourceAttrJSON, err := json.Marshal(resourceAttr)
102+
resourceAttrJSON, err = json.Marshal(resourceAttr)
103103
if err != nil {
104104
return "", err
105105
}
@@ -210,7 +210,7 @@ func updateRAPriv(ctx contractapi.TransactionContextInterface, resourceID string
210210
Attributes: attrsmap,
211211
}
212212

213-
resourceAttrJSON, err := json.Marshal(resourceAttr)
213+
resourceAttrJSON, err = json.Marshal(resourceAttr)
214214
if err != nil {
215215
return "", err
216216
}

Policy.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ type Policy struct {
1313
UserAttr map[string]string `json:"userAttr"`
1414
ResourceAttr map[string]string `json:"resourceAttr"`
1515
EnvAttr map[string]string `json:"envAttr"`
16+
Operation string `json:"op"`
1617
Rules map[string]string `json:"rules"`
1718
}
1819

19-
func registerPolicy(ctx contractapi.TransactionContextInterface, policyID string, userAttr string, resourceAttr string, envAttr string, rules string) (string, error) {
20+
func registerPolicy(ctx contractapi.TransactionContextInterface, policyID string, userAttr string, resourceAttr string, envAttr string, operation string, rules string) (string, error) {
2021

2122
if len(policyID) == 0 {
2223
return "", fmt.Errorf("Please enter valid Policy ID")
@@ -63,6 +64,7 @@ func registerPolicy(ctx contractapi.TransactionContextInterface, policyID string
6364
UserAttr: userAttrsMap,
6465
ResourceAttr: resourceAttrsMap,
6566
EnvAttr: envAttrsMap,
67+
Operation: operation,
6668
Rules: rulesMap,
6769
}
6870

Resource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func updateResource(ctx contractapi.TransactionContextInterface, resourceID stri
8080
Data: data,
8181
}
8282

83-
resourceJSON, err := json.Marshal(resource)
83+
resourceJSON, err = json.Marshal(resource)
8484
if err != nil {
8585
return "", err
8686
}

User.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func updateUAPub(ctx contractapi.TransactionContextInterface, userID string, use
126126
Attributes: attrsmap,
127127
}
128128

129-
userJSON, err := json.Marshal(user)
129+
userJSON, err = json.Marshal(user)
130130

131131
if err != nil {
132132
return "", err

0 commit comments

Comments
 (0)