source: examples/python_tests/payraise_rt1/attr.py @ 47d5cf9

mei_rt2mei_rt2_fix_1
Last change on this file since 47d5cf9 was 5f551d3, checked in by Mei <mei@…>, 12 years ago

1) add more python examples

  • Property mode set to 100755
File size: 4.7 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
51head=ABAC.Role(alpha,"payRaise")
52param=ABAC.DataTerm("principal", "This")
53tail1 = ABAC.Role(alpha,"evaluatorOf","goodPerformance")
54tail1.role_add_linked_data_term(param)
55param=ABAC.DataTerm("principal", "This")
56tail2 = ABAC.Role(alpha,"managerOf","niceCoworker")
57tail2.role_add_linked_data_term(param)
58attr=ABAC.Attribute(head, 1800)
59attr.attribute_add_tail(tail1)
60attr.attribute_add_tail(tail2)
61attr.attribute_bake()
62attr.attribute_write_cert("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
63ctxt.load_attribute_file("Alpha_payraise__Alpha_performance_qT_niceguy_qT_attr.der")
64print attr.string() 
65print attr.typed_string()
66print "\n"
67
68#################################################
69# [keyid:alpha].role:managerOf([principal:?Z])<-
70#           [keyid:alpha].role:evaluatorOf([principal:?Z])
71param=ABAC.DataTerm("principal", "Z")
72head=ABAC.Role(alpha,"managerOf")
73head.role_add_data_term(param)
74param=ABAC.DataTerm("principal", "Z")
75tail = ABAC.Role(alpha,"evaluatorOf")
76tail.role_add_data_term(param)
77attr=ABAC.Attribute(head, 1800)
78attr.attribute_add_tail(tail)
79attr.attribute_bake()
80attr.attribute_write_cert("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
81ctxt.load_attribute_file("Alpha_manager_qZ__Alpha_evaluator_qZ_attr.der")
82print attr.string() 
83print attr.typed_string()
84print "\n"
85
86#################################################
87# [keyid:alpha].role:evaluatorOf([keyid:Maryann]) <-[keyid:Bob]
88param=ABAC.DataTerm(maryannID)
89head = ABAC.Role(alpha,"evaluatorOf")
90head.role_add_data_term(param)
91tail = ABAC.Role(bob)
92attr=ABAC.Attribute(head, 1800)
93attr.attribute_add_tail(tail)
94attr.attribute_bake()
95attr.attribute_write_cert("Alpha_evaluator_m__Bob_attr.der")
96ctxt.load_attribute_file("Alpha_evaluator_m__Bob_attr.der")
97print attr.string() 
98print attr.typed_string()
99print "\n"
100
101#################################################
102# [keyid:Bob].role:goodPerformance <- [keyid:Maryann])
103head = ABAC.Role(bob,"goodPerformance")
104tail = ABAC.Role(maryann)
105attr=ABAC.Attribute(head, 1800)
106attr.attribute_add_tail(tail)
107attr.attribute_bake()
108attr.attribute_write_cert("Bob_goodperformance__Maryann_attr.der")
109ctxt.load_attribute_file("Bob_goodperformance__Maryann_attr.der")
110print attr.string() 
111print attr.typed_string()
112print "\n"
113
114#################################################
115# [keyid:Bob].role:niceCoworker <- [keyid:Maryann])
116head = ABAC.Role(bob,"niceCoworker")
117tail = ABAC.Role(maryann)
118attr=ABAC.Attribute(head, 1800)
119attr.attribute_add_tail(tail)
120attr.attribute_bake()
121attr.attribute_write_cert("Bob_nicecoworker__Maryann_attr.der")
122ctxt.load_attribute_file("Bob_nicecoworker__Maryann_attr.der")
123print attr.string() 
124print attr.typed_string()
125print "\n"
126
127#################################################
128# [keyid:alpha].role:evaluatorOf([keyid:Joe]) <-[keyid:Bob]
129param=ABAC.DataTerm(joeID)
130head = ABAC.Role(alpha,"evaluatorOf")
131head.role_add_data_term(param)
132tail = ABAC.Role(bob)
133attr=ABAC.Attribute(head, 1800)
134attr.attribute_add_tail(tail)
135attr.attribute_bake()
136attr.attribute_write_cert("Alpha_evaluator_j__Bob_attr.der")
137ctxt.load_attribute_file("Alpha_evaluator_j__Bob_attr.der")
138print attr.string() 
139print attr.typed_string()
140print "\n"
141
142#################################################
143# [keyid:Bob].role:goodPerformance <- [keyid:Joe])
144head = ABAC.Role(bob,"goodPerformance")
145tail = ABAC.Role(joe)
146attr=ABAC.Attribute(head, 1800)
147attr.attribute_add_tail(tail)
148attr.attribute_bake()
149attr.attribute_write_cert("Bob_goodperformance__Joe_attr.der")
150ctxt.load_attribute_file("Bob_goodperformance__Joe_attr.der")
151print attr.string() 
152print attr.typed_string()
153print "\n"
154
155
156ctxt.dump_yap_db()
157##
Note: See TracBrowser for help on using the repository browser.