source: java/GraphTest.java @ be05757

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

Read from diretory in 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;
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 GraphTest {
20    /**
21     * Import a directory full of files, using the suffixes as determinants.
22     * First import all the identities (pem), then the credentials (der) into
23     * the credential graph then any alias files into the two maps.
24     */
25    protected static void importDir(File d, CredentialGraph g) {
26    }
27
28    public static void main(String[] args) throws IOException {
29        if (args.length < 3) {
30            System.out.println("Usage: GraphTest <files> <role> <principal>");
31            System.out.println("    runs the query role <-?- principal and prints the result");
32            System.exit(1);
33        }
34
35        CredentialGraph graph = new CredentialGraph();
36        Vector<KeyPair> kp = new Vector<KeyPair>();
37        Map<File, Exception> errs = new HashMap<File, Exception>();
38
39        for (int i= 0; i < args.length-2; i++) {
40            File f = new File(args[i]);
41
42            try {
43                if (f.isDirectory()) 
44                    for (Credential c :Credential.readDirectory(f, kp, errs)) 
45                        graph.add_credential(c);
46                else if (f.getPath().endsWith(".pem")) 
47                    Credential.addIdentity(new Identity(f));
48                else if (f.getPath().endsWith(".der"))
49                    graph.add_credential(new Credential(f));
50                else
51                    System.out.println(f + " of unknown type");
52            }
53            catch (Exception e) {
54                System.err.println("Failed to process " + f + ": " +e);
55            }
56        }
57
58        for (KeyPair k: kp) System.err.println(k);
59        for (File f: errs.keySet()) System.err.println(f + " " + errs.get(f));
60
61        //
62        // run the query
63        //
64
65        Role role = new Role(args[args.length-2], true);
66        Role prin = new Role(args[args.length-1], true);
67        Query q = graph.querier();
68        Graph<Role, Credential> ret = q.run(role.toString(), prin.toString());
69        String fn = "attr";
70        int n = 0;
71        String suf = ".der";
72        for (Credential c : ret.getEdges()) {
73            System.out.println(c.simpleString());
74            if ( c.hasCertificate()) c.write(fn + n++ + suf);
75        }
76
77        fn = "id";
78        n = 0;
79        suf = ".pem";
80        for (Identity i: Credential.identities()) {
81            System.out.println("ID: " + i);
82            i.write(fn + n++ + suf);
83        }
84    }
85}
Note: See TracBrowser for help on using the repository browser.