#!/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 alphaID=ABAC.ID("Alpha_ID.pem"); alphaID.id_load_privkey_file("Alpha_private.pem"); alpha=alphaID.id_keyid() bobID=ABAC.ID("Bob_ID.pem"); bobID.id_load_privkey_file("Bob_private.pem"); bob=bobID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem"); maryannID.id_load_privkey_file("Maryann_private.pem"); maryann=maryannID.id_keyid() joeID=ABAC.ID("Joe_ID.pem"); joeID.id_load_privkey_file("Joe_private.pem"); joe=joeID.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 Joe getting a pay raise ? # role=[keyid:alpha].role:payRaise # p=[keyid:Joe] role = ABAC.Role(alpha,"payRaise") p = ABAC.Role(joe) print "\n===bad============ alpha.payRaise <- Joe" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # Is Maryann getting a pay raise ? # role=[keyid:alpha].role:payRaise # p=[keyid:Maryann] role = ABAC.Role(alpha,"payRaise") p = ABAC.Role(maryann) print "\n===good============ alpha.payRaise <- Maryann" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## #ctxt.dump_yap_db()