source: fedd/abac-src/ttg/process/RMINegotiator.java @ 79b6596

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

ABAC sources from Cobham

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[8780cbec]1package com.nailabs.abac.process;
2
3import com.nailabs.abac.trust.*;
4import com.nailabs.abac.test.*;
5import edu.stanford.peer.rbtm.credential.Entity;
6import java.rmi.*;
7import java.rmi.server.*;
8
9/**
10 * This class is a concrete negotiator implementation that employs RMI as the
11 * underlying communications transport mechanism.
12 */
13public class RMINegotiator extends UnicastRemoteObject implements Negotiator  {
14    /**
15     * The peer with which this instance negotiates.
16     */
17    protected Negotiator peer;
18
19    /**
20     * The context for the current negotiation, including a trust target graph,
21     * strategy, and frontier manager instances.
22     */
23    protected NegotiationContext context;
24
25    /**
26     * Default constructor for the client-side negotiatior. This negotiator
27     * is requesting access to a resource.
28     */
29    public RMINegotiator(NegotiationContext nc) throws RemoteException { 
30        context = nc;
31    }
32
33    /**
34     * Constructor for the server-side negotiator. This negotiator has a
35     * resource that needs protection.
36     */
37    public RMINegotiator(TargetNode root, RMINegotiator peer) 
38        throws RemoteException {
39        setPeer(peer); 
40    } 
41   
42    public Entity getSelf() 
43    {
44        return context.getSelf();
45    }
46
47    /**
48     * initial a new root node and start the negotiation process.
49     */
50    public boolean negotiate() {
51        TTG graph = context.getGraph();
52        Strategy s = context.getStrategy();
53        SatisfactionState state;
54        int i = 0;
55        debug("pre-processing locally...");
56        //perform strategy once
57        s.iterate();
58        Message changes = graph.getChanges();
59        graph.reset();
60        do {
61            debug("processing cycle = " + ++i);
62            debug("sending message " + changes);
63            System.out.println("Sending message: ");
64            System.out.println(changes.toXML());
65        try {
66            Message updates = peer.receive(changes);
67            debug("receiving message " + updates);
68            changes = receive(updates);
69        }
70        catch(Exception ex) {
71            Debug.rbtmStop();
72            ex.printStackTrace();
73            return false;
74        }
75            state = new SatisfactionState(context.getStrategy().getSatisfactionState());
76            debug("RMINegotiator:  primary trust target  is " + state);
77        }while(state.getState() == SatisfactionState.UNKNOWN && i <= 100);
78        // out of the loop so we need to return success or failure
79        return (state.getState() == SatisfactionState.SATISFIED);
80    }
81
82
83    /** set the other negotiator dynamically */
84    public void setPeer(Negotiator peer) {
85        this.peer = peer;
86    }
87
88    public void setRoot(TrustTarget tt) {
89        context.getGraph().setRoot(tt);
90        //TargetNode node = (TargetNode)context.getGraph().getNodeByHash(tt);
91        //context.getStrategy().addToWorklist(node);
92    }
93   
94
95    /**
96     * Synchronously receive a message which can contain multiple operations
97     * from an peer and then return the updates to the originating
98     * peer.
99     */
100    public Message receive(Message msg) throws Exception {
101        Strategy strategy = context.getStrategy();
102        TTG graph = context.getGraph();
103        Message results = null;
104
105        //for(int i = 0, max = msg.getOperationsCount(); i < max; i++) {
106        //    System.out.println("max = " + max);
107        //   try {
108        //      Operation op = msg.getNextOperation();
109        //      op.perform(graph);
110        //    }
111        //    catch(Exception ex) {
112        //      ex.printStackTrace();
113        //    }
114        //}
115        debug("begin receive");
116        graph.update(msg);
117        debug("graph has been updated");
118        strategy.process(msg);
119        debug("strategy has processed the work list");
120        results = graph.getChanges();
121        debug("grabbing the delta list = " + results);
122        graph.reset();
123
124        debug("end receive");   
125        return results;
126    }
127   
128    /** convenience method for printing messages */
129    public void debug(String message) {
130        StringBuffer buff = new StringBuffer("RMINegotiator[");
131        buff.append(context.getSelf()).append("]: ").append(message);
132        //System.out.println(buff);
133        Debug.debug("negotiate", buff.toString());
134    }
135}
Note: See TracBrowser for help on using the repository browser.