source: java/GraphTest.java @ 84f0e7a

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

Initial run at unifying the interface.

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[31b67d5]1import java.io.*;
[7ef13e3]2import java.util.*;
[31b67d5]3
4import edu.uci.ics.jung.graph.*;
5
6import net.deterlab.abac.Credential;
[84f0e7a]7import net.deterlab.abac.Context;
[31b67d5]8import net.deterlab.abac.Query;
9import net.deterlab.abac.Role;
[9725efb]10import net.deterlab.abac.Identity;
[31b67d5]11
[7ef13e3]12import java.security.KeyPair;
13
14
[31b67d5]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) {
[7ef13e3]22            System.out.println("Usage: GraphTest <files> <role> <principal>");
[31b67d5]23            System.out.println("    runs the query role <-?- principal and prints the result");
24            System.exit(1);
25        }
26
[84f0e7a]27        Context ctxt = new Context();
[5cf72cc]28        Map<String, Exception> errs = new HashMap<String, Exception>();
[31b67d5]29
[7ef13e3]30        for (int i= 0; i < args.length-2; i++) {
31            File f = new File(args[i]);
[31b67d5]32
[7ef13e3]33            try {
34                if (f.isDirectory()) 
[84f0e7a]35                    ctxt.readDirectory(f, errs);
[be05757]36                else if (f.getPath().endsWith(".pem")) 
[84f0e7a]37                    ctxt.loadIDFile(f);
[7ef13e3]38                else if (f.getPath().endsWith(".der"))
[84f0e7a]39                    ctxt.loadAttributeFile(f);
[5cf72cc]40                else if (f.getPath().endsWith(".zip"))
[84f0e7a]41                    ctxt.readZipFile(f, errs);
[7ef13e3]42                else
43                    System.out.println(f + " of unknown type");
44            }
45            catch (Exception e) {
46                System.err.println("Failed to process " + f + ": " +e);
47            }
48        }
[cae7369]49
[5cf72cc]50        for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f));
[be05757]51
[31b67d5]52        //
53        // run the query
54        //
55
[84f0e7a]56        Role role = new Role(args[args.length-2], ctxt);
57        Role prin = new Role(args[args.length-1], ctxt);
58        Collection<Credential> ret = ctxt.query(role.toString(), prin.toString());
59        Set<Identity> ids = new TreeSet<Identity>();
60
[1a7e6d3]61        String fn = "attr";
62        int n = 0;
63        String suf = ".der";
[84f0e7a]64        for (Credential c : ret) {
65            System.out.println(c.simpleString(ctxt));
66            if ( c.hasCertificate()) {
67                c.write(fn + n++ + suf);
68                ids.add(c.getID());
69            }
[1a7e6d3]70        }
[9725efb]71
[1a7e6d3]72        fn = "id";
73        n = 0;
74        suf = ".pem";
[84f0e7a]75        for (Identity i: ids) {
[9725efb]76            System.out.println("ID: " + i);
[1a7e6d3]77            i.write(fn + n++ + suf);
78        }
[84f0e7a]79        ctxt.writeZipFile(new File("./testout.zip"), true, true);
[31b67d5]80    }
81}
Note: See TracBrowser for help on using the repository browser.