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

mei_rt2mei_rt2_fix_1
Last change on this file since 47d5cf9 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: 5.2 KB
Line 
1#!/usr/bin/env python
2
3"""
4  Setup access policy attribute rules
5
6cmd1:env keystore=`pwd` ./attr.py
7
8"""
9
10import os
11import ABAC
12
13keystore=os.environ["keystore"]
14
15ctxt = ABAC.Context()
16print "ABAC version %s" % ctxt.version()
17
18ctxt.load_directory(keystore)
19
20out = ctxt.context_principals()
21print "...initial principal set..."
22for x in out[1]:
23    print "%s " % x.string()
24print "\n" 
25
26out = ctxt.context_credentials()
27print "...initial policy attribute set..."
28for c in out[1]:
29    print "%s <- %s" % (c.head_string(), c.tail_string())
30print "\n"
31
32stateUID=ABAC.ID("StateU_ID.pem")
33stateUID.id_load_privkey_file("StateU_private.pem")
34stateU=stateUID.id_keyid()
35
36bobID=ABAC.ID("Bob_ID.pem")
37bobID.id_load_privkey_file("Bob_private.pem")
38bob=bobID.id_keyid()
39
40markID=ABAC.ID("Mark_ID.pem")
41markID.id_load_privkey_file("Mark_private.pem")
42mark=markID.id_keyid()
43
44joeID=ABAC.ID("Joe_ID.pem")
45joeID.id_load_privkey_file("Joe_private.pem")
46joe=joeID.id_keyid()
47
48maryannID=ABAC.ID("Maryann_ID.pem")
49maryannID.id_load_privkey_file("Maryann_private.pem")
50maryann=maryannID.id_keyid()
51
52janID=ABAC.ID("Jan_ID.pem")
53janID.id_load_privkey_file("Jan_private.pem")
54jan=janID.id_keyid()
55
56
57################################################
58# [keyid:stateU].role:foundingAlumni
59#              <- [keyid:stateU].role:diploma([string:?D:['mathmatics','psychology']],
60#                                             [integer:?Year:[1960,1961,1963]])
61head = ABAC.Role(stateU,"foundingAlumni")
62cond=ABAC.Constraint("string")
63cond.constraint_add_string_target("'mathmatics'")
64cond.constraint_add_string_target("'psychology'")
65param1=ABAC.DataTerm("string", "D", cond)
66cond=ABAC.Constraint("integer")
67cond.constraint_add_integer_target(1960)
68cond.constraint_add_integer_target(1961)
69cond.constraint_add_integer_target(1963)
70param2=ABAC.DataTerm("integer", "Year", cond)
71tail = ABAC.Role(stateU,"diploma")
72tail.role_add_data_term(param1)
73tail.role_add_data_term(param2)
74attr=ABAC.Attribute(head, 1800)
75attr.attribute_add_tail(tail)
76attr.attribute_bake()
77attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
78ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
79print attr.string() 
80print attr.typed_string()
81print "\n"
82
83#################################################
84# [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob]
85param1=ABAC.DataTerm("string", "'mathmatics'")
86param2=ABAC.DataTerm("integer", "1961")
87head = ABAC.Role(stateU,"diploma")
88head.role_add_data_term(param1)
89head.role_add_data_term(param2)
90tail = ABAC.Role(bob)
91attr=ABAC.Attribute(head, 1800)
92attr.attribute_add_tail(tail)
93attr.attribute_bake()
94attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der")
95ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der")
96print attr.string() 
97print attr.typed_string()
98print "\n"
99
100#################################################
101# [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1965]) <- [keyid:mark]
102param1=ABAC.DataTerm("string", "'mathmatics'")
103param2=ABAC.DataTerm("integer", "1965")
104head = ABAC.Role(stateU,"diploma")
105head.role_add_data_term(param1)
106head.role_add_data_term(param2)
107tail = ABAC.Role(mark)
108attr=ABAC.Attribute(head, 1800)
109attr.attribute_add_tail(tail)
110attr.attribute_bake()
111attr.attribute_write_cert("StateU_diploma_m__Mark_attr.der")
112ctxt.load_attribute_file("StateU_diploma_m__Mark_attr.der")
113print attr.string() 
114print attr.typed_string()
115print "\n"
116
117#################################################
118# [keyid:stateU].role:diploma([string:'zoology'],[integer:1961]) <- [keyid:joe]
119param1=ABAC.DataTerm("string", "'zoology'")
120param2=ABAC.DataTerm("integer", "1961")
121head = ABAC.Role(stateU,"diploma")
122head.role_add_data_term(param1)
123head.role_add_data_term(param2)
124tail = ABAC.Role(joe)
125attr=ABAC.Attribute(head, 1800)
126attr.attribute_add_tail(tail)
127attr.attribute_bake()
128attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der")
129ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der")
130print attr.string() 
131print attr.typed_string()
132print "\n"
133
134#################################################
135# [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann]
136param1=ABAC.DataTerm("string", "'psychology'")
137param2=ABAC.DataTerm("integer", "1962")
138head = ABAC.Role(stateU,"diploma")
139head.role_add_data_term(param1)
140head.role_add_data_term(param2)
141tail = ABAC.Role(maryann)
142attr=ABAC.Attribute(head, 1800)
143attr.attribute_add_tail(tail)
144attr.attribute_bake()
145attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der")
146ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der")
147print attr.string() 
148print attr.typed_string()
149print "\n"
150
151
152#################################################
153# [keyid:stateU].role:diploma([string:'psychology'],[integer:1960]) <- [keyid:jan]
154param1=ABAC.DataTerm("string", "'psychology'")
155param2=ABAC.DataTerm("integer", "1960")
156head = ABAC.Role(stateU,"diploma")
157head.role_add_data_term(param1)
158head.role_add_data_term(param2)
159tail = ABAC.Role(jan)
160attr=ABAC.Attribute(head, 1800)
161attr.attribute_add_tail(tail)
162attr.attribute_bake()
163attr.attribute_write_cert("StateU_diploma_p__Jan_attr.der")
164ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der")
165print attr.string() 
166print attr.typed_string()
167print "\n"
168
169
170ctxt.dump_yap_db()
171##
Note: See TracBrowser for help on using the repository browser.