source: java/GraphTest.java @ f0ae3d8

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since f0ae3d8 was f0ae3d8, checked in by Ted Faber <faber@…>, 13 years ago

Whoops, forgot to remove.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1import java.io.*;
2import java.util.*;
3
4import edu.uci.ics.jung.graph.*;
5
6import net.deterlab.abac.Credential;
7import net.deterlab.abac.CredentialGraph;
8import net.deterlab.abac.Query;
9import net.deterlab.abac.Role;
10import net.deterlab.abac.Identity;
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 GraphTest {
20    public static void main(String[] args) throws IOException {
21        if (args.length < 3) {
22            System.out.println("Usage: GraphTest <files> <role> <principal>");
23            System.out.println("    runs the query role <-?- principal and prints the result");
24            System.exit(1);
25        }
26
27        CredentialGraph graph = new CredentialGraph();
28        Vector<KeyPair> kp = new Vector<KeyPair>();
29        Map<String, Exception> errs = new HashMap<String, Exception>();
30
31        for (int i= 0; i < args.length-2; i++) {
32            File f = new File(args[i]);
33
34            try {
35                if (f.isDirectory()) 
36                    for (Credential c :Credential.readDirectory(f, kp, errs)) 
37                        graph.add_credential(c);
38                else if (f.getPath().endsWith(".pem")) 
39                    Credential.addIdentity(new Identity(f));
40                else if (f.getPath().endsWith(".der"))
41                    graph.add_credential(new Credential(f));
42                else if (f.getPath().endsWith(".zip"))
43                    for (Credential c :Credential.readZipFile(f, kp, errs)) 
44                        graph.add_credential(c);
45                else
46                    System.out.println(f + " of unknown type");
47            }
48            catch (Exception e) {
49                System.err.println("Failed to process " + f + ": " +e);
50            }
51        }
52
53        for (KeyPair k: kp) System.err.println(k);
54        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
55
56        //
57        // run the query
58        //
59
60        Role role = new Role(args[args.length-2], true);
61        Role prin = new Role(args[args.length-1], true);
62        Query q = graph.querier();
63        Graph<Role, Credential> ret = q.run(role.toString(), prin.toString());
64        String fn = "attr";
65        int n = 0;
66        String suf = ".der";
67        for (Credential c : ret.getEdges()) {
68            System.out.println(c.simpleString());
69            if ( c.hasCertificate()) c.write(fn + n++ + suf);
70        }
71
72        fn = "id";
73        n = 0;
74        suf = ".pem";
75        for (Identity i: Credential.identities()) {
76            System.out.println("ID: " + i);
77            i.write(fn + n++ + suf);
78        }
79        Credential.writeZipFile(graph.credentials(), 
80                new File("./testout.zip"), true);
81    }
82}
Note: See TracBrowser for help on using the repository browser.