[5f551d3] | 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 | ########################################################################## |
---|
| 31 | # role=[keyid:Acme].role:preferred_customer |
---|
| 32 | # p =[keyid:coyote] |
---|
| 33 | role = ABAC.Role(acme,"preferred_customer") |
---|
| 34 | p = ABAC.Role(coyote) |
---|
| 35 | print "\n===good============ Acme.preferred_customer <- Coyote" |
---|
| 36 | out = ctxt.query(role, p) |
---|
| 37 | for c in out[1]: |
---|
| 38 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 39 | |
---|
| 40 | ########################################################################## |
---|
| 41 | # role=[keyid:Acme].role:buy_rockets |
---|
| 42 | # p =[keyid:coyote] |
---|
| 43 | role = ABAC.Role(acme,"buy_rockets") |
---|
| 44 | p = ABAC.Role(coyote) |
---|
| 45 | print "\n===good============ Acme.buy_rockets <- Coyote" |
---|
| 46 | out = ctxt.query(role, p) |
---|
| 47 | for c in out[1]: |
---|
| 48 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | ########################################################################## |
---|
| 52 | # role=[keyid:Coyote].role:friend |
---|
| 53 | # p=[keyid:Acme] |
---|
| 54 | role = ABAC.Role(coyote,"friend") |
---|
| 55 | p = ABAC.Role(acme) |
---|
| 56 | print "\n===bad=============== Coyote.friend <- Acme" |
---|
| 57 | out = ctxt.query(role, p) |
---|
| 58 | for c in out[1]: |
---|
| 59 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | ########################################################################## |
---|
| 63 | # dump the loaded principals/policies |
---|
| 64 | # |
---|
| 65 | out = ctxt.context_principals() |
---|
| 66 | print "\n...final principal set..." |
---|
| 67 | for x in out[1]: |
---|
| 68 | print "%s " % x.string() |
---|
| 69 | print "\n" |
---|
| 70 | out = ctxt.context_credentials() |
---|
| 71 | print "\n...final policy attribute set..." |
---|
| 72 | for c in out[1]: |
---|
| 73 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 74 | print "\n" |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|