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 | ralphsID=ABAC.ID("Ralphs_ID.pem"); |
---|
23 | ralphsID.id_load_privkey_file("Ralphs_private.pem"); |
---|
24 | ralphs=ralphsID.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 | maryID=ABAC.ID("Mary_ID.pem"); |
---|
31 | maryID.id_load_privkey_file("Mary_private.pem"); |
---|
32 | mary=maryID.id_keyid() |
---|
33 | |
---|
34 | ########################################################################## |
---|
35 | # oset = [keyid:mary].oset:what2eat |
---|
36 | # p [string:'navel orange'] |
---|
37 | oset = ABAC.Oset(mary,"what2eat") |
---|
38 | term=ABAC.DataTerm("string", "'navel orange'") |
---|
39 | p = ABAC.Oset(term) |
---|
40 | |
---|
41 | print "\n===good============ mary.what2eat <- navel orange" |
---|
42 | out = ctxt.query(oset, p) |
---|
43 | for c in out[1]: |
---|
44 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
45 | |
---|
46 | ########################################################################## |
---|
47 | # oset = [keyid:mary].oset:what2eat |
---|
48 | # p [string:'kiwi'] |
---|
49 | oset = ABAC.Oset(mary,"what2eat") |
---|
50 | term=ABAC.DataTerm("string", "'kiwi'") |
---|
51 | p = ABAC.Oset(term) |
---|
52 | |
---|
53 | print "\n===good============ mary.what2eat <- kiwi" |
---|
54 | out = ctxt.query(oset, p) |
---|
55 | for c in out[1]: |
---|
56 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
57 | |
---|
58 | ########################################################################## |
---|
59 | # oset = [keyid:bob].oset:what2eat |
---|
60 | # p [string:'navel orange'] |
---|
61 | oset = ABAC.Oset(bob,"what2eat") |
---|
62 | term=ABAC.DataTerm("string", "'navel orange'") |
---|
63 | p = ABAC.Oset(term) |
---|
64 | |
---|
65 | print "\n===bad============ bob.what2eat <- navel orange" |
---|
66 | out = ctxt.query(oset, p) |
---|
67 | for c in out[1]: |
---|
68 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
69 | |
---|
70 | ########################################################################## |
---|
71 | # oset = [keyid:$ralphs].oset:fruitprice([float:1.50]) |
---|
72 | # p = [string:'apple'] |
---|
73 | param=ABAC.DataTerm("float", "1.50") |
---|
74 | oset = ABAC.Oset(ralphs,"fruitprice") |
---|
75 | oset.oset_add_data_term(param) |
---|
76 | term=ABAC.DataTerm("string", "'apple'") |
---|
77 | p = ABAC.Oset(term) |
---|
78 | |
---|
79 | print "\n===good============ ralphs.fruitprice(1.50) <- apple" |
---|
80 | out = ctxt.query(oset, p) |
---|
81 | for c in out[1]: |
---|
82 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
83 | |
---|
84 | ########################################################################## |
---|
85 | # oset = [keyid:$ralphs].oset:fruitprice([float:1.50]) |
---|
86 | # p = [string:'green apple'] |
---|
87 | param=ABAC.DataTerm("float", "1.50") |
---|
88 | oset = ABAC.Oset(ralphs,"fruitprice") |
---|
89 | oset.oset_add_data_term(param) |
---|
90 | term=ABAC.DataTerm("string", "'green apple'") |
---|
91 | p = ABAC.Oset(term) |
---|
92 | |
---|
93 | print "\n===bad============ ralphs.fruitprice(1.50) <- green apple" |
---|
94 | out = ctxt.query(oset, p) |
---|
95 | for c in out[1]: |
---|
96 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
97 | |
---|
98 | ########################################################################## |
---|
99 | # dump the yap dB |
---|
100 | # |
---|
101 | #ctxt.dump_yap_db() |
---|
102 | |
---|
103 | ########################################################################## |
---|
104 | # dump the loaded principals/policies |
---|
105 | # |
---|
106 | out = ctxt.context_principals() |
---|
107 | print "\n...final principal set..." |
---|
108 | for x in out[1]: |
---|
109 | print "%s " % x.string() |
---|
110 | print "\n" |
---|
111 | out = ctxt.context_credentials() |
---|
112 | print "\n...final policy attribute set..." |
---|
113 | for c in out[1]: |
---|
114 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
115 | print "\n" |
---|
116 | |
---|
117 | |
---|
118 | |
---|