source: java/GraphTest.java @ e9360e2

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

Credential compatibility with libcreddy. Creddy expects an X509 extension identifying the key used to sign an attribute credential.

  • Property mode set to 100644
File size: 2.3 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    public static void main(String[] args) throws IOException {
21        if (args.length < 3) {
22            System.out.println("Usage: GraphTest <files> <role> <principal>");
23            System.out.println("    runs the query role <-?- principal and prints the result");
24            System.exit(1);
25        }
26
27        CredentialGraph graph = new CredentialGraph();
28        Map<String, Exception> errs = new HashMap<String, Exception>();
29
30        for (int i= 0; i < args.length-2; i++) {
31            File f = new File(args[i]);
32
33            try {
34                if (f.isDirectory()) 
35                    for (Credential c :Credential.readDirectory(f, errs)) 
36                        graph.add_credential(c);
37                else if (f.getPath().endsWith(".pem")) 
38                    Credential.addIdentity(new Identity(f));
39                else if (f.getPath().endsWith(".der"))
40                    graph.add_credential(new Credential(f));
41                else if (f.getPath().endsWith(".zip"))
42                    for (Credential c :Credential.readZipFile(f, errs)) 
43                        graph.add_credential(c);
44                else
45                    System.out.println(f + " of unknown type");
46            }
47            catch (Exception e) {
48                System.err.println("Failed to process " + f + ": " +e);
49            }
50        }
51
52        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
53
54        //
55        // run the query
56        //
57
58        Role role = new Role(args[args.length-2], true);
59        Role prin = new Role(args[args.length-1], true);
60        Query q = graph.querier();
61        Graph<Role, Credential> ret = q.run(role.toString(), prin.toString());
62        String fn = "attr";
63        int n = 0;
64        String suf = ".der";
65        for (Credential c : ret.getEdges()) {
66            System.out.println(c.simpleString());
67            if ( c.hasCertificate()) c.write(fn + n++ + suf);
68        }
69
70        fn = "id";
71        n = 0;
72        suf = ".pem";
73        for (Identity i: Credential.identities()) {
74            System.out.println("ID: " + i);
75            i.write(fn + n++ + suf);
76        }
77        Credential.writeZipFile(graph.credentials(), 
78                new File("./testout.zip"), true, true);
79    }
80}
Note: See TracBrowser for help on using the repository browser.