source: examples/python_tests/acme_friend_rt1/attr.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.6 KB
Line 
1#!/usr/bin/env python
2
3"""
4  Setup access policy attribute rules
5
6cmd1:env keystore=`pwd` ./attr.py
7
8"""
9
10import os
11import ABAC
12
13keystore=os.environ["keystore"]
14
15ctxt = ABAC.Context()
16print "ABAC version %s" % ctxt.version()
17
18ctxt.load_directory(keystore)
19
20out = ctxt.context_principals()
21print "...initial principal set..."
22for x in out[1]:
23    print "%s " % x.string()
24print "\n" 
25
26out = ctxt.context_credentials()
27print "...initial policy attribute set..."
28for c in out[1]:
29    print "%s <- %s" % (c.head_string(), c.tail_string())
30print "\n"
31
32acmeID=ABAC.ID("Acme_ID.pem")
33acmeID.id_load_privkey_file("Acme_private.pem");
34acme=acmeID.id_keyid()
35
36coyoteID=ABAC.ID("Coyote_ID.pem")
37coyoteID.id_load_privkey_file("Coyote_private.pem");
38coyote=coyoteID.id_keyid()
39
40roadrunnerID=ABAC.ID("Roadrunner_ID.pem")
41roadrunnerID.id_load_privkey_file("Roadrunner_private.pem");
42roadrunner=roadrunnerID.id_keyid()
43
44jackrabbitID=ABAC.ID("Jackrabbit_ID.pem")
45jackrabbitID.id_load_privkey_file("Jackrabbit_private.pem");
46jackrabbit=jackrabbitID.id_keyid()
47
48################################################
49# [keyid:Acme].role:preferred_customer <- [keyid:Acme].role:friendof([keyid:Roadrunner])
50head = ABAC.Role(acme,"preferred_customer")
51param=ABAC.DataTerm(roadrunnerID)
52tail = ABAC.Role(acme,"friendof")
53tail.role_add_data_term(param)
54attr=ABAC.Attribute(head, 1800)
55attr.attribute_add_tail(tail)
56attr.attribute_bake()
57attr.attribute_write_cert("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der")
58ctxt.load_attribute_file("Acme_preferred_customer__Acme_friendof_Roadrunner_attr.der")
59print attr.string() 
60print attr.typed_string()
61print "\n"
62
63#################################################
64# [keyid:Acme].role:prefered_customer <- [keyid:Coyote]
65head = ABAC.Role(acme,"preferred_customer")
66tail = ABAC.Role(coyote)
67attr=ABAC.Attribute(head, 1800)
68attr.attribute_add_tail(tail)
69attr.attribute_bake()
70attr.attribute_write_cert("Acme_preferred_customer__Coyote_attr.der")
71ctxt.load_attribute_file("Acme_preferred_customer__Coyote_attr.der")
72print attr.string() 
73print attr.typed_string()
74print "\n"
75
76#################################################
77# [keyid:Acme].role:friendof([keyid:Roadrunner]) <- [keyid:Jackrabbit]
78param=ABAC.DataTerm(roadrunnerID)
79head = ABAC.Role(acme,"friendof")
80head.role_add_data_term(param)
81tail = ABAC.Role(jackrabbit)
82attr=ABAC.Attribute(head, 1800)
83attr.attribute_add_tail(tail)
84attr.attribute_bake()
85attr.attribute_write_cert("Acme_friendof_Roadrunner__Jackrabbit_attr.der")
86ctxt.load_attribute_file("Acme_friendof_Roadrunner__Jackrabbit_attr.der")
87print attr.string() 
88print attr.typed_string()
89print "\n"
90
91ctxt.dump_yap_db()
92##
Note: See TracBrowser for help on using the repository browser.