[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 | System.err.println("Trying " + args[i]); |
---|
| 32 | |
---|
| 33 | try { |
---|
| 34 | if (f.isDirectory()) |
---|
| 35 | ctxt.load_directory(f, errs); |
---|
| 36 | else if (f.getPath().endsWith(".pem")) |
---|
| 37 | ctxt.load_id_file(f); |
---|
| 38 | else if (f.getPath().endsWith(".der")) |
---|
| 39 | ctxt.load_attribute_file(f); |
---|
| 40 | else if (f.getPath().endsWith(".xml")) |
---|
| 41 | ctxt.load_attribute_file(f); |
---|
| 42 | else if (f.getPath().endsWith(".zip")) |
---|
| 43 | ctxt.load_zip(f, errs); |
---|
| 44 | else if (f.getPath().endsWith(".rt0")) |
---|
| 45 | ctxt.load_rt0(f); |
---|
| 46 | else |
---|
| 47 | System.out.println(f + " of unknown type"); |
---|
| 48 | } |
---|
| 49 | catch (Exception e) { |
---|
| 50 | System.err.println("Failed to process " + f + ": " +e); |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f)); |
---|
| 55 | |
---|
| 56 | // |
---|
| 57 | // run the query |
---|
| 58 | // |
---|
| 59 | |
---|
| 60 | System.out.println("Creds"); |
---|
| 61 | for (Credential c : ctxt.credentials()) { |
---|
| 62 | System.out.println(c.simpleString(ctxt)); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | } |
---|
| 66 | } |
---|