source: java/GraphTest.java @ 65dbf06

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

Parses either

  • Property mode set to 100644
File size: 2.8 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.CredentialFactory;
8import net.deterlab.abac.Context;
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        /* Set up to parse XML or X509 (XML first) */
22        try {
23            CredentialFactory.registerClass("net.deterlab.abac.GENICredential");
24            CredentialFactory.registerClass("net.deterlab.abac.X509Credential");
25        }
26        catch (Exception e) {
27            e.printStackTrace();
28            System.exit(20);
29        }
30
31        if (args.length < 3) {
32            System.out.println("Usage: GraphTest <files> <role> <principal>");
33            System.out.println("    runs the query role <-?- principal and prints the result");
34            System.exit(1);
35        }
36
37        Context ctxt = new Context();
38        Map<String, Exception> errs = new HashMap<String, Exception>();
39
40        for (int i= 0; i < args.length-2; i++) {
41            File f = new File(args[i]);
42
43            try {
44                if (f.isDirectory()) 
45                    ctxt.load_directory(f, errs);
46                else if (f.getPath().endsWith(".pem")) 
47                    ctxt.load_id_file(f);
48                else if (f.getPath().endsWith(".der"))
49                    ctxt.load_attribute_file(f);
50                else if (f.getPath().endsWith(".zip"))
51                    ctxt.load_zip(f, errs);
52                else if (f.getPath().endsWith(".rt0"))
53                    ctxt.load_rt0(f);
54                else
55                    System.out.println(f + " of unknown type");
56            }
57            catch (Exception e) {
58                System.err.println("Failed to process " + f + ": " +e);
59            }
60        }
61
62        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
63
64        //
65        // run the query
66        //
67
68        Role role = new Role(args[args.length-2], ctxt);
69        Role prin = new Role(args[args.length-1], ctxt);
70        Context.QueryResult ret = ctxt.query(role.toString(), prin.toString());
71        Set<Identity> ids = new TreeSet<Identity>();
72
73        String fn = "attr";
74        int n = 0;
75        String suf = ".der";
76        System.out.println("Result: " + ret.getSuccess());
77        System.out.println("Proof");
78        for (Credential c : ret.getCredentials()) {
79            System.out.println(c.simpleString(ctxt));
80            if ( c.hasCertificate()) {
81                c.write(fn + n++ + suf);
82                ids.add(c.issuer());
83            }
84        }
85
86        fn = "id";
87        n = 0;
88        suf = ".pem";
89        System.out.println("Identities");
90        for (Identity i: ids) {
91            System.out.println("ID: " + i);
92            i.write(fn + n++ + suf);
93        }
94        try {
95            ctxt.write_zip(new File("./testout.zip"), true, true);
96        }
97        catch (IOException ioe) {
98            System.err.println("Could not write ZIP: " + ioe);
99        }
100        System.out.println("rt0 with keyids");
101        ctxt.write_rt0(new OutputStreamWriter(System.out), true);
102    }
103}
Note: See TracBrowser for help on using the repository browser.