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 | joeID=ABAC.ID("Joe_ID.pem") |
---|
31 | joeID.id_load_privkey_file("Joe_private.pem") |
---|
32 | joe=joeID.id_keyid() |
---|
33 | |
---|
34 | maryannID=ABAC.ID("Maryann_ID.pem") |
---|
35 | maryannID.id_load_privkey_file("Maryann_private.pem") |
---|
36 | maryann=maryannID.id_keyid() |
---|
37 | |
---|
38 | ########################################################################## |
---|
39 | # role=[keyid:stateU].role:foundingAlumni |
---|
40 | # p=[keyid:Bob] |
---|
41 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
42 | p = ABAC.Role(bob) |
---|
43 | print "\n===good============ stateU.foundingAlumni <- Bob" |
---|
44 | out = ctxt.query(role, p) |
---|
45 | for c in out[1]: |
---|
46 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
47 | |
---|
48 | ########################################################################## |
---|
49 | # role=[keyid:stateU].role:foundingAlumni |
---|
50 | # p=[keyid:Maryann] |
---|
51 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
52 | p = ABAC.Role(maryann) |
---|
53 | print "\n===bad============ stateU.foundingAlumni <- Maryann" |
---|
54 | out = ctxt.query(role, p) |
---|
55 | for c in out[1]: |
---|
56 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
57 | |
---|
58 | ########################################################################## |
---|
59 | # role=[keyid:stateU].role:foundingAlumni |
---|
60 | # p=[keyid:Joe] |
---|
61 | role = ABAC.Role(stateU,"foundingAlumni") |
---|
62 | p = ABAC.Role(joe) |
---|
63 | print "\n===bad============ stateU.foundingAlumni <- Joe" |
---|
64 | out = ctxt.query(role, p) |
---|
65 | for c in out[1]: |
---|
66 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
67 | |
---|
68 | ########################################################################## |
---|
69 | # dump the loaded principals/policies |
---|
70 | # |
---|
71 | out = ctxt.context_principals() |
---|
72 | print "\n...final principal set..." |
---|
73 | for x in out[1]: |
---|
74 | print "%s " % x.string() |
---|
75 | print "\n" |
---|
76 | out = ctxt.context_credentials() |
---|
77 | print "\n...final policy attribute set..." |
---|
78 | for c in out[1]: |
---|
79 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
80 | print "\n" |
---|
81 | |
---|
82 | |
---|