import java.io.*; import java.util.*; import edu.uci.ics.jung.graph.*; import net.deterlab.abac.Credential; import net.deterlab.abac.Context; import net.deterlab.abac.Role; import net.deterlab.abac.Identity; import java.security.KeyPair; /** * Simple test of the native Java implementation of ABAC. Loads credentials * from an rt0 file and runs a query against them. */ public class GraphTest { public static void main(String[] args) throws IOException { if (args.length < 3) { System.out.println("Usage: GraphTest "); System.out.println(" runs the query role <-?- principal and prints the result"); System.exit(1); } Context ctxt = new Context(); Map errs = new HashMap(); for (int i= 0; i < args.length-2; i++) { File f = new File(args[i]); try { if (f.isDirectory()) ctxt.readDirectory(f, errs); else if (f.getPath().endsWith(".pem")) ctxt.loadIDFile(f); else if (f.getPath().endsWith(".der")) ctxt.loadAttributeFile(f); else if (f.getPath().endsWith(".zip")) ctxt.readZipFile(f, errs); else System.out.println(f + " of unknown type"); } catch (Exception e) { System.err.println("Failed to process " + f + ": " +e); } } for (String f: errs.keySet()) System.err.println(f + " " + errs.get(f)); // // run the query // Role role = new Role(args[args.length-2], ctxt); Role prin = new Role(args[args.length-1], ctxt); Collection ret = ctxt.query(role.toString(), prin.toString()); Set ids = new TreeSet(); String fn = "attr"; int n = 0; String suf = ".der"; for (Credential c : ret) { System.out.println(c.simpleString(ctxt)); if ( c.hasCertificate()) { c.write(fn + n++ + suf); ids.add(c.getID()); } } fn = "id"; n = 0; suf = ".pem"; for (Identity i: ids) { System.out.println("ID: " + i); i.write(fn + n++ + suf); } ctxt.writeZipFile(new File("./testout.zip"), true, true); } }