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