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 | aliceID=ABAC.ID("Alice_ID.pem") |
---|
23 | aliceID.id_load_privkey_file("Alice_private.pem") |
---|
24 | alice=aliceID.id_keyid() |
---|
25 | |
---|
26 | partyID=ABAC.ID("Party_ID.pem") |
---|
27 | partyID.id_load_privkey_file("Party_private.pem") |
---|
28 | party=partyID.id_keyid() |
---|
29 | |
---|
30 | teaID=ABAC.ID("Tea_ID.pem") |
---|
31 | teaID.id_load_privkey_file("Tea_private.pem") |
---|
32 | tea=teaID.id_keyid() |
---|
33 | |
---|
34 | hatterID=ABAC.ID("Hatter_ID.pem") |
---|
35 | hatterID.id_load_privkey_file("Hatter_private.pem") |
---|
36 | hatter=hatterID.id_keyid() |
---|
37 | |
---|
38 | marchhareID=ABAC.ID("Marchhare_ID.pem") |
---|
39 | marchhareID.id_load_privkey_file("Marchhare_private.pem") |
---|
40 | marchhare=marchhareID.id_keyid() |
---|
41 | |
---|
42 | dormouseID=ABAC.ID("Dormouse_ID.pem") |
---|
43 | dormouseID.id_load_privkey_file("Dormouse_private.pem") |
---|
44 | dormouse=dormouseID.id_keyid() |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | ########################################################################## |
---|
49 | # role=[keyid:Party].role:guests |
---|
50 | # p=[keyid:dormouse] |
---|
51 | role = ABAC.Role(party,"guests") |
---|
52 | p = ABAC.Role(dormouse) |
---|
53 | print "\n===good============ Party.guests <- dourmouse" |
---|
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:Party].role:guests |
---|
60 | # p=[keyid:hatter] |
---|
61 | role = ABAC.Role(party,"guests") |
---|
62 | p = ABAC.Role(hatter) |
---|
63 | print "\n===bad============ Party.guests <- hatter" |
---|
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" |
---|