source: examples/python_tests/partial_proof_rt0/query.py @ 212e99f

mei_rt2mei_rt2_fix_1 libabac-0.2.2apre-partial
Last change on this file since 212e99f was a7f03f3, checked in by Mei <mei@…>, 12 years ago

1) add the new yap porting directory and some of code
2) add parital proof test code

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3"""
4cmd1:env keystore=`pwd` ./query.py
5cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
6
7"""
8
9import os
10import ABAC
11
12ctxt = ABAC.Context()
13
14# Keystore is the directory containing the principal credentials.
15# Load existing principals and/or policy credentials
16if (os.environ.has_key("keystore")) :
17    keystore=os.environ["keystore"]
18    ctxt.load_directory(keystore)
19else:
20    print("keystore is not set...")
21    exit(1)
22
23# retrieve principals' keyid value from local credential files
24acmeID=ABAC.ID("Acme_ID.pem");
25acme=acmeID.id_keyid()
26
27oshID=ABAC.ID("Osh_ID.pem");
28osh=oshID.id_keyid()
29
30coyoteID=ABAC.ID("Coyote_ID.pem");
31coyote=coyoteID.id_keyid()
32
33ladybugID=ABAC.ID("Ladybug_ID.pem");
34ladybug=ladybugID.id_keyid()
35
36##########################################################################
37# dump the loaded principals/policies
38#
39out = ctxt.context_principals()
40print "\n...final principal set..."
41for x in out[1]:
42    print "%s " % x.string()
43out = ctxt.context_credentials()
44print "\n...final policy attribute set..."
45for c in out[1]:
46    print "%s <- %s" % (c.head_string(), c.tail_string())
47
48##########################################################################
49# can coyote buy rockets from Acme ?
50# role=[keyid:Acme].role:buy_rockets
51# p =[keyid:coyote]
52role = ABAC.Role(acme,"buy_rockets")
53p = ABAC.Role(coyote)
54print "\n===good============ Acme.buy_rockets <- Coyote"
55out = ctxt.query(role, p)
56for c in out[1]:
57    print "%s <- %s" % (c.head_string(), c.tail_string())
58
59##########################################################################
60# can ladybug buy rockets from Acme ?
61# role=[keyid:Acme].role:buy_rockets
62# p =[keyid:ladybug]
63role = ABAC.Role(acme,"buy_rockets")
64p = ABAC.Role(ladybug)
65print "\n===bad============ Acme.buy_rockets <- Ladybug"
66out = ctxt.query(role, p)
67for c in out[1]:
68    print "%s <- %s" % (c.head_string(), c.tail_string())
69
70##########################################################################
71# can ladybug buy rockets from Osh ?
72# role=[keyid:Osh].role:buy_rockets
73# p =[keyid:ladybug]
74role = ABAC.Role(osh,"buy_rockets")
75p = ABAC.Role(ladybug)
76print "\n===good============ Osh.buy_rockets <- Ladybug"
77out = ctxt.query(role, p)
78for c in out[1]:
79    print "%s <- %s" % (c.head_string(), c.tail_string())
80
81
Note: See TracBrowser for help on using the repository browser.