/* * Copyrighted (C) 2002, Networks Associates Technology, Inc. * All rights reserved */ package com.nailabs.abac.trust; import com.nailabs.abac.process.*; import com.nailabs.abac.test.*; import edu.stanford.peer.rbtm.credential.*; import java.util.*; import java.io.*; /** * A generic node type for a trust target graph (TTG). The node encapsulates * a trust target and provides methods for processing a node. */ public abstract class TTGNode extends Observable implements Observer, Serializable, XMLizable { /** A trust target that this node represents on the graph */ private Goal goal = null; /** A negotiation context which binds graph, strategy, and frontiers */ protected NegotiationContext context; /** The processing state of this graph node */ protected transient ProcessingState processor = new ProcessingState(); /** Encapsulated set of parents for a TTG node */ protected TTGNodeSet parents = new TTGNodeSet(); /** Encapsulated set of children for a TTG node */ protected TTGNodeSet children = new TTGNodeSet(); /** Convenience debugging name to be overridden in subclasses */ protected String subName = "TTGNode"; /** Generic node factory method which creates a node based on a goal */ public static TTGNode createNode(Goal seed) { if(seed instanceof TrustTarget) { EntityExpression target = ((TrustTarget)seed).getTargetRole(); if(target instanceof Entity) { return new TrivialTTNode((TrustTarget)seed); } if(target instanceof Role) { return new SimpleTTNode((TrustTarget)seed); } if(target instanceof LinkedRole) { return new LinkTTNode((TrustTarget)seed); } if(target instanceof Intersection) { return new IntersectionTTNode((TrustTarget)seed); } } if(seed instanceof LinkingGoal) { return new LinkingGoalNode((LinkingGoal)seed); } return null; } /** Default constructor. Subclasses should access processing state field */ public TTGNode(Goal target) { goal = target; processor.addObserver(this); } /** updates the processing state of this node */ public void updateProcessingState(ProcessingState state) { processor.update(state); } /** * This method should be polymorphic since children will have customized * fields. */ public void update(Observable obs, Object obj) { if(obs == processor) { setChanged(); notifyObservers(processor); } } /** Polymorphic method for initializing a node based on its context */ public void init(NegotiationContext context) { System.out.println("TTGNode: initialize context for " + getGoal()); if(context == null) { System.out.println("WARNING NULL CONTEXT ENCOUNTERED!!!"); } this.context = context; } /** * A generic process method to determine whether to process this node * as a verifier or an opponent. * @param context The context of this trust negotiation */ public void process(NegotiationContext context) { Entity verifier = getGoal().getVerifier(); if(context.getSelf().equals(verifier)) { // check verifier processed . . . if(getProcessingState().isVerifierProcessed()) { System.out.println("TTGNode: already verifier processed node " + getGoal()); return; } verifierProcess(context); } // check opponent processed . . . else { if(getProcessingState().isOpponentProcessed()) { System.out.println("TTGNode: already opponent processed node " + getGoal()); return; } opponentProcess(context); } } /** * Each distinct node type should know how to process itself, so this * method should be overridden in subclasses. * @param context A context w/helper functions required for processing */ public abstract void verifierProcess(NegotiationContext context); /** * Each distinct node type should know how to process itself, so this * method should be overridden in subclasses. * @param context A context w/helper functions required for processing */ public abstract void opponentProcess(NegotiationContext context); /** Public accessor method for the negotiation context */ public NegotiationContext getContext() { return context; } /** Accessor/modifier method for the verifier of the trust target. */ public Entity getVerifier() { return goal.getVerifier(); } /** Accessor/modifier method for the subject (RHS) of the trust target. */ public EntityExpression getSubject() { return goal.getSubject(); } /** Accessor method for the processing state of this node */ public ProcessingState getProcessingState() { return processor; } /** Accessor method for the goal/trust target of this graph node */ public Goal getGoal() { return goal; } /** Accessor method for the type of this TTG node */ public String getType() { return subName; } /** Accessor/modifier method for the target role of the trust target. */ //public EntityExpression getTargetExpression() { return goal.getTargetRole();} /** Adds a parent node to this instance */ public void addParent(TTGNode node) { parents.add(node); } /** Adds a child node to this instance. */ public void addChild(TTGNode node) { children.add(node); } /** accessor for a set of all the child nodes of the current instance */ public TTGNodeSet getChildren() { return children; } /** accessor for a set of all the parent nodes of the current instance */ public TTGNodeSet getParents() { return parents; } /** Print out a node in human readable format */ public String toString() { StringBuffer buff = new StringBuffer("["); buff.append(getClass().getName()).append(", "); buff.append(processor).append(", "); buff.append(getGoal().toString()).append("]"); return buff.toString(); } /** Polymorphic method for converting a node into an XML string */ public abstract String toXML(); /** Method for children to use for creating a XML compatible string */ protected String toXML(String options, String elements) { StringBuffer buff = new StringBuffer("<"); buff.append(subName).append(options).append(">\n"); buff.append(getGoal().toXML()); buff.append(processor.toXML()); buff.append(elements); buff.append("\n"); return buff.toString(); } /** Friendly debuggin method to be inherited by all children */ protected void debug(String key, String message) { StringBuffer buff = new StringBuffer(subName); if(context != null) buff.append("[").append(context.getSelf()).append("]"); buff.append(": ").append(message); Debug.debug(key, buff.toString()); } }