source: examples/python_tests/alumni2_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.5 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
27stateUID=ABAC.ID("StateU_ID.pem")
28stateUID.id_load_privkey_file("StateU_private.pem")
29stateU=stateUID.id_keyid()
30
31bobID=ABAC.ID("Bob_ID.pem")
32bobID.id_load_privkey_file("Bob_private.pem")
33bob=bobID.id_keyid()
34
35joeID=ABAC.ID("Joe_ID.pem")
36joeID.id_load_privkey_file("Joe_private.pem")
37joe=joeID.id_keyid()
38
39maryannID=ABAC.ID("Maryann_ID.pem")
40maryannID.id_load_privkey_file("Maryann_private.pem")
41maryann=maryannID.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 bob a founding alumni of stateU ?
57# role=[keyid:stateU].role:foundingAlumni
58# p=[keyid:Bob]
59role = ABAC.Role(stateU,"foundingAlumni")
60p = ABAC.Role(bob)
61print "\n===good============ stateU.foundingAlumni <- Bob"
62out = ctxt.query(role, p)
63for c in out[1]:
64    print "%s <- %s" % (c.head_string(), c.tail_string())
65
66##########################################################################
67# is maryann a founding alumni of stateU ?
68# role=[keyid:stateU].role:foundingAlumni
69# p=[keyid:Maryann]
70role = ABAC.Role(stateU,"foundingAlumni")
71p = ABAC.Role(maryann)
72print "\n===bad============ stateU.foundingAlumni <- Maryann"
73out = ctxt.query(role, p)
74for c in out[1]:
75    print "%s <- %s" % (c.head_string(), c.tail_string())
76
77##########################################################################
78# is joe a founding alumni of stateU ?
79# role=[keyid:stateU].role:foundingAlumni
80# p=[keyid:Joe]
81role = ABAC.Role(stateU,"foundingAlumni")
82p = ABAC.Role(joe)
83print "\n===bad============ stateU.foundingAlumni <- Joe"
84out = ctxt.query(role, p)
85for c in out[1]:
86    print "%s <- %s" % (c.head_string(), c.tail_string())
Note: See TracBrowser for help on using the repository browser.