source: java/GraphTest.java @ 84f0e7a

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

Initial run at unifying the interface.

  • Property mode set to 100644
File size: 2.1 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.Context;
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        Context ctxt = new Context();
28        Map<String, Exception> errs = new HashMap<String, Exception>();
29
30        for (int i= 0; i < args.length-2; i++) {
31            File f = new File(args[i]);
32
33            try {
34                if (f.isDirectory()) 
35                    ctxt.readDirectory(f, errs);
36                else if (f.getPath().endsWith(".pem")) 
37                    ctxt.loadIDFile(f);
38                else if (f.getPath().endsWith(".der"))
39                    ctxt.loadAttributeFile(f);
40                else if (f.getPath().endsWith(".zip"))
41                    ctxt.readZipFile(f, errs);
42                else
43                    System.out.println(f + " of unknown type");
44            }
45            catch (Exception e) {
46                System.err.println("Failed to process " + f + ": " +e);
47            }
48        }
49
50        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
51
52        //
53        // run the query
54        //
55
56        Role role = new Role(args[args.length-2], ctxt);
57        Role prin = new Role(args[args.length-1], ctxt);
58        Collection<Credential> ret = ctxt.query(role.toString(), prin.toString());
59        Set<Identity> ids = new TreeSet<Identity>();
60
61        String fn = "attr";
62        int n = 0;
63        String suf = ".der";
64        for (Credential c : ret) {
65            System.out.println(c.simpleString(ctxt));
66            if ( c.hasCertificate()) {
67                c.write(fn + n++ + suf);
68                ids.add(c.getID());
69            }
70        }
71
72        fn = "id";
73        n = 0;
74        suf = ".pem";
75        for (Identity i: ids) {
76            System.out.println("ID: " + i);
77            i.write(fn + n++ + suf);
78        }
79        ctxt.writeZipFile(new File("./testout.zip"), true, true);
80    }
81}
Note: See TracBrowser for help on using the repository browser.