source: examples/python_tests/alumni3_rt1/query.py @ 2e9455f

mei_rt2
Last change on this file since 2e9455f was 646e57e, checked in by Mei <mei@…>, 12 years ago

1) add partial proof

  • Property mode set to 100755
File size: 3.3 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
35markID=ABAC.ID("Mark_ID.pem")
36markID.id_load_privkey_file("Mark_private.pem")
37mark=markID.id_keyid()
38
39joeID=ABAC.ID("Joe_ID.pem")
40joeID.id_load_privkey_file("Joe_private.pem")
41joe=joeID.id_keyid()
42
43maryannID=ABAC.ID("Maryann_ID.pem")
44maryannID.id_load_privkey_file("Maryann_private.pem")
45maryann=maryannID.id_keyid()
46
47janID=ABAC.ID("Jan_ID.pem")
48janID.id_load_privkey_file("Jan_private.pem")
49jan=janID.id_keyid()
50
51##########################################################################
52# dump the loaded principals/policies
53#
54out = ctxt.context_principals()
55print "\n...final principal set..."
56for x in out[1]:
57    print "%s " % x.string()
58out = ctxt.context_credentials()
59print "\n...final policy attribute set..."
60for c in out[1]:
61    print "%s <- %s" % (c.head_string(), c.tail_string())
62
63##########################################################################
64# role=[keyid:stateU].role:foundingAlumni
65# p=[keyid:Bob]
66role = ABAC.Role(stateU,"foundingAlumni")
67p = ABAC.Role(bob)
68print "\n===good============ stateU.foundingAlumni <- Bob"
69out = ctxt.query(role, p)
70for c in out[1]:
71    print "%s <- %s" % (c.head_string(), c.tail_string())
72
73##########################################################################
74# role=[keyid:stateU].role:foundingAlumni
75# p=[keyid:Mark]
76role = ABAC.Role(stateU,"foundingAlumni")
77p = ABAC.Role(mark)
78print "\n===bad============ stateU.foundingAlumni <- Mark"
79out = ctxt.query(role, p)
80for c in out[1]:
81    print "%s <- %s" % (c.head_string(), c.tail_string())
82
83##########################################################################
84# role=[keyid:stateU].role:foundingAlumni
85# p=[keyid:Joe]
86role = ABAC.Role(stateU,"foundingAlumni")
87p = ABAC.Role(joe)
88print "\n===bad============ stateU.foundingAlumni <- Joe"
89out = ctxt.query(role, p)
90for c in out[1]:
91    print "%s <- %s" % (c.head_string(), c.tail_string())
92
93##########################################################################
94# role=[keyid:stateU].role:foundingAlumni
95# p=[keyid:Maryann]
96role = ABAC.Role(stateU,"foundingAlumni")
97p = ABAC.Role(maryann)
98print "\n===bad============ stateU.foundingAlumni <- Maryann"
99out = ctxt.query(role, p)
100for c in out[1]:
101    print "%s <- %s" % (c.head_string(), c.tail_string())
102
103##########################################################################
104# role=[keyid:stateU].role:foundingAlumni
105# p=[keyid:Jan]
106role = ABAC.Role(stateU,"foundingAlumni")
107p = ABAC.Role(jan)
108print "\n===good============ stateU.foundingAlumni <- Jan"
109out = ctxt.query(role, p)
110for c in out[1]:
111    print "%s <- %s" % (c.head_string(), c.tail_string())
112
Note: See TracBrowser for help on using the repository browser.