package com.nailabs.abac.test; import com.nailabs.abac.process.*; import com.nailabs.abac.trust.*; import edu.stanford.peer.rbtm.credential.*; import edu.stanford.peer.rbtm.engine.*; import java.util.*; import java.io.*; public class TestEngine extends edu.stanford.peer.rbtm.test.TestEngine { public static void parseStrategyHints(HashMap conf) { String section = "Strategy"; 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 void parseEntityId(HashMap conf) { String section = "EntityID"; HashSet nameSet = (HashSet)conf.get(section); String name = null; try { name = (String)nameSet.iterator().next(); conf.put(section, new SimpleEntity(name)); } catch(Exception ex) { //ex.printStackTrace(); } } public static void parseAckPolicy(HashMap conf) { AckPolicy policy = new AckPolicy(); String section = "AckPolicy"; HashSet policySet = (HashSet)conf.get(section); if(policySet == null)policySet = new HashSet(); Iterator i = policySet.iterator(); while(i.hasNext()) { try { StringTokenizer st = new StringTokenizer((String)i.next(), "="); EntityExpression key = StaticCredential.getEntityExpression(st.nextToken()); EntityExpression value = StaticCredential.getEntityExpression(st.nextToken()); policy.addAckFact(key, value); } catch(Exception ex) { ex.printStackTrace(); } } conf.put(section, policy); System.out.println("AckPolicy = " + policy); } public static void parseACPolicy(HashMap conf) { ACPolicy policy = new ACPolicy(); String section = "AccessControl"; HashSet policySet = (HashSet)conf.get(section); if(policySet == null)policySet = new HashSet(); Iterator i = policySet.iterator(); while(i.hasNext()) { try { StringTokenizer st = new StringTokenizer((String)i.next(), "="); StaticCredential key = new StaticCredential(st.nextToken()); String valueString = st.nextToken().trim(); Role value = (valueString.equalsIgnoreCase("true"))? ACPolicy.TRUE: (Role)StaticCredential.getRole(valueString); policy.addACFact(key, value); } catch(Exception ex) { ex.printStackTrace(); } } conf.put(section, policy); System.out.println("ACPolicy = " + policy); } protected static HashSet parseCredentials(String section, HashMap conf) { HashSet creds = new HashSet(); try { Iterator i = ((HashSet)conf.get(section)).iterator(); while(i.hasNext()) { creds.add(new StaticCredential((String)i.next())); } } catch(Exception ex) { ex.printStackTrace(); } System.out.println(section + ": " + creds); return creds; } protected static HashSet parseRoleNames(String section, HashMap conf) { HashSet names = new HashSet(); try { Iterator i = ((HashSet)conf.get(section)).iterator(); while(i.hasNext()) { names.add(new SimpleRoleName((String)i.next())); } } catch(NullPointerException npe) { System.out.println("warning: " + section + " is null"); } catch(Exception ex) { ex.printStackTrace(); } System.out.println(section + ": " + names); return names; } public static void parseIssuerTracesAll(HashMap conf) { String section = "IssuerTracesAll"; HashSet traces = parseRoleNames(section, conf); conf.put(section, traces); } public static void parseIssuerTracesDef(HashMap conf) { String section = "IssuerTracesDef"; HashSet traces = parseRoleNames(section, conf); conf.put(section, traces); } public static void parseIssuerTraceable(HashMap conf) { String section = "IssuerTraceable"; HashSet traces = parseRoleNames(section, conf); conf.put(section, traces); } public static void parseSubjectTraceable(HashMap conf) { String section = "SubjectTraceable"; HashSet traces = parseRoleNames(section, conf); conf.put(section, traces); } public static void parsePolicyReachable(HashMap conf) { String section = "PolicyReachable"; HashSet reached = parseCredentials(section, conf); conf.put(section, reached); } public static void parseSelfReachable(HashMap conf) { String section = "SelfReachable"; HashSet reached = parseCredentials(section, conf); conf.put(section, reached); } /** */ public static HashMap loadConfiguration(String name) { HashMap map = edu.stanford.peer.rbtm.test.TestEngine.loadConfiguration(name); System.out.println("Loaded configuration from " + name); System.out.println("map = " + map ); parseEntityId(map); parseAckPolicy(map); parseACPolicy(map); //parseIssuerTraceable(map); parseIssuerTracesAll(map); parseIssuerTracesDef(map); parseSubjectTraceable(map); parsePolicyReachable(map); parseSelfReachable(map); parseStrategyHints(map); return map; } public static void main(String arg[]) { HashMap oConf = loadConfiguration((arg.length>0)?arg[0]:"alice.txt"); HashMap vConf = loadConfiguration((arg.length>1)?arg[1]:"medsup.txt"); TrustTarget primaryTT = null; //System.out.println("vConf = " + vConf.toString()); //System.out.println("oConf = " + oConf.toString()); // Create frontiers FrontierManager.addFrontier(oConf); FrontierManager.addFrontier(vConf); // Create entities for the negotiators Entity o = (Entity)oConf.get("EntityID"); Entity v = (Entity)vConf.get("EntityID"); System.out.println("opponent = " + o); System.out.println("verifier = " + v); // 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); primaryTT = new TrustTarget((arg.length > 2)? arg[2]: "MedSup: MedSup.discount <<-?- Alice"); 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(); } }