source: java/XMLExample.java @ 4560b65

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since 4560b65 was 8ee55e7, checked in by Ted Faber <faber@…>, 11 years ago

Create example in GENI creds

  • Property mode set to 100644
File size: 2.3 KB
Line 
1import java.io.*;
2import java.util.*;
3
4import edu.uci.ics.jung.graph.*;
5
6import net.deterlab.abac.Role;
7import net.deterlab.abac.Identity;
8import net.deterlab.abac.Credential;
9import net.deterlab.abac.CredentialFactory;
10import net.deterlab.abac.GENICredential;
11
12import 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 */
19public 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            CredentialFactory.registerClass("net.deterlab.abac.GENICredential");
39
40            for ( Identity i: ids) 
41                writeCombinedIdentity(i);
42
43
44            GENICredential c = new GENICredential(
45                    new Role(acme.getKeyID() + ".experiment_create"),
46                    new Role(acme.getKeyID() + ".partner.experiment_create"));
47            c.make_cert(acme);
48            creds.add(c);
49            c = new GENICredential(
50                    new Role(acme.getKeyID() + ".partner"),
51                    new Role(globotron.getKeyID()));
52            c.make_cert(acme);
53            creds.add(c);
54            c = new GENICredential(
55                    new Role(globotron.getKeyID() + ".experiment_create"),
56                    new Role(globotron.getKeyID() + ".admin.power_user"));
57            c.make_cert(globotron);
58            creds.add(c);
59            c = new GENICredential(
60                    new Role(globotron.getKeyID() + ".admin"),
61                    new Role(alice.getKeyID()));
62            c.make_cert(globotron);
63            creds.add(c);
64            c = new GENICredential(
65                    new Role(alice.getKeyID() + ".power_user"),
66                    new Role(bob.getKeyID()));
67            c.make_cert(alice);
68            creds.add(c);
69
70            int i =0;
71            for (Credential cc: creds) {
72                cc.write("./example/e" + i + ".xml");
73                i ++;
74            }
75
76        }
77        catch (Exception e) {
78            e.printStackTrace();
79        }
80
81    }
82}
Note: See TracBrowser for help on using the repository browser.