source: examples/python_tests/access_rt2/query.py @ 7211a95

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

1) add more python examples
2) add the missing linking role and linking oset api calls
3) fix the output of time typed data term/oset obj in typed_string format

(transform back from yap time format to our ddddddddTdddddd format

  • Property mode set to 100755
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
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# print "ABAC version %s" % ctxt.version()
17
18keystore=os.environ["keystore"]
19
20ctxt.load_directory(keystore)
21
22alphaID=ABAC.ID("Alpha_ID.pem");
23alphaID.id_load_privkey_file("Alpha_private.pem");
24#ctxt.load_id(alphaID)
25alpha=alphaID.id_keyid()
26
27bobID=ABAC.ID("Bob_ID.pem");
28bobID.id_load_privkey_file("Bob_private.pem");
29#ctxt.load_id(bobID)
30bob=bobID.id_keyid()
31
32joeID=ABAC.ID("Joe_ID.pem");
33joeID.id_load_privkey_file("Joe_private.pem");
34joe=joeID.id_keyid()
35
36##########################################################################
37# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
38# p = "[keyid:bob]"
39param1=ABAC.DataTerm("string", "'Read'")
40param2=ABAC.DataTerm("urn","'file//fileA'")
41role = ABAC.Role(alpha,"access")
42role.role_add_data_term(param1)
43role.role_add_data_term(param2)
44p = ABAC.Role(bob)
45
46print "\n===good============ Alpha.access(Read,fileA)<-?-Bob"
47out = ctxt.query(role, p)
48
49for c in out[1]:
50    print "%s <- %s" % (c.head_string(), c.tail_string())
51
52##########################################################################
53# role =[keyid:alpha].role:access([string:'Read'],[urn:'file//fileA'])
54# p = "[keyid:joe]"
55param1=ABAC.DataTerm("string", "'Read'")
56param2=ABAC.DataTerm("urn","'file//fileA'")
57role = ABAC.Role(alpha,"access")
58role.role_add_data_term(param1)
59role.role_add_data_term(param2)
60p = ABAC.Role(joe)
61
62print "\n===bad============ Alpha.access(Read,fileA)<-?-Joe"
63out = ctxt.query(role,p)
64
65for c in out[1]:
66    print "%s <- %s" % (c.head_string(), c.tail_string())
67
68
69##########################################################################
70# role =[keyid:alpha].role:team([string:'proj2'])
71# p = "[keyid:joe]"
72param=ABAC.DataTerm("string", "'proj2'")
73role = ABAC.Role(alpha,"team")
74role.role_add_data_term(param)
75p = ABAC.Role(joe)
76print "\n===good============ Alpha.team(proj2)<-?-Joe"
77out = ctxt.query(role,p)
78
79for c in out[1]:
80    print "%s <- %s" % (c.head_string(), c.tail_string())
81
82
83##########################################################################
84# dump the loaded principals/policies
85#
86out = ctxt.context_principals()
87print "\n...final principal set..."
88for x in out[1]:
89    print "%s " % x.string()
90print "\n"
91out = ctxt.context_credentials()
92print "\n...final policy attribute set..."
93for c in out[1]:
94    print "%s <- %s" % (c.head_string(), c.tail_string())
95print "\n"
96
Note: See TracBrowser for help on using the repository browser.