#!/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 isiID=ABAC.ID("ISI_ID.pem") isiID.id_load_privkey_file("ISI_private.pem"); isi=isiID.id_keyid() uscID=ABAC.ID("USC_ID.pem") uscID.id_load_privkey_file("USC_private.pem"); usc=uscID.id_keyid() maryannID=ABAC.ID("Maryann_ID.pem") maryannID.id_load_privkey_file("Maryann_private.pem"); maryann=maryannID.id_keyid() johnID=ABAC.ID("John_ID.pem") johnID.id_load_privkey_file("John_private.pem"); john=johnID.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 john an evaluator of maryann ? #role=[keyid:USC].role:evaluatorOf([keyid:Maryann]) #p=[keyid:John] param=ABAC.DataTerm(maryannID) role = ABAC.Role(usc,"evaluatorOf") role.role_add_data_term(param) p = ABAC.Role(john) print "\n===good============ USC.evaluatorOf(Maryann) <- John" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # is john a manager of maryann ? #role=[keyid:USC].role:managerOf([keyid:Maryann]) #p=[keyid:John] param=ABAC.DataTerm(maryannID) role = ABAC.Role(usc,"managerOf") role.role_add_data_term(param) p = ABAC.Role(john) print "\n===good============ USC.managerOf(Maryann) <- John" out = ctxt.query(role, p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string()) ########################################################################## # is john an employee of usc ? # role=[keyid:USC].role:employee # p=[keyid:John]" role = ABAC.Role(usc,"employee") p = ABAC.Role(john) print "\n===good============ USC.employee <-?- John" out = ctxt.query(role,p) for c in out[1]: print "%s <- %s" % (c.head_string(), c.tail_string())