source: examples/python_tests/experiment_multi_rt0/query.py @ a7f03f3

mei_rt2mei_rt2_fix_1
Last change on this file since a7f03f3 was abf8d5d, checked in by Mei <mei@…>, 12 years ago

1) add backtrack/multiple solutions proof code changes and new

examples.

  • Property mode set to 100755
File size: 2.0 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()
15
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)
24
25# retrieve principals' keyid value from local credential files
26acmeID=ABAC.ID("Acme_ID.pem");
27acmeID.id_load_privkey_file("Acme_private.pem");
28acme=acmeID.id_keyid()
29
30bobID=ABAC.ID("Bob_ID.pem");
31bobID.id_load_privkey_file("Bob_private.pem");
32bob=bobID.id_keyid()
33
34aliceID=ABAC.ID("Alice_ID.pem");
35aliceID.id_load_privkey_file("Alice_private.pem");
36alice=aliceID.id_keyid()
37
38globotronID=ABAC.ID("Globotron_ID.pem");
39globotronID.id_load_privkey_file("Globotron_private.pem");
40globotron=globotronID.id_keyid()
41
42##########################################################################
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
54def get_next(ctxt) :
55    next=1
56    while( next ) :
57        out = ctxt.next_proof()
58        print ("\nnext proof:")
59        for c in out[1]:
60            print "%s <- %s" % (c.head_string(), c.tail_string())
61        else:
62            next=0
63            print("no more..\n")
64
65##########################################################################
66# can bob create experiment at Acme ?
67# role=[keyid:Acme].role:experiment_create
68# p=[keyid:Bob]
69role = ABAC.Role(acme,"experiment_create")
70p = ABAC.Role(bob)
71print "\n===good=============== Acme.experiment_create <- Bob"
72out = ctxt.query(role, p)
73for c in out[1]:
74    print "%s <- %s" % (c.head_string(), c.tail_string())
75get_next(ctxt)
76
Note: See TracBrowser for help on using the repository browser.