1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import edu.uci.ics.jung.graph.*; |
---|
5 | |
---|
6 | import net.deterlab.abac.Role; |
---|
7 | import net.deterlab.abac.Identity; |
---|
8 | import net.deterlab.abac.Credential; |
---|
9 | import net.deterlab.abac.CredentialFactory; |
---|
10 | import net.deterlab.abac.GENICredential; |
---|
11 | |
---|
12 | import java.security.KeyPair; |
---|
13 | |
---|
14 | |
---|
15 | /** |
---|
16 | * Simple test of the native Java implementation of ABAC. Loads credentials |
---|
17 | * from an rt0 file and runs a query against them. |
---|
18 | */ |
---|
19 | public class XMLExample { |
---|
20 | |
---|
21 | public static void writeCombinedIdentity(Identity i) throws IOException, FileNotFoundException { |
---|
22 | FileOutputStream f = new FileOutputStream(new File("./example/" + |
---|
23 | i.getName() + ".pem")); |
---|
24 | |
---|
25 | i.write(f); |
---|
26 | i.writePrivateKey(f); |
---|
27 | } |
---|
28 | public static void main(String[] args) throws IOException { |
---|
29 | try { |
---|
30 | Identity acme = new Identity("Acme"); |
---|
31 | Identity globotron = new Identity("Globotron"); |
---|
32 | Identity alice = new Identity("Alice"); |
---|
33 | Identity bob = new Identity("Bob"); |
---|
34 | Vector<Identity> ids = new Vector<Identity>(); |
---|
35 | Vector<Credential> creds = new Vector<Credential>(); |
---|
36 | Collections.addAll(ids, acme, globotron, alice, bob); |
---|
37 | |
---|
38 | for ( Identity i: ids) |
---|
39 | writeCombinedIdentity(i); |
---|
40 | |
---|
41 | |
---|
42 | GENICredential c = new GENICredential( |
---|
43 | new Role(acme.getKeyID() + ".experiment_create"), |
---|
44 | new Role(acme.getKeyID() + ".partner.experiment_create")); |
---|
45 | c.make_cert(acme); |
---|
46 | creds.add(c); |
---|
47 | c = new GENICredential( |
---|
48 | new Role(acme.getKeyID() + ".partner"), |
---|
49 | new Role(globotron.getKeyID())); |
---|
50 | c.make_cert(acme); |
---|
51 | creds.add(c); |
---|
52 | c = new GENICredential( |
---|
53 | new Role(globotron.getKeyID() + ".experiment_create"), |
---|
54 | new Role(globotron.getKeyID() + ".admin.power_user")); |
---|
55 | c.make_cert(globotron); |
---|
56 | creds.add(c); |
---|
57 | c = new GENICredential( |
---|
58 | new Role(globotron.getKeyID() + ".admin"), |
---|
59 | new Role(alice.getKeyID())); |
---|
60 | c.make_cert(globotron); |
---|
61 | creds.add(c); |
---|
62 | c = new GENICredential( |
---|
63 | new Role(alice.getKeyID() + ".power_user"), |
---|
64 | new Role(bob.getKeyID())); |
---|
65 | c.make_cert(alice); |
---|
66 | creds.add(c); |
---|
67 | |
---|
68 | int i =0; |
---|
69 | for (Credential cc: creds) { |
---|
70 | cc.write("./example/e" + i + ".xml"); |
---|
71 | i ++; |
---|
72 | } |
---|
73 | |
---|
74 | } |
---|
75 | catch (Exception e) { |
---|
76 | e.printStackTrace(); |
---|
77 | } |
---|
78 | |
---|
79 | } |
---|
80 | } |
---|