[7211a95] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
[f824a9e] | 4 | Run the queries described in README |
---|
[7211a95] | 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 | |
---|
[f824a9e] | 16 | # Keystore is the directory containing the principal credentials. |
---|
| 17 | # Load existing principals and/or policy credentials |
---|
| 18 | if (os.environ.has_key("keystore")) : |
---|
| 19 | keystore=os.environ["keystore"] |
---|
| 20 | ctxt.load_directory(keystore) |
---|
| 21 | else: |
---|
| 22 | print("keystore is not set...") |
---|
| 23 | exit(1) |
---|
[7211a95] | 24 | |
---|
[f824a9e] | 25 | # retrieve principals' keyid value from local credential files |
---|
[7211a95] | 26 | leagueID=ABAC.ID("League_ID.pem"); |
---|
| 27 | leagueID.id_load_privkey_file("League_private.pem"); |
---|
| 28 | league=leagueID.id_keyid() |
---|
| 29 | |
---|
| 30 | johnID=ABAC.ID("John_ID.pem"); |
---|
| 31 | johnID.id_load_privkey_file("John_private.pem"); |
---|
| 32 | john=johnID.id_keyid() |
---|
| 33 | |
---|
| 34 | markID=ABAC.ID("Mark_ID.pem"); |
---|
| 35 | markID.id_load_privkey_file("Mark_private.pem"); |
---|
| 36 | mark=markID.id_keyid() |
---|
| 37 | |
---|
| 38 | ########################################################################## |
---|
[f824a9e] | 39 | # dump the loaded principals/policies |
---|
| 40 | # |
---|
| 41 | out = ctxt.context_principals() |
---|
| 42 | print "\n...final principal set..." |
---|
| 43 | for x in out[1]: |
---|
| 44 | print "%s " % x.string() |
---|
| 45 | out = ctxt.context_credentials() |
---|
| 46 | print "\n...final policy attribute set..." |
---|
| 47 | for c in out[1]: |
---|
| 48 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 49 | |
---|
| 50 | ########################################################################## |
---|
| 51 | # can john go to stadium at 1pm? |
---|
[7211a95] | 52 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T130000]) |
---|
| 53 | # p=[keyid:john] |
---|
| 54 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 55 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 56 | param3=ABAC.DataTerm("time", "20120228T130000") |
---|
| 57 | role = ABAC.Role(league,"stadium") |
---|
| 58 | role.role_add_data_term(param1) |
---|
| 59 | role.role_add_data_term(param2) |
---|
| 60 | role.role_add_data_term(param3) |
---|
| 61 | p=ABAC.Role(john) |
---|
| 62 | print "\n===good============ league.stadium(access,true,20120128T130000)<-?-john" |
---|
| 63 | out = ctxt.query(role, p) |
---|
| 64 | for c in out[1]: |
---|
| 65 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 66 | |
---|
| 67 | ########################################################################## |
---|
[f824a9e] | 68 | # can mark go to stadium at 11am? |
---|
[7211a95] | 69 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T110000]) |
---|
| 70 | # p=[keyid:mark] |
---|
| 71 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 72 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 73 | param3=ABAC.DataTerm("time", "20120228T110000") |
---|
| 74 | role = ABAC.Role(league,"stadium") |
---|
| 75 | role.role_add_data_term(param1) |
---|
| 76 | role.role_add_data_term(param2) |
---|
| 77 | role.role_add_data_term(param3) |
---|
| 78 | p=ABAC.Role(mark) |
---|
| 79 | print "\n===bad============ league.stadium(access,true,20120128T110000)<-?-mark" |
---|
| 80 | out = ctxt.query(role, p) |
---|
| 81 | for c in out[1]: |
---|
| 82 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|
| 83 | |
---|
| 84 | ########################################################################## |
---|
[f824a9e] | 85 | # can mark go to stadium at 8am then? |
---|
[7211a95] | 86 | # role=[keyid:league].role:stadium([string:'access'],[boolean:true],[time:20120228T080000]) |
---|
| 87 | # p=[keyid:mark] |
---|
| 88 | param1=ABAC.DataTerm("string", "'access'") |
---|
| 89 | param2=ABAC.DataTerm("boolean", "true") |
---|
| 90 | param3=ABAC.DataTerm("time", "20120228T080000") |
---|
| 91 | role = ABAC.Role(league,"stadium") |
---|
| 92 | role.role_add_data_term(param1) |
---|
| 93 | role.role_add_data_term(param2) |
---|
| 94 | role.role_add_data_term(param3) |
---|
| 95 | p=ABAC.Role(mark) |
---|
| 96 | print "\n===good============ league.stadium(access,true,20120128T080000)<-?-mark" |
---|
| 97 | out = ctxt.query(role, p) |
---|
| 98 | for c in out[1]: |
---|
| 99 | print "%s <- %s" % (c.head_string(), c.tail_string()) |
---|