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

mei_rt2
Last change on this file since 2e9455f was 46df1bc, checked in by Mei <mei@…>, 11 years ago

1) get ready for release 0.2.3
2) add forward function declaration in abac_pl_yap.c for

abac_credential_dup

3) tested against freebsd82 and freebsd91

  • 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#ctxt.dump_yap_db()
27
28# retrieve principals' keyid value from local credential files
29acmeID=ABAC.ID("Acme_ID.pem");
30acmeID.id_load_privkey_file("Acme_private.pem");
31acme=acmeID.id_keyid()
32
33bobID=ABAC.ID("Bob_ID.pem");
34bobID.id_load_privkey_file("Bob_private.pem");
35bob=bobID.id_keyid()
36
37aliceID=ABAC.ID("Alice_ID.pem");
38aliceID.id_load_privkey_file("Alice_private.pem");
39alice=aliceID.id_keyid()
40
41globotronID=ABAC.ID("Globotron_ID.pem");
42globotronID.id_load_privkey_file("Globotron_private.pem");
43globotron=globotronID.id_keyid()
44
45##########################################################################
46# dump the loaded principals/policies
47#
48out = ctxt.context_principals()
49print "\n...final principal set..."
50for x in out[1]:
51    print "%s " % x.string()
52out = ctxt.context_credentials()
53print "\n...final policy attribute set..."
54for c in out[1]:
55    print "%s <- %s" % (c.head_string(), c.tail_string())
56
57##########################################################################
58# is alice a admin at Globotron ?
59# role=[keyid:Globotron].role:admin
60# p=[keyid:Alice]
61role = ABAC.Role(globotron,"admin")
62p = ABAC.Role(alice)
63print "\n===good=============== Globotron.admin <- Alice"
64out = ctxt.query(role, p)
65for c in out[1]:
66    print "%s <- %s" % (c.head_string(), c.tail_string())
67
68##########################################################################
69# is bob a admin at Globotron ?
70# role=[keyid:Globotron].role:admin
71# p=[keyid:Bob]
72role = ABAC.Role(globotron,"admin")
73p = ABAC.Role(bob)
74print "\n===bad=============== Globotron.admin <- Bob"
75out = ctxt.query(role, p)
76for c in out[1]:
77    print "%s <- %s" % (c.head_string(), c.tail_string())
78
79
80##########################################################################
81# can bob create experiment at Acme ?
82# role=[keyid:Acme].role:experiment_create
83# p=[keyid:Bob]
84role = ABAC.Role(acme,"experiment_create")
85p = ABAC.Role(bob)
86print "\n===good=============== Acme.experiment_create <- Bob"
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.