source: java/Reader.java @ 3612811

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

More reading and writing working. About to revamp CredentialFactory?
again

  • Property mode set to 100644
File size: 2.0 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            e.printStackTrace();
36            System.exit(20);
37        }
38
39        for (int i= 0; i < args.length; i++) {
40            File f = new File(args[i]);
41
42            try {
43                if (f.isDirectory()) 
44                    ctxt.load_directory(f, errs);
45                else if (f.getPath().endsWith(".pem")) 
46                    ctxt.load_id_file(f);
47                else if (f.getPath().endsWith(".der"))
48                    ctxt.load_attribute_file(f);
49                else if (f.getPath().endsWith(".xml"))
50                    ctxt.load_attribute_file(f);
51                else if (f.getPath().endsWith(".zip"))
52                    ctxt.load_zip(f, errs);
53                else if (f.getPath().endsWith(".rt0"))
54                    ctxt.load_rt0(f);
55                else
56                    System.out.println(f + " of unknown type");
57            }
58            catch (Exception e) {
59                System.err.println("Failed to process " + f + ": " +e);
60            }
61        }
62
63        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
64
65        //
66        // run the query
67        //
68
69        System.out.println("Creds");
70        for (Credential c : ctxt.credentials()) {
71            System.out.println(c.simpleString(ctxt));
72            System.out.println(c);
73        }
74
75    }
76}
Note: See TracBrowser for help on using the repository browser.