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 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
23 | acmeID.id_load_privkey_file("Acme_private.pem"); |
---|
24 | acme=acmeID.id_keyid() |
---|
25 | |
---|
26 | coyoteID=ABAC.ID("Coyote_ID.pem"); |
---|
27 | coyoteID.id_load_privkey_file("Coyote_private.pem"); |
---|
28 | coyote=coyoteID.id_keyid() |
---|
29 | |
---|
30 | warnerbrosID=ABAC.ID("WarnerBros_ID.pem"); |
---|
31 | warnerbrosID.id_load_privkey_file("WarnerBros_private.pem"); |
---|
32 | warnerbros=warnerbrosID.id_keyid() |
---|
33 | |
---|
34 | batmanID=ABAC.ID("Batman_ID.pem"); |
---|
35 | batmanID.id_load_privkey_file("Batman_private.pem"); |
---|
36 | batman=batmanID.id_keyid() |
---|
37 | |
---|
38 | ########################################################################## |
---|
39 | # role = "[keyid:Acme].role:buy_rockets" |
---|
40 | # p = "[keyid:coyote]" |
---|
41 | role = ABAC.Role(acme,"buy_rockets") |
---|
42 | p = ABAC.Role(coyote) |
---|
43 | |
---|
44 | print "\n===good============ Acme.buy_rockets <- Coyote" |
---|
45 | out = ctxt.query(role, p) |
---|
46 | |
---|
47 | for c in out[1]: |
---|
48 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
49 | |
---|
50 | |
---|
51 | ########################################################################## |
---|
52 | # role = "[keyid:Acme].role:buy_rockets" |
---|
53 | # p = "[keyid:batman]" |
---|
54 | role = ABAC.Role(acme,"buy_rockets") |
---|
55 | p = ABAC.Role(batman) |
---|
56 | |
---|
57 | print "\n===bad============ Acme.buy_rockets <- Batman" |
---|
58 | out = ctxt.query(role, p) |
---|
59 | |
---|
60 | for c in out[1]: |
---|
61 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
62 | |
---|
63 | |
---|
64 | ########################################################################## |
---|
65 | # dump the loaded principals/policies |
---|
66 | # |
---|
67 | out = ctxt.context_principals() |
---|
68 | print "\n...final principal set..." |
---|
69 | for x in out[1]: |
---|
70 | print "%s " % x.string() |
---|
71 | print "\n" |
---|
72 | out = ctxt.context_credentials() |
---|
73 | print "\n...final policy attribute set..." |
---|
74 | for c in out[1]: |
---|
75 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
76 | print "\n" |
---|
77 | |
---|
78 | |
---|
79 | |
---|