package com.nailabs.abac.test; import java.io.*; import java.util.*; import com.nailabs.abac.credential.*; import com.nailabs.abac.process.*; import com.nailabs.abac.trust.*; import edu.stanford.peer.rbtm.credential.*; public class DiscoveryTest extends RtmlTest { /** parse the lookup table to map an entity to its host */ public static void parsePrepInfo(HashMap conf) { // this method may not be needed once cred domains contain urls String section = "PrepInfo"; HashSet propSet = (HashSet)conf.get(section); Properties props = new Properties(); try { Iterator i = propSet.iterator(); while(i.hasNext()) { props.load(new StringBufferInputStream((String)i.next())); } props.list(System.out); conf.put(section, props); } catch (Exception ex) { //ex.printStackTrace(); } } public static HashMap loadConfiguration(String name) { HashMap map = RtmlTest.loadConfiguration(name); parsePrepInfo(map); return map; } public static void main(String arg[]) { HashMap oConf = loadConfiguration((arg.length>0)?arg[0]:"ussh.txt"); HashMap vConf = loadConfiguration((arg.length>1)?arg[1]:"sadmir.txt"); TrustTarget primaryTT = null; // Create frontiers FrontierManager.addFrontier(vConf); FrontierManager.addFrontier(oConf); // Create entities for the negotiators Entity o = (Entity)oConf.get("EntityID"); Entity v = (Entity)vConf.get("EntityID"); System.out.println("vConf = " + vConf.toString()); System.out.println("oConf = " + oConf.toString()); // Initialize the contexts for each side NegotiationContext oContext = new NegotiationContext(oConf); NegotiationContext vContext = new NegotiationContext(vConf); PropertiesObserver oObs = new PropertiesObserver(oContext.getSelf()); PropertiesObserver vObs = new PropertiesObserver(vContext.getSelf()); RMINegotiator oAgent = null, vAgent = null; try { oAgent = new RMINegotiator(oContext); vAgent = new RMINegotiator(vContext); //v = new RtmlEntity("SAdmir", "FakeHashKeySAdmir"); //o = new RtmlEntity("USSH", "FakeHashKeyUSSH"); System.out.println("opponent = " + o + "," + o.hashCode()); System.out.println("verifier = " + v + "," + v.hashCode()); Role targetRole = new Role(v, new SimpleRoleName("getsSLocs")); System.out.println("target role = " + targetRole + "," + targetRole.hashCode()); primaryTT = new TrustTarget(v, targetRole, o); oContext.getGraph().addObserver(oObs); oContext.getStrategy().addObserver(oObs); vContext.getGraph().addObserver(vObs); vContext.getStrategy().addObserver(vObs); } catch(Exception ex) { ex.printStackTrace(System.err); } vAgent.setPeer(oAgent); System.out.println("Primary trust target = " + primaryTT); vAgent.setRoot(primaryTT); boolean success = vAgent.negotiate(); System.out.println("The negotiation has " + ((success)? "succeeded": "failed")); oObs.close(); vObs.close(); System.exit(0); } }