[7211a95] | 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 | alphaID=ABAC.ID("Alpha_ID.pem"); |
---|
| 23 | alphaID.id_load_privkey_file("Alpha_private.pem"); |
---|
| 24 | alpha=alphaID.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 | maryannID=ABAC.ID("Maryann_ID.pem"); |
---|
| 31 | maryannID.id_load_privkey_file("Maryann_private.pem"); |
---|
| 32 | maryann=maryannID.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:alpha].role:payRaise |
---|
| 40 | # p=[keyid:Joe] |
---|
| 41 | role = ABAC.Role(alpha,"payRaise") |
---|
| 42 | p = ABAC.Role(joe) |
---|
| 43 | print "\n===bad============ alpha.payRaise <- Joe" |
---|
| 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 | |
---|
| 50 | ########################################################################## |
---|
| 51 | # role=[keyid:alpha].role:payRaise |
---|
| 52 | # p=[keyid:Maryann] |
---|
| 53 | role = ABAC.Role(alpha,"payRaise") |
---|
| 54 | p = ABAC.Role(maryann) |
---|
| 55 | print "\n===good============ alpha.payRaise <- Maryann" |
---|
| 56 | out = ctxt.query(role, p) |
---|
| 57 | for c in out[1]: |
---|
| 58 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | ########################################################################## |
---|
| 62 | # dump the loaded principals/policies |
---|
| 63 | # |
---|
| 64 | out = ctxt.context_principals() |
---|
| 65 | print "\n...final principal set..." |
---|
| 66 | for x in out[1]: |
---|
| 67 | print "%s " % x.string() |
---|
| 68 | print "\n" |
---|
| 69 | out = ctxt.context_credentials() |
---|
| 70 | print "\n...final policy attribute set..." |
---|
| 71 | for c in out[1]: |
---|
| 72 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 73 | print "\n" |
---|
| 74 | |
---|
| 75 | |
---|