source: java/GraphTest.java @ 7ef13e3

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 7ef13e3 was 7ef13e3, checked in by Ted Faber <faber@…>, 13 years ago

Validate credentials.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import java.io.*;
2import java.util.*;
3
4import edu.uci.ics.jung.graph.*;
5
6import net.deterlab.abac.Credential;
7import net.deterlab.abac.CredentialGraph;
8import net.deterlab.abac.Query;
9import net.deterlab.abac.Role;
10
11import org.bouncycastle.openssl.PEMReader;
12import org.bouncycastle.jce.provider.X509CertificateObject;
13import java.security.KeyPair;
14import java.security.PublicKey;
15// import org.bouncycastle.util.io.pem.PemObject;
16
17
18/**
19 * Simple test of the native Java implementation of ABAC. Loads credentials
20 * from an rt0 file and runs a query against them.
21 */
22public class GraphTest {
23
24    protected static void importCred(File f, CredentialGraph g) 
25        throws Exception {
26        Credential c = new Credential(f);
27        g.add_credential(c);
28    }
29
30
31    protected static void importDir(File d, CredentialGraph g) {
32        Vector<File> ids = new Vector<File>();
33        Vector<File> creds = new Vector<File>();
34
35        for (File f: d.listFiles()) {
36            if (f.getPath().endsWith(".pem")) ids.add(f);
37            else if (f.getPath().endsWith(".der") ) creds.add(f);
38            else System.out.println(f + " of unknown type");
39        }
40        for (File f: ids ){
41            try {
42                Credential.addIdentity(f);
43            }
44            catch (Exception e) {
45                System.err.println("Cannot add " + f + ": " + e);
46            }
47        }
48
49        for (File f: creds) {
50            try {
51                importCred(f, g);
52            }
53            catch (Exception e) {
54                System.err.println("Cannot add " + f + ": " + e);
55            }
56        }
57    }
58    public static void main(String[] args) throws IOException {
59        if (args.length < 3) {
60            System.out.println("Usage: GraphTest <files> <role> <principal>");
61            System.out.println("    runs the query role <-?- principal and prints the result");
62            System.exit(1);
63        }
64
65        CredentialGraph graph = new CredentialGraph();
66        String role = args[args.length-2];
67        String prin = args[args.length-1];
68
69        for (int i= 0; i < args.length-2; i++) {
70            File f = new File(args[i]);
71
72            try {
73                if (f.isDirectory()) 
74                    importDir(f, graph);
75                else if (f.getPath().endsWith(".pem"))
76                    Credential.addIdentity(f);
77                else if (f.getPath().endsWith(".der"))
78                    importCred(f, graph);
79                else
80                    System.out.println(f + " of unknown type");
81            }
82            catch (Exception e) {
83                System.err.println("Failed to process " + f + ": " +e);
84            }
85        }
86        //
87        // run the query
88        //
89
90        Query q = graph.querier();
91        Graph<Role, Credential> ret = q.run(role, prin);
92        for (Credential c : ret.getEdges())
93            System.out.println(c.toString());
94    }
95}
Note: See TracBrowser for help on using the repository browser.