source: examples/python_tests/evaluator_rt1/query.py @ c6d5da3

mei_rt2mei_rt2_fix_1
Last change on this file since c6d5da3 was f824a9e, checked in by Mei <mei@…>, 13 years ago

1) add more doc to python_tests

  • Property mode set to 100755
File size: 2.6 KB
RevLine 
[5f551d3]1#!/usr/bin/env python
2
3"""
[f824a9e]4Run the queries described in README
[5f551d3]5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
[f824a9e]16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set...")
23    exit(1)
[5f551d3]24
[f824a9e]25# retrieve principals' keyid value from local credential files
[5f551d3]26isiID=ABAC.ID("ISI_ID.pem")
27isiID.id_load_privkey_file("ISI_private.pem");
28isi=isiID.id_keyid()
29
30uscID=ABAC.ID("USC_ID.pem")
31uscID.id_load_privkey_file("USC_private.pem");
32usc=uscID.id_keyid()
33
34maryannID=ABAC.ID("Maryann_ID.pem")
35maryannID.id_load_privkey_file("Maryann_private.pem");
36maryann=maryannID.id_keyid()
37
38johnID=ABAC.ID("John_ID.pem")
39johnID.id_load_privkey_file("John_private.pem");
40john=johnID.id_keyid()
41
42##########################################################################
[f824a9e]43# dump the loaded principals/policies
44#
45out = ctxt.context_principals()
46print "\n...final principal set..."
47for x in out[1]:
48    print "%s " % x.string()
49out = ctxt.context_credentials()
50print "\n...final policy attribute set..."
51for c in out[1]:
52    print "%s <- %s" % (c.head_string(), c.tail_string())
53
54##########################################################################
55# is john an evaluator of maryann ?
[5f551d3]56#role=[keyid:USC].role:evaluatorOf([keyid:Maryann])
57#p=[keyid:John]
58param=ABAC.DataTerm(maryannID)
59role = ABAC.Role(usc,"evaluatorOf")
60role.role_add_data_term(param)
61p = ABAC.Role(john)
62print "\n===good============ USC.evaluatorOf(Maryann) <- John"
63out = ctxt.query(role, p)
64for c in out[1]:
65    print "%s <- %s" % (c.head_string(), c.tail_string())
66
67##########################################################################
[f824a9e]68# is john a manager of maryann ?
[5f551d3]69#role=[keyid:USC].role:managerOf([keyid:Maryann])
70#p=[keyid:John]
71param=ABAC.DataTerm(maryannID)
72role = ABAC.Role(usc,"managerOf")
73role.role_add_data_term(param)
74p = ABAC.Role(john)
75print "\n===good============ USC.managerOf(Maryann) <- John"
76out = ctxt.query(role, p)
77for c in out[1]:
78    print "%s <- %s" % (c.head_string(), c.tail_string())
79
80##########################################################################
[f824a9e]81# is john an employee of usc ?
[5f551d3]82# role=[keyid:USC].role:employee
83# p=[keyid:John]"
84role = ABAC.Role(usc,"employee")
85p = ABAC.Role(john)
86print "\n===good============  USC.employee <-?- John"
87out = ctxt.query(role,p)
88for c in out[1]:
89    print "%s <- %s" % (c.head_string(), c.tail_string())
Note: See TracBrowser for help on using the repository browser.