-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper.py
37 lines (32 loc) · 966 Bytes
/
mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# from poltree import *
import json
def get_code(a):
if(a == "read"): return 1
elif(a == "write"): return 2
else: return 0
def policy_rules_parse(policy_file):
file = open(policy_file, "r")
rules_json = json.load(file)
file.close()
print(len(rules_json))
# r1 = ABAC_RULE("r1", 0, , rules_json[0]["ua"], rules_json[0]["oa"])
# print(r1.get_user_attribute_value("designation"))
rule_list = []
for rule in rules_json:
rule_list.append(
ABAC_RULE(
rule["name"],
get_code(rule["op"]),
int(rule["ea"]["day"] == "weekday"),
rule["ua"],
rule["oa"]
)
)
return rule_list
def build(policy_file):
rules = policy_rules_parse(policy_file)
poltree = build_policy(rules)
return poltree
def evalute_request(poltree, ua, oa, access):
result = evaluate(poltree, ua, oa, access)
return result