[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 | leagueID=ABAC.ID("League_ID.pem"); |
---|
| 23 | leagueID.id_load_privkey_file("League_private.pem"); |
---|
| 24 | league=leagueID.id_keyid() |
---|
| 25 | |
---|
| 26 | johnID=ABAC.ID("John_ID.pem"); |
---|
| 27 | johnID.id_load_privkey_file("John_private.pem"); |
---|
| 28 | john=johnID.id_keyid() |
---|
| 29 | |
---|
| 30 | markID=ABAC.ID("Mark_ID.pem"); |
---|
| 31 | markID.id_load_privkey_file("Mark_private.pem"); |
---|
| 32 | mark=markID.id_keyid() |
---|
| 33 | |
---|
| 34 | ########################################################################## |
---|
| 35 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T130000]) |
---|
| 36 | # p=[keyid:john] |
---|
| 37 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 38 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 39 | param3=ABAC.DataTerm("time", "20120228T130000") |
---|
| 40 | role = ABAC.Role(league,"stadium") |
---|
| 41 | role.role_add_data_term(param1) |
---|
| 42 | role.role_add_data_term(param2) |
---|
| 43 | role.role_add_data_term(param3) |
---|
| 44 | p=ABAC.Role(john) |
---|
| 45 | print "\n===good============ league.stadium(access,true,20120128T130000)<-?-john" |
---|
| 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 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T110000]) |
---|
| 52 | # p=[keyid:mark] |
---|
| 53 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 54 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 55 | param3=ABAC.DataTerm("time", "20120228T110000") |
---|
| 56 | role = ABAC.Role(league,"stadium") |
---|
| 57 | role.role_add_data_term(param1) |
---|
| 58 | role.role_add_data_term(param2) |
---|
| 59 | role.role_add_data_term(param3) |
---|
| 60 | p=ABAC.Role(mark) |
---|
| 61 | print "\n===bad============ league.stadium(access,true,20120128T110000)<-?-mark" |
---|
| 62 | out = ctxt.query(role, p) |
---|
| 63 | for c in out[1]: |
---|
| 64 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 65 | |
---|
| 66 | ########################################################################## |
---|
| 67 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T080000]) |
---|
| 68 | # p=[keyid:mark] |
---|
| 69 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 70 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 71 | param3=ABAC.DataTerm("time", "20120228T080000") |
---|
| 72 | role = ABAC.Role(league,"stadium") |
---|
| 73 | role.role_add_data_term(param1) |
---|
| 74 | role.role_add_data_term(param2) |
---|
| 75 | role.role_add_data_term(param3) |
---|
| 76 | p=ABAC.Role(mark) |
---|
| 77 | print "\n===good============ league.stadium(access,true,20120128T080000)<-?-mark" |
---|
| 78 | out = ctxt.query(role, p) |
---|
| 79 | for c in out[1]: |
---|
| 80 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 81 | |
---|
| 82 | ########################################################################## |
---|
| 83 | # dump the yap dB |
---|
| 84 | # |
---|
| 85 | #ctxt.dump_yap_db() |
---|
| 86 | |
---|
| 87 | ########################################################################## |
---|
| 88 | # dump the loaded principals/policies |
---|
| 89 | # |
---|
| 90 | out = ctxt.context_principals() |
---|
| 91 | print "\n...final principal set..." |
---|
| 92 | for x in out[1]: |
---|
| 93 | print "%s " % x.string() |
---|
| 94 | print "\n" |
---|
| 95 | out = ctxt.context_credentials() |
---|
| 96 | print "\n...final policy attribute set..." |
---|
| 97 | for c in out[1]: |
---|
| 98 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 99 | print "\n" |
---|
| 100 | |
---|