1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import edu.uci.ics.jung.graph.*; |
---|
5 | |
---|
6 | import net.deterlab.abac.CredentialFactory; |
---|
7 | import net.deterlab.abac.Credential; |
---|
8 | import net.deterlab.abac.Context; |
---|
9 | import net.deterlab.abac.Role; |
---|
10 | import net.deterlab.abac.Identity; |
---|
11 | |
---|
12 | import 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 | */ |
---|
19 | public class Reader { |
---|
20 | public static void main(String[] args) throws IOException { |
---|
21 | if (args.length < 1) { |
---|
22 | System.out.println("Usage: Reader <files>"); |
---|
23 | System.out.println(" Reads the files and prints the credentials"); |
---|
24 | System.exit(1); |
---|
25 | } |
---|
26 | |
---|
27 | Context ctxt = new Context(); |
---|
28 | Map<String, Exception> errs = new HashMap<String, Exception>(); |
---|
29 | |
---|
30 | try { |
---|
31 | CredentialFactory cf = new CredentialFactory( |
---|
32 | new String[] { |
---|
33 | "net.deterlab.abac.X509Credential", |
---|
34 | "net.deterlab.abac.GENICredential" |
---|
35 | }); |
---|
36 | ctxt.setCredentialFactory(cf); |
---|
37 | } |
---|
38 | catch (Exception e) { |
---|
39 | System.exit(20); |
---|
40 | } |
---|
41 | |
---|
42 | for (int i= 0; i < args.length; i++) { |
---|
43 | File f = new File(args[i]); |
---|
44 | |
---|
45 | try { |
---|
46 | if (f.isDirectory()) |
---|
47 | ctxt.load_directory(f, errs); |
---|
48 | else if (f.getPath().endsWith(".pem")) |
---|
49 | ctxt.load_id_file(f); |
---|
50 | else if (f.getPath().endsWith(".der")) |
---|
51 | ctxt.load_attribute_file(f); |
---|
52 | else if (f.getPath().endsWith(".xml")) |
---|
53 | ctxt.load_attribute_file(f); |
---|
54 | else if (f.getPath().endsWith(".zip")) |
---|
55 | ctxt.load_zip(f, errs); |
---|
56 | else if (f.getPath().endsWith(".rt0")) |
---|
57 | ctxt.load_rt0(f); |
---|
58 | else |
---|
59 | System.out.println(f + " of unknown type"); |
---|
60 | } |
---|
61 | catch (Exception e) { |
---|
62 | System.err.println("Failed to process " + f + ": " +e); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f)); |
---|
67 | |
---|
68 | // |
---|
69 | // run the query |
---|
70 | // |
---|
71 | |
---|
72 | System.out.println("Creds"); |
---|
73 | for (Credential c : ctxt.credentials()) { |
---|
74 | System.out.println(c.simpleString(ctxt)); |
---|
75 | System.out.println(c); |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|
79 | } |
---|