#!/usr/bin/env python """ Run the queries described in README cmd1:env keystore=`pwd` ./query.py cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py """ import os import ABAC ctxt = ABAC.Context() # Keystore is the directory containing the principal credentials. # Load existing principals and/or policy credentials if (os.environ.has_key("keystore")) : keystore=os.environ["keystore"] ctxt.load_directory(keystore) else: print("keystore is not set...") exit(1) # retrieve principals' keyid value from local credential files stateUID=ABAC.ID("StateU_ID.pem") stateUID.id_load_privkey_file("StateU_private.pem") stateU=stateUID.id_keyid() bobID=ABAC.ID("Bob_ID.pem") bobID.id_load_privkey_file("Bob_private.pem") bob=bobID.id_keyid() joeID=ABAC.ID("Joe_ID.pem") joeID.id_load_privkey_file("Joe_private.pem") joe=joeID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem") maryannID.id_load_privkey_file("Maryann_private.pem") maryann=maryannID.id_keyid() ########################################################################## # dump the loaded principals/policies # out = ctxt.context_principals() print "\n...final principal set..." for x in out[1]: print "%s " % x.string() out = ctxt.context_credentials() print "\n...final policy attribute set..." for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # is bob a founding alumni of stateU ? # role=[keyid:stateU].role:foundingAlumni # p=[keyid:Bob] role = ABAC.Role(stateU,"foundingAlumni") p = ABAC.Role(bob) print "\n===bad============ stateU.foundingAlumni <- Bob" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # is maryann a founding alumni of stateU ? # role=[keyid:stateU].role:foundingAlumni # p=[keyid:Maryann] role = ABAC.Role(stateU,"foundingAlumni") p = ABAC.Role(maryann) print "\n===good============ stateU.foundingAlumni <- Maryann" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # is joe a founding alumni of stateU ? # role=[keyid:stateU].role:foundingAlumni # p=[keyid:Joe] role = ABAC.Role(stateU,"foundingAlumni") p = ABAC.Role(joe) print "\n===good============ stateU.foundingAlumni <- Joe" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string())