source: examples/python_tests/alumni2_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: 3.6 KB
RevLine 
[5f551d3]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
40joeID=ABAC.ID("Joe_ID.pem")
41joeID.id_load_privkey_file("Joe_private.pem")
42joe=joeID.id_keyid()
43
44maryannID=ABAC.ID("Maryann_ID.pem")
45maryannID.id_load_privkey_file("Maryann_private.pem")
46maryann=maryannID.id_keyid()
47
48
49################################################
50# [keyid:stateU].role:foundingAlumni
51#                   <- [keyid:stateU].role:diploma([?], [integer:?Year:[1960,1961,1963]])
52head = ABAC.Role(stateU,"foundingAlumni")
53param1=ABAC.DataTerm("anonymous", "_")
54cond=ABAC.Constraint("integer")
55cond.constraint_add_integer_target(1960)
56cond.constraint_add_integer_target(1961)
57cond.constraint_add_integer_target(1963)
58param2=ABAC.DataTerm("integer", "Year", cond)
59tail = ABAC.Role(stateU,"diploma")
60tail.role_add_data_term(param1)
61tail.role_add_data_term(param2)
62attr=ABAC.Attribute(head, 1800)
63attr.attribute_add_tail(tail)
64attr.attribute_bake()
65attr.attribute_write_cert("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
66ctxt.load_attribute_file("StateU_foundingAlumni__stateU_diploma_q_qY_attr.der")
67print attr.string() 
68print attr.typed_string()
69print "\n"
70
71#################################################
72# [keyid:stateU].role:diploma([string:'mathmatics'],[integer:1961]) <- [keyid:bob]
73param1=ABAC.DataTerm("string", "'mathmatics'")
74param2=ABAC.DataTerm("integer", "1961")
75head = ABAC.Role(stateU,"diploma")
76head.role_add_data_term(param1)
77head.role_add_data_term(param2)
78tail = ABAC.Role(bob)
79attr=ABAC.Attribute(head, 1800)
80attr.attribute_add_tail(tail)
81attr.attribute_bake()
82attr.attribute_write_cert("StateU_diploma_m__Bob_attr.der")
83ctxt.load_attribute_file("StateU_diploma_m__Bob_attr.der")
84print attr.string() 
85print attr.typed_string()
86print "\n"
87
88#################################################
89# [keyid:stateU].role:diploma([string:'zoology'],[integer:1955]) <- [keyid:joe]
90param1=ABAC.DataTerm("string", "'zoology'")
91param2=ABAC.DataTerm("integer", "1955")
92head = ABAC.Role(stateU,"diploma")
93head.role_add_data_term(param1)
94head.role_add_data_term(param2)
95tail = ABAC.Role(joe)
96attr=ABAC.Attribute(head, 1800)
97attr.attribute_add_tail(tail)
98attr.attribute_bake()
99attr.attribute_write_cert("StateU_diploma_z__Joe_attr.der")
100ctxt.load_attribute_file("StateU_diploma_z__Joe_attr.der")
101print attr.string() 
102print attr.typed_string()
103print "\n"
104
105#################################################
106# [keyid:stateU].role:diploma([string:'psychology'],[integer:1962]) <- [keyid:maryann]
107param1=ABAC.DataTerm("string", "'psychology'")
108param2=ABAC.DataTerm("integer", "1962")
109head = ABAC.Role(stateU,"diploma")
110head.role_add_data_term(param1)
111head.role_add_data_term(param2)
112tail = ABAC.Role(maryann)
113attr=ABAC.Attribute(head, 1800)
114attr.attribute_add_tail(tail)
115attr.attribute_bake()
116attr.attribute_write_cert("StateU_diploma_p__Maryann_attr.der")
117ctxt.load_attribute_file("StateU_diploma_p__Maryann_attr.der")
118print attr.string() 
119print attr.typed_string()
120print "\n"
121
122ctxt.dump_yap_db()
123##
Note: See TracBrowser for help on using the repository browser.