[7f16578] | 1 | import java.io.*; |
---|
| 2 | import java.util.*; |
---|
| 3 | |
---|
| 4 | import edu.uci.ics.jung.graph.*; |
---|
| 5 | |
---|
[3612811] | 6 | import net.deterlab.abac.CredentialFactory; |
---|
[7f16578] | 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 | |
---|
[3612811] | 30 | try { |
---|
| 31 | CredentialFactory.registerClass("net.deterlab.abac.X509Credential"); |
---|
| 32 | CredentialFactory.registerClass("net.deterlab.abac.GENICredential"); |
---|
| 33 | } |
---|
| 34 | catch (Exception e) { |
---|
| 35 | System.exit(20); |
---|
| 36 | } |
---|
| 37 | |
---|
[7f16578] | 38 | for (int i= 0; i < args.length; i++) { |
---|
| 39 | File f = new File(args[i]); |
---|
| 40 | |
---|
| 41 | try { |
---|
| 42 | if (f.isDirectory()) |
---|
| 43 | ctxt.load_directory(f, errs); |
---|
| 44 | else if (f.getPath().endsWith(".pem")) |
---|
| 45 | ctxt.load_id_file(f); |
---|
| 46 | else if (f.getPath().endsWith(".der")) |
---|
| 47 | ctxt.load_attribute_file(f); |
---|
| 48 | else if (f.getPath().endsWith(".xml")) |
---|
| 49 | ctxt.load_attribute_file(f); |
---|
| 50 | else if (f.getPath().endsWith(".zip")) |
---|
| 51 | ctxt.load_zip(f, errs); |
---|
| 52 | else if (f.getPath().endsWith(".rt0")) |
---|
| 53 | ctxt.load_rt0(f); |
---|
| 54 | else |
---|
| 55 | System.out.println(f + " of unknown type"); |
---|
| 56 | } |
---|
| 57 | catch (Exception e) { |
---|
| 58 | System.err.println("Failed to process " + f + ": " +e); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f)); |
---|
| 63 | |
---|
| 64 | // |
---|
| 65 | // run the query |
---|
| 66 | // |
---|
| 67 | |
---|
| 68 | System.out.println("Creds"); |
---|
| 69 | for (Credential c : ctxt.credentials()) { |
---|
| 70 | System.out.println(c.simpleString(ctxt)); |
---|
[797bebe] | 71 | System.out.println(c); |
---|
[7f16578] | 72 | } |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | } |
---|