1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import edu.uci.ics.jung.graph.*; |
---|
5 | |
---|
6 | import net.deterlab.abac.Credential; |
---|
7 | import net.deterlab.abac.Context; |
---|
8 | import net.deterlab.abac.Role; |
---|
9 | import net.deterlab.abac.Identity; |
---|
10 | |
---|
11 | import 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 | */ |
---|
18 | public 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.load_directory(f, errs); |
---|
35 | else if (f.getPath().endsWith(".pem")) |
---|
36 | ctxt.load_id_file(f); |
---|
37 | else if (f.getPath().endsWith(".der")) |
---|
38 | ctxt.load_attribute_file(f); |
---|
39 | else if (f.getPath().endsWith(".zip")) |
---|
40 | ctxt.load_zip_file(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 | Context.QueryResult 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 | System.out.println("Result: " + ret.getSuccess()); |
---|
64 | for (Credential c : ret.getCredentials()) { |
---|
65 | System.out.println(c.simpleString(ctxt)); |
---|
66 | if ( c.hasCertificate()) { |
---|
67 | c.write(fn + n++ + suf); |
---|
68 | ids.add(c.issuer()); |
---|
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.write_zip_file(new File("./testout.zip"), true, true); |
---|
80 | } |
---|
81 | } |
---|