source: examples/python_tests/basic_attribute/attr.py @ af8e9b9

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since af8e9b9 was be6cb41, checked in by Mei <mei@…>, 12 years ago

1) forgot to add the new files

  • Property mode set to 100755
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./attr.py
7
8"""
9
10import os
11import ABAC
12
13ctxt = ABAC.Context()
14
15def print_a(ctxt, msg, dotdot):
16    print "%s rule set..." % msg
17    credentials = ctxt.credentials()
18    for credential in credentials:
19        print "%s:%s<-%s" % (dotdot,credential.head().string(), credential.tail().string())
20
21# Keystore is the directory containing the principal credentials.
22# Load existing principals and/or policy credentials
23if (os.environ.has_key("keystore")) :
24    keystore=os.environ["keystore"]
25else:
26    print("keystore is not set...")
27    exit(1) 
28
29superKID=ABAC.ID("SuperK_ID.pem");
30superKID.load_privkey("SuperK_private.pem");
31ctxt.load_id_chunk(superKID.cert_chunk())
32superK=superKID.keyid()
33
34jackID=ABAC.ID("Jack_ID.pem");
35jackID.load_privkey("Jack_private.pem");
36ctxt.load_id_chunk(jackID.cert_chunk())
37jack=jackID.keyid()
38
39bobID=ABAC.ID("Bob_ID.pem");
40bobID.load_privkey("Bob_private.pem");
41ctxt.load_id_chunk(bobID.cert_chunk())
42bob=bobID.keyid()
43
44maryID=ABAC.ID("Mary_ID.pem");
45maryID.load_privkey("Mary_private.pem");
46ctxt.load_id_chunk(maryID.cert_chunk())
47mary=maryID.keyid()
48
49#case 1:
50#Only employee of SuperK can park
51#[keyid:SuperK].role:park <- [keyid:SuperK].role:employee
52attr = ABAC.Attribute(superKID, "park", 0)
53attr.role(superK,"employee")
54attr.bake()
55attr.write_file("SuperK_park__SuperK_employee_attr.xml")
56ctxt.load_attribute_file("SuperK_park__SuperK_employee_attr.xml")
57print_a(ctxt,"case1","..")
58
59#case 2:
60#Jack is an employee of SuperK
61#[keyid:SuperK].role:employee <- [keyid:Jack]
62attr = ABAC.Attribute(superKID, "employee", 0)
63attr.principal(jack)
64attr.bake()
65# create a policy file at the file system
66attr.write_file("SuperK_employee__Jack_attr.xml")
67ctxt.load_attribute_chunk(attr.cert_chunk());
68print_a(ctxt,"case2","....")
69
70#case 3:
71#Bob is an employee of SuperK
72#[keyid:SuperK].role:employee <- [keyid:Jack]
73attr = ABAC.Attribute(superKID, "employee", 0)
74attr.principal(bob)
75attr.bake()
76#chunk=attr.cert_chunk()
77#nattr=ABAC.Attribute_chunk(chunk)
78#ctxt.load_attribute(nattr);
79#print_a(ctxt,"case3", "....")
80
81#case 4:
82#Mary is an employee of SuperK
83#[keyid:SuperK].role:employee <- [keyid:Mary]
84attr = ABAC.Attribute(superKID, "employee", 0)
85attr.principal(mary)
86attr.bake()
87chunk=attr.cert_chunk()
88ctxt.load_attribute_chunk(chunk);
89print_a(ctxt,"case4","......")
Note: See TracBrowser for help on using the repository browser.