source: examples/python_tests/alumni3_rt1/query.py @ 7a452cd

mei_rt2mei_rt2_fix_1
Last change on this file since 7a452cd was f824a9e, checked in by Mei <mei@…>, 13 years ago

1) add more doc to python_tests

  • Property mode set to 100755
File size: 3.3 KB
Line 
1#!/usr/bin/env python
2
3"""
4Run the queries described in README
5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set...")
23    exit(1)
24
25# retrieve principals' keyid value from local credential files
26stateUID=ABAC.ID("StateU_ID.pem")
27stateUID.id_load_privkey_file("StateU_private.pem")
28stateU=stateUID.id_keyid()
29
30bobID=ABAC.ID("Bob_ID.pem")
31bobID.id_load_privkey_file("Bob_private.pem")
32bob=bobID.id_keyid()
33
34markID=ABAC.ID("Mark_ID.pem")
35markID.id_load_privkey_file("Mark_private.pem")
36mark=markID.id_keyid()
37
38joeID=ABAC.ID("Joe_ID.pem")
39joeID.id_load_privkey_file("Joe_private.pem")
40joe=joeID.id_keyid()
41
42maryannID=ABAC.ID("Maryann_ID.pem")
43maryannID.id_load_privkey_file("Maryann_private.pem")
44maryann=maryannID.id_keyid()
45
46janID=ABAC.ID("Jan_ID.pem")
47janID.id_load_privkey_file("Jan_private.pem")
48jan=janID.id_keyid()
49
50##########################################################################
51# dump the loaded principals/policies
52#
53out = ctxt.context_principals()
54print "\n...final principal set..."
55for x in out[1]:
56    print "%s " % x.string()
57out = ctxt.context_credentials()
58print "\n...final policy attribute set..."
59for c in out[1]:
60    print "%s <- %s" % (c.head_string(), c.tail_string())
61
62##########################################################################
63# role=[keyid:stateU].role:foundingAlumni
64# p=[keyid:Bob]
65role = ABAC.Role(stateU,"foundingAlumni")
66p = ABAC.Role(bob)
67print "\n===good============ stateU.foundingAlumni <- Bob"
68out = ctxt.query(role, p)
69for c in out[1]:
70    print "%s <- %s" % (c.head_string(), c.tail_string())
71
72##########################################################################
73# role=[keyid:stateU].role:foundingAlumni
74# p=[keyid:Mark]
75role = ABAC.Role(stateU,"foundingAlumni")
76p = ABAC.Role(mark)
77print "\n===bad============ stateU.foundingAlumni <- Mark"
78out = ctxt.query(role, p)
79for c in out[1]:
80    print "%s <- %s" % (c.head_string(), c.tail_string())
81
82##########################################################################
83# role=[keyid:stateU].role:foundingAlumni
84# p=[keyid:Joe]
85role = ABAC.Role(stateU,"foundingAlumni")
86p = ABAC.Role(joe)
87print "\n===bad============ stateU.foundingAlumni <- Joe"
88out = ctxt.query(role, p)
89for c in out[1]:
90    print "%s <- %s" % (c.head_string(), c.tail_string())
91
92##########################################################################
93# role=[keyid:stateU].role:foundingAlumni
94# p=[keyid:Maryann]
95role = ABAC.Role(stateU,"foundingAlumni")
96p = ABAC.Role(maryann)
97print "\n===bad============ stateU.foundingAlumni <- Maryann"
98out = ctxt.query(role, p)
99for c in out[1]:
100    print "%s <- %s" % (c.head_string(), c.tail_string())
101
102##########################################################################
103# role=[keyid:stateU].role:foundingAlumni
104# p=[keyid:Jan]
105role = ABAC.Role(stateU,"foundingAlumni")
106p = ABAC.Role(jan)
107print "\n===good============ stateU.foundingAlumni <- Jan"
108out = ctxt.query(role, p)
109for c in out[1]:
110    print "%s <- %s" % (c.head_string(), c.tail_string())
111
Note: See TracBrowser for help on using the repository browser.