source: fedd/abac-src/ttg/trust/TargetNode.java @ 70caa72

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since 70caa72 was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[8780cbec]1package com.nailabs.abac.trust;
2
3import com.nailabs.abac.process.*;
4import edu.stanford.peer.rbtm.credential.*;
5import java.util.*;
6
7/**
8 * A target node is the parent class for the <CODE>*TTNode</CODE> classes,
9 * which have the following common elements: satisfaction state, implication
10 * parents, and control parents.
11 */
12public abstract class TargetNode extends TTGNode
13    implements SatisfactionListener {
14
15    /** The satisfaction state of this node */
16    protected SatisfactionState satisfier;
17   
18    /**
19     * A set of implication parent nodes. Each parent represents a separate
20     * edge in the trust target graph.
21     * @see com.nailabs.abac.process.ImplicationEdge
22     */
23    protected TTGNodeSet implicationParents = new TTGNodeSet();
24
25   
26    /**
27     * A set of control parent nodes. Each parent represents a separate edge
28     * in the trust target graph.
29     * @see com.nailabs.abac.process.ControlEdge
30     */
31    protected TTGNodeSet controlParents = new TTGNodeSet();
32   
33    /** Default constructor for a TargetNode */
34    public TargetNode(TrustTarget target) {
35        super(target);
36        subName = "TargetNode";
37        processor = new ProcessingState();
38        satisfier = new SatisfactionState(SatisfactionState.UNKNOWN);
39        satisfier.addObserver(this);
40    }
41   
42    /** Constructor which also creates a trust target implicitly */
43    public TargetNode(Entity verifier, EntityExpression target, Entity subject)
44        throws CredentialParsingException, TrustTargetParsingException
45    {
46        this(new TrustTarget(verifier, target, subject));
47    }
48
49   /**
50     * This method should be polymorphic since children will have customized
51     * fields.
52     */
53    public void update(Observable obs, Object obj) {
54        if(obs == satisfier) {
55            setChanged();
56            notifyObservers(satisfier);
57        } else {
58            super.update(obs, obj);
59        }
60    }
61
62
63    /** Read-only accessor method for the satisfaction state. */
64    public int getSatisfactionValue() { 
65        if(satisfier == null) return -1;
66        return satisfier.getState(); 
67    }
68
69    /**
70     * Accessor method for setting the satisfaction state field.
71     * @param state The new satisfaction state.
72     * @return The old satisfaction state.
73     */
74    protected SatisfactionState setState(SatisfactionState state) {
75        SatisfactionState old = satisfier;
76        satisfier = state;
77        debug("satisfaction",
78              "satisfaction state for " + getGoal() + " = " + state);
79        //if(!satisfier.equals(old)) {
80    setChanged();
81    notifyObservers(state);
82        //}
83        return old;
84    }
85
86    /**
87     * Process a node whose trust target verifier entity is not self
88     * @see RMINegotiator
89     */
90    public abstract void opponentProcess(NegotiationContext context);
91
92    /**
93     * Process a node whose trust target verifier entity is self
94     * @see RMINegotiator
95     */
96    public abstract void verifierProcess(NegotiationContext context);
97
98    /**
99     * Records the new state and then propagates it to the parent listeners.
100     * @param state The new satisfaction state to be propagated.
101     */
102    public  TTGNodeSet receive(TrustTarget source, SatisfactionState state) {
103        TTGNodeSet results = new TTGNodeSet();
104        debug("satisfaction", getGoal() + " received " + state + " from " +
105              source);
106        // if the state has not changed stop propagating it
107        if(!(this instanceof TrivialTTNode)) {
108            if(satisfier.getState() == state.getState() ||
109               getGoal().equals(source)) {
110                debug("satisfaction",
111                      "not trivial and received same state bailing out now!");
112                return results;
113            }
114        }
115        setState(state);
116        //}
117        Iterator i = implicationParents.values().iterator();
118        while(i.hasNext()) {
119            try { // this will fail if the parent is a linking goal
120                SatisfactionListener listener = (SatisfactionListener)i.next();
121                TTGNodeSet branchResult = listener.receive((TrustTarget)getGoal(), state);
122                if(branchResult == null && branchResult.size() > 0) {
123                    results.addAll(branchResult);
124                }
125            }
126            catch(Exception ex) { // to print out exception uncomment
127                ex.printStackTrace();
128            }
129        }
130        //if(state.getState() == SatisfactionState.FAILED) {
131    //bail out for now...
132    //return results;
133    //}
134    // Work with the control parents
135        i = controlParents.values().iterator();
136        Strategy strategy = context.getStrategy();
137    //if satisfied and there exist control parent(s), then notify strategy
138    if(state.getState() == SatisfactionState.SATISFIED) {
139        if(i.hasNext()) {
140            //notify strategy that a control child has been satisfied
141            strategy.addSatisfiedControlChild(this); 
142        }
143        while(i.hasNext()) { //place each control parent on the worklist
144            TTGNode controlParent = (TTGNode)i.next();
145            strategy.addToWorklist(controlParent);
146        }
147        }
148        System.out.println("TargetNode: " + getGoal() + "exiting receive method");
149        return results;
150    }
151
152    /** Add a goal as an implication parent of this node. */
153    public void addImplicationParent(TargetNode parent) {
154        if(parent != null){ 
155            debug("node", "adding implication parent");
156            implicationParents.add(parent);
157            parent.receive((TrustTarget)getGoal(), satisfier);
158        }
159    }
160
161    /** Add a goal as a control parent of this node. */ 
162    public void addControlParent(TargetNode parent) {
163        if(parent != null) { 
164            controlParents.add(parent);
165            if(getSatisfactionValue() == SatisfactionState.SATISFIED) {
166                context.getStrategy().addToWorklist(parent);
167            }
168            //setChanged();
169            //notifyObservers();
170        }
171        //receive((TrustTarget)getGoal(), satisfier);
172    }
173
174    /** Convenience accessor method for the target role expression */
175    public EntityExpression getTargetExpression() { 
176        return ((TrustTarget)getGoal()).getTargetRole(); 
177    }
178
179    public String toXML() {
180        return toXML(new String(""));
181    }
182
183    public String toXML(String options) {
184        return toXML(options, satisfier.toXML());
185    }
186
187    /** Print out a node in human readable format */
188    public String toString() {
189        StringBuffer buff = new StringBuffer("[");
190        buff.append(getClass().getName()).append(", ");
191        buff.append(processor).append(", ");
192        buff.append(satisfier).append(", ");
193        buff.append(getGoal().toString()).append("]");
194        return buff.toString();
195    }
196
197}
198
199
200 
Note: See TracBrowser for help on using the repository browser.