[7f16578] | 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 Reader { |
---|
| 19 | public static void main(String[] args) throws IOException { |
---|
| 20 | if (args.length < 1) { |
---|
| 21 | System.out.println("Usage: Reader <files>"); |
---|
| 22 | System.out.println(" Reads the files and prints the credentials"); |
---|
| 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; 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(".xml")) |
---|
| 40 | ctxt.load_attribute_file(f); |
---|
| 41 | else if (f.getPath().endsWith(".zip")) |
---|
| 42 | ctxt.load_zip(f, errs); |
---|
| 43 | else if (f.getPath().endsWith(".rt0")) |
---|
| 44 | ctxt.load_rt0(f); |
---|
| 45 | else |
---|
| 46 | System.out.println(f + " of unknown type"); |
---|
| 47 | } |
---|
| 48 | catch (Exception e) { |
---|
| 49 | System.err.println("Failed to process " + f + ": " +e); |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f)); |
---|
| 54 | |
---|
| 55 | // |
---|
| 56 | // run the query |
---|
| 57 | // |
---|
| 58 | |
---|
| 59 | System.out.println("Creds"); |
---|
| 60 | for (Credential c : ctxt.credentials()) { |
---|
| 61 | System.out.println(c.simpleString(ctxt)); |
---|
[797bebe] | 62 | System.out.println(c); |
---|
[7f16578] | 63 | } |
---|
| 64 | |
---|
| 65 | } |
---|
| 66 | } |
---|