source: examples/python_tests/payraise_rt1/attr.py @ 7211a95

mei_rt2mei_rt2_fix_1
Last change on this file since 7211a95 was 7211a95, checked in by Mei <mei@…>, 12 years ago

1) add more python examples
2) add the missing linking role and linking oset api calls
3) fix the output of time typed data term/oset obj in typed_string format

(transform back from yap time format to our ddddddddTdddddd format

  • Property mode set to 100755
File size: 4.8 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./attr.py
7"""
8
9import os
10import ABAC
11
12keystore=os.environ["keystore"]
13
14ctxt = ABAC.Context()
15print "ABAC version %s" % ctxt.version()
16
17ctxt.load_directory(keystore)
18
19out = ctxt.context_principals()
20print "...initial principal set..."
21for x in out[1]:
22    print "%s " % x.string()
23print "\n" 
24
25out = ctxt.context_credentials()
26print "...initial policy attribute set..."
27for c in out[1]:
28    print "%s <- %s" % (c.head_string(), c.tail_string())
29print "\n"
30
31alphaID=ABAC.ID("Alpha_ID.pem");
32alphaID.id_load_privkey_file("Alpha_private.pem");
33alpha=alphaID.id_keyid()
34
35bobID=ABAC.ID("Bob_ID.pem");
36bobID.id_load_privkey_file("Bob_private.pem");
37bob=bobID.id_keyid()
38
39maryannID=ABAC.ID("Maryann_ID.pem");
40maryannID.id_load_privkey_file("Maryann_private.pem");
41maryann=maryannID.id_keyid()
42
43joeID=ABAC.ID("Joe_ID.pem");
44joeID.id_load_privkey_file("Joe_private.pem");
45joe=joeID.id_keyid()
46
47################################################
48# [keyid:alpha].role:payRaise <-
49#      [keyid:alpha].role:evaluatorOf([principal:?this]).role:goodPerformance &
50#      [keyid:alpha].role:managerOf([principal:?this]).role:niceCoworker
51
52# [keyid:alpha].role:access([string:'Read'],[urn:'file//fileB']) <- [keyid:bob]
53head=ABAC.Role(alpha,"payRaise")
54param=ABAC.DataTerm("principal", "This")
55tail1 = ABAC.Role(alpha,"evaluatorOf","goodPerformance")
56tail1.role_add_linked_data_term(param)
57param=ABAC.DataTerm("principal", "This")
58tail2 = ABAC.Role(alpha,"managerOf","niceCoworker")
59tail2.role_add_linked_data_term(param)
60attr=ABAC.Attribute(head, 1800)
61attr.attribute_add_tail(tail1)
62attr.attribute_add_tail(tail2)
63attr.attribute_bake()
64attr.attribute_write_cert("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
65ctxt.load_attribute_file("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
66print attr.string() 
67print attr.typed_string()
68print "\n"
69
70#################################################
71# [keyid:alpha].role:managerOf([principal:?Z])<-
72#           [keyid:alpha].role:evaluatorOf([principal:?Z])
73param=ABAC.DataTerm("principal", "Z")
74head=ABAC.Role(alpha,"managerOf")
75head.role_add_data_term(param)
76param=ABAC.DataTerm("principal", "Z")
77tail = ABAC.Role(alpha,"evaluatorOf")
78tail.role_add_data_term(param)
79attr=ABAC.Attribute(head, 1800)
80attr.attribute_add_tail(tail)
81attr.attribute_bake()
82attr.attribute_write_cert("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
83ctxt.load_attribute_file("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
84print attr.string() 
85print attr.typed_string()
86print "\n"
87
88#################################################
89# [keyid:alpha].role:evaluatorOf([keyid:Maryann]) <-[keyid:Bob]
90param=ABAC.DataTerm(maryannID)
91head = ABAC.Role(alpha,"evaluatorOf")
92head.role_add_data_term(param)
93tail = ABAC.Role(bob)
94attr=ABAC.Attribute(head, 1800)
95attr.attribute_add_tail(tail)
96attr.attribute_bake()
97attr.attribute_write_cert("Alpha_evaluator_m__Bob_attr.der")
98ctxt.load_attribute_file("Alpha_evaluator_m__Bob_attr.der")
99print attr.string() 
100print attr.typed_string()
101print "\n"
102
103#################################################
104# [keyid:Bob].role:goodPerformance <- [keyid:Maryann])
105head = ABAC.Role(bob,"goodPerformance")
106tail = ABAC.Role(maryann)
107attr=ABAC.Attribute(head, 1800)
108attr.attribute_add_tail(tail)
109attr.attribute_bake()
110attr.attribute_write_cert("Bob_goodperformance__Maryann_attr.der")
111ctxt.load_attribute_file("Bob_goodperformance__Maryann_attr.der")
112print attr.string() 
113print attr.typed_string()
114print "\n"
115
116#################################################
117# [keyid:Bob].role:niceCoworker <- [keyid:Maryann])
118head = ABAC.Role(bob,"niceCoworker")
119tail = ABAC.Role(maryann)
120attr=ABAC.Attribute(head, 1800)
121attr.attribute_add_tail(tail)
122attr.attribute_bake()
123attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der")
124ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der")
125print attr.string() 
126print attr.typed_string()
127print "\n"
128
129#################################################
130# [keyid:alpha].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob]
131param=ABAC.DataTerm(joeID)
132head = ABAC.Role(alpha,"evaluatorOf")
133head.role_add_data_term(param)
134tail = ABAC.Role(bob)
135attr=ABAC.Attribute(head, 1800)
136attr.attribute_add_tail(tail)
137attr.attribute_bake()
138attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der")
139ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der")
140print attr.string() 
141print attr.typed_string()
142print "\n"
143
144#################################################
145# [keyid:Bob].role:goodPerformance <- [keyid:Joe])
146head = ABAC.Role(bob,"goodPerformance")
147tail = ABAC.Role(joe)
148attr=ABAC.Attribute(head, 1800)
149attr.attribute_add_tail(tail)
150attr.attribute_bake()
151attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der")
152ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der")
153print attr.string() 
154print attr.typed_string()
155print "\n"
156
157
158ctxt.dump_yap_db()
159##
Note: See TracBrowser for help on using the repository browser.