source: examples/python_tests/payraise_rt1/query.py @ 20eaefe

mei_rt2mei_rt2_fix_1
Last change on this file since 20eaefe was 646e57e, checked in by Mei <mei@…>, 12 years ago

1) add partial proof

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3"""
4Run the queries described in README
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()
15ctxt.set_no_partial_proof()
16
17# Keystore is the directory containing the principal credentials.
18# Load existing principals and/or policy credentials
19if (os.environ.has_key("keystore")) :
20    keystore=os.environ["keystore"]
21    ctxt.load_directory(keystore)
22else:
23    print("keystore is not set...")
24    exit(1)
25
26# retrieve principals' keyid value from local credential files
27alphaID=ABAC.ID("Alpha_ID.pem");
28alphaID.id_load_privkey_file("Alpha_private.pem");
29alpha=alphaID.id_keyid()
30
31bobID=ABAC.ID("Bob_ID.pem");
32bobID.id_load_privkey_file("Bob_private.pem");
33bob=bobID.id_keyid()
34
35maryannID=ABAC.ID("Maryann_ID.pem");
36maryannID.id_load_privkey_file("Maryann_private.pem");
37maryann=maryannID.id_keyid()
38
39joeID=ABAC.ID("Joe_ID.pem");
40joeID.id_load_privkey_file("Joe_private.pem");
41joe=joeID.id_keyid()
42
43##########################################################################
44# dump the loaded principals/policies
45#
46out = ctxt.context_principals()
47print "\n...final principal set..."
48for x in out[1]:
49    print "%s " % x.string()
50out = ctxt.context_credentials()
51print "\n...final policy attribute set..."
52for c in out[1]:
53    print "%s <- %s" % (c.head_string(), c.tail_string())
54
55##########################################################################
56# Is Joe getting a pay raise ?
57# role=[keyid:alpha].role:payRaise
58# p=[keyid:Joe]
59role = ABAC.Role(alpha,"payRaise")
60p = ABAC.Role(joe)
61print "\n===bad============ alpha.payRaise <- Joe"
62out = ctxt.query(role, p)
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66
67
68##########################################################################
69# Is Maryann getting a pay raise ?
70# role=[keyid:alpha].role:payRaise
71# p=[keyid:Maryann]
72role = ABAC.Role(alpha,"payRaise")
73p = ABAC.Role(maryann)
74print "\n===good============ alpha.payRaise <- Maryann"
75out = ctxt.query(role, p)
76for c in out[1]:
77    print "%s <- %s" % (c.head_string(), c.tail_string())
78
79
80##########################################################################
81#ctxt.dump_yap_db()
82
Note: See TracBrowser for help on using the repository browser.