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 | geniID=ABAC.ID("Geni_ID.pem"); |
---|
23 | geniID.id_load_privkey_file("Geni_private.pem"); |
---|
24 | geni=geniID.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 | jackID=ABAC.ID("Jack_ID.pem"); |
---|
31 | jackID.id_load_privkey_file("Jack_private.pem"); |
---|
32 | jack=jackID.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 | ########################################################################## |
---|
39 | # role=[keyid:geni].role:leader |
---|
40 | # p=[keyid:Bob] |
---|
41 | role = ABAC.Role(geni,"leader") |
---|
42 | p = ABAC.Role(bob) |
---|
43 | print "\n===good============ geni.leader <- 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:geni].role:leader |
---|
50 | # p=[keyid:Jack] |
---|
51 | role = ABAC.Role(geni,"leader") |
---|
52 | p = ABAC.Role(jack) |
---|
53 | print "\n===bad============ geni.leader <- Jack" |
---|
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:geni].role:leader |
---|
60 | # p=[keyid:Joe] |
---|
61 | role = ABAC.Role(geni,"leader") |
---|
62 | p = ABAC.Role(joe) |
---|
63 | print "\n===good============ geni.leader <- 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 | ########################################################################## |
---|
70 | # dump the loaded principals/policies |
---|
71 | # |
---|
72 | out = ctxt.context_principals() |
---|
73 | print "\n...final principal set..." |
---|
74 | for x in out[1]: |
---|
75 | print "%s " % x.string() |
---|
76 | print "\n" |
---|
77 | out = ctxt.context_credentials() |
---|
78 | print "\n...final policy attribute set..." |
---|
79 | for c in out[1]: |
---|
80 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
81 | print "\n" |
---|
82 | |
---|
83 | |
---|