import java.io.*; import java.util.*; import edu.uci.ics.jung.graph.*; import net.deterlab.abac.Credential; import net.deterlab.abac.CredentialGraph; import net.deterlab.abac.Query; import net.deterlab.abac.Role; import org.bouncycastle.openssl.PEMReader; import org.bouncycastle.jce.provider.X509CertificateObject; import java.security.KeyPair; import java.security.PublicKey; // import org.bouncycastle.util.io.pem.PemObject; /** * Simple test of the native Java implementation of ABAC. Loads credentials * from an rt0 file and runs a query against them. */ public class GraphTest { protected static void importCred(File f, CredentialGraph g) throws Exception { Credential c = new Credential(f); g.add_credential(c); } protected static void importDir(File d, CredentialGraph g) { Vector ids = new Vector(); Vector creds = new Vector(); for (File f: d.listFiles()) { if (f.getPath().endsWith(".pem")) ids.add(f); else if (f.getPath().endsWith(".der") ) creds.add(f); else System.out.println(f + " of unknown type"); } for (File f: ids ){ try { Credential.addIdentity(f); } catch (Exception e) { System.err.println("Cannot add " + f + ": " + e); } } for (File f: creds) { try { importCred(f, g); } catch (Exception e) { System.err.println("Cannot add " + f + ": " + e); } } } 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); } CredentialGraph graph = new CredentialGraph(); String role = args[args.length-2]; String prin = args[args.length-1]; for (int i= 0; i < args.length-2; i++) { File f = new File(args[i]); try { if (f.isDirectory()) importDir(f, graph); else if (f.getPath().endsWith(".pem")) Credential.addIdentity(f); else if (f.getPath().endsWith(".der")) importCred(f, graph); else System.out.println(f + " of unknown type"); } catch (Exception e) { System.err.println("Failed to process " + f + ": " +e); } } // // run the query // Query q = graph.querier(); Graph ret = q.run(role, prin); for (Credential c : ret.getEdges()) System.out.println(c.toString()); } }