source: java/Reader.java @ 4560b65

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since 4560b65 was 65dbf06, checked in by Ted Faber <faber@…>, 11 years ago

Parses either

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import java.io.*;
2import java.util.*;
3
4import edu.uci.ics.jung.graph.*;
5
6import net.deterlab.abac.CredentialFactory;
7import net.deterlab.abac.Credential;
8import net.deterlab.abac.Context;
9import net.deterlab.abac.Role;
10import net.deterlab.abac.Identity;
11
12import 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 */
19public 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.registerClass("net.deterlab.abac.X509Credential");
32            CredentialFactory.registerClass("net.deterlab.abac.GENICredential");
33        }
34        catch (Exception e) {
35            System.exit(20);
36        }
37
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));
71            System.out.println(c);
72        }
73
74    }
75}
Note: See TracBrowser for help on using the repository browser.