source: java/GraphTest.java @ 0595372

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

Some cleanup

  • 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.Role;
9import net.deterlab.abac.Identity;
10
11import java.security.KeyPair;
12
13
14/**
15 * Simple test of the native Java implementation of ABAC. Loads credentials
16 * from an rt0 file and runs a query against them.
17 */
18public class GraphTest {
19    public static void main(String[] args) throws IOException {
20        if (args.length < 3) {
21            System.out.println("Usage: GraphTest <files> <role> <principal>");
22            System.out.println("    runs the query role <-?- principal and prints the result");
23            System.exit(1);
24        }
25
26        Context ctxt = new Context();
27        Map<String, Exception> errs = new HashMap<String, Exception>();
28
29        for (int i= 0; i < args.length-2; i++) {
30            File f = new File(args[i]);
31
32            try {
33                if (f.isDirectory()) 
34                    ctxt.readDirectory(f, errs);
35                else if (f.getPath().endsWith(".pem")) 
36                    ctxt.loadIDFile(f);
37                else if (f.getPath().endsWith(".der"))
38                    ctxt.loadAttributeFile(f);
39                else if (f.getPath().endsWith(".zip"))
40                    ctxt.readZipFile(f, errs);
41                else
42                    System.out.println(f + " of unknown type");
43            }
44            catch (Exception e) {
45                System.err.println("Failed to process " + f + ": " +e);
46            }
47        }
48
49        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
50
51        //
52        // run the query
53        //
54
55        Role role = new Role(args[args.length-2], ctxt);
56        Role prin = new Role(args[args.length-1], ctxt);
57        Collection<Credential> ret = ctxt.query(role.toString(), prin.toString());
58        Set<Identity> ids = new TreeSet<Identity>();
59
60        String fn = "attr";
61        int n = 0;
62        String suf = ".der";
63        for (Credential c : ret) {
64            System.out.println(c.simpleString(ctxt));
65            if ( c.hasCertificate()) {
66                c.write(fn + n++ + suf);
67                ids.add(c.getID());
68            }
69        }
70
71        fn = "id";
72        n = 0;
73        suf = ".pem";
74        for (Identity i: ids) {
75            System.out.println("ID: " + i);
76            i.write(fn + n++ + suf);
77        }
78        ctxt.writeZipFile(new File("./testout.zip"), true, true);
79    }
80}
Note: See TracBrowser for help on using the repository browser.