[8780cbec] | 1 | package com.nailabs.abac.test; |
---|
| 2 | |
---|
| 3 | import com.nailabs.abac.process.*; |
---|
| 4 | import com.nailabs.abac.credential.*; |
---|
| 5 | import edu.stanford.peer.rbtm.credential.*; |
---|
| 6 | import java.rmi.*; |
---|
| 7 | import java.rmi.server.*; |
---|
| 8 | import java.rmi.registry.*; |
---|
| 9 | import java.util.*; |
---|
| 10 | |
---|
| 11 | import javax.swing.*; |
---|
| 12 | import java.awt.*; |
---|
| 13 | import java.awt.event.*; |
---|
| 14 | |
---|
| 15 | public class ClientRTMLService extends UnicastRemoteObject |
---|
| 16 | implements NegotiatorFactory |
---|
| 17 | { |
---|
| 18 | static HashMap configs = new HashMap(); |
---|
| 19 | |
---|
| 20 | public static final int PORT = 6666; |
---|
| 21 | FrontierManager frontiers; |
---|
| 22 | boolean isDone = false; |
---|
| 23 | |
---|
| 24 | static { |
---|
| 25 | try { |
---|
| 26 | LocateRegistry.createRegistry(1099); |
---|
| 27 | System.out.println("Creating default registry on port 1099..."); |
---|
| 28 | } catch(Exception ex) { |
---|
| 29 | ex.printStackTrace(); |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | public ClientRTMLService(int port) |
---|
| 34 | throws RemoteException |
---|
| 35 | { |
---|
| 36 | super(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | public ClientRTMLService() throws RemoteException |
---|
| 40 | { |
---|
| 41 | this(PORT); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | public Remote getNegotiator(String entity, Negotiator peer) |
---|
| 45 | throws RemoteException |
---|
| 46 | { |
---|
| 47 | System.out.println("Looking up negotiator for " + entity); |
---|
| 48 | if(!FrontierManager.getFrontiers().contains(entity))return null; |
---|
| 49 | Entity oppo = peer.getSelf(); |
---|
| 50 | HashMap config = (HashMap)configs.get(entity); |
---|
| 51 | Entity self = (Entity)config.get("EntityID"); |
---|
| 52 | config.put("Peer", oppo); |
---|
| 53 | NegotiationContext context = new NegotiationContext(config); |
---|
| 54 | TextGraphObserver observer = new TextGraphObserver(entity); |
---|
| 55 | RMINegotiator agent = null; |
---|
| 56 | Remote stub = null; |
---|
| 57 | // grab a set of credential graph engines |
---|
| 58 | System.out.println("Received request for " + entity + " from " + |
---|
| 59 | oppo.toString()); |
---|
| 60 | try { |
---|
| 61 | agent = new RMINegotiator(context); |
---|
| 62 | context.getGraph().addObserver(observer); |
---|
| 63 | //stub = (Negotiator)exportObject(agent); |
---|
| 64 | stub = (agent == null)? null: toStub(agent); |
---|
| 65 | } |
---|
| 66 | catch(Exception ex) { |
---|
| 67 | ex.printStackTrace(); |
---|
| 68 | } |
---|
| 69 | System.out.println("agent = " + agent); |
---|
| 70 | System.out.println("stub = " + stub); |
---|
| 71 | // construct a new negotiation context |
---|
| 72 | return stub; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public void kill() throws RemoteException { isDone = true; } |
---|
| 76 | |
---|
| 77 | public static void main(String arg[]) |
---|
| 78 | { |
---|
| 79 | //if (System.getSecurityManager() == null) { |
---|
| 80 | // System.setSecurityManager(new RMISecurityManager()); |
---|
| 81 | //} |
---|
| 82 | Vector entities = new Vector(arg.length); |
---|
| 83 | for(int i = 0; i < arg.length; i++) |
---|
| 84 | { |
---|
| 85 | System.out.print("Loading from "); |
---|
| 86 | System.out.println(arg[i]); |
---|
| 87 | //check for int port number (TBD) |
---|
| 88 | HashMap config = RtmlTest.loadConfiguration(arg[i]); |
---|
| 89 | RtmlEntity id = (RtmlEntity)config.get("EntityID"); |
---|
| 90 | //System.out.print(" (config = "); |
---|
| 91 | //System.out.print(config); |
---|
| 92 | //System.out.println("), "); |
---|
| 93 | FrontierManager.addFrontier(config); |
---|
| 94 | configs.put(id.getHash(), config); |
---|
| 95 | configs.put(id.getName(), config); |
---|
| 96 | entities.add(id.getName()); |
---|
| 97 | System.out.println("\nLoaded configuration for " + id); |
---|
| 98 | } |
---|
| 99 | System.out.println("."); |
---|
| 100 | try { |
---|
| 101 | ClientRTMLService service = |
---|
| 102 | new ClientRTMLService(); |
---|
| 103 | Naming.rebind("ClientRTMLService", service); |
---|
| 104 | UIManager.setLookAndFeel |
---|
| 105 | (UIManager.getCrossPlatformLookAndFeelClassName()); |
---|
| 106 | } |
---|
| 107 | catch(Exception ex) { |
---|
| 108 | ex.printStackTrace(); |
---|
| 109 | } |
---|
| 110 | //...create the components to go into the frame... |
---|
| 111 | final JFrame frame = new JFrame("TTG Callback Admin"); |
---|
| 112 | JButton discoverButton = new JButton("Rediscover"); |
---|
| 113 | JButton exitButton = new JButton("Exit"); |
---|
| 114 | JPanel buttonBar = new JPanel(); |
---|
| 115 | final JList list = new JList(entities); |
---|
| 116 | JLabel title = new JLabel("Negotiators Running:"); |
---|
| 117 | JPanel contents = new JPanel(); |
---|
| 118 | JScrollPane listScroller = new JScrollPane(list); |
---|
| 119 | Dimension dim = new Dimension(300, 80); |
---|
| 120 | |
---|
| 121 | title.setAlignmentX(Component.CENTER_ALIGNMENT); |
---|
| 122 | list.setSelectedIndex(0); |
---|
| 123 | listScroller.setPreferredSize(new Dimension(250, 80)); |
---|
| 124 | listScroller.setMinimumSize(new Dimension(250, 80)); |
---|
| 125 | listScroller.setAlignmentX(Component.CENTER_ALIGNMENT); |
---|
| 126 | exitButton.addActionListener(new ActionListener() { |
---|
| 127 | public void actionPerformed(ActionEvent e) { |
---|
| 128 | System.exit(0); |
---|
| 129 | } |
---|
| 130 | }); |
---|
| 131 | discoverButton.addActionListener(new ActionListener() { |
---|
| 132 | public void actionPerformed(ActionEvent e) { |
---|
| 133 | String name = (String)list.getSelectedValue(); |
---|
| 134 | System.out.println("Rediscovering for " + name); |
---|
| 135 | HashMap config = (HashMap)configs.get(name); |
---|
| 136 | RtmlEntity id = (RtmlEntity)config.get("EntityID"); |
---|
| 137 | RtmlFrontier frontier = |
---|
| 138 | (RtmlFrontier)RtmlFrontier.getFrontier(id); |
---|
| 139 | frontier.init(config); |
---|
| 140 | } |
---|
| 141 | }); |
---|
| 142 | |
---|
| 143 | contents.setLayout(new BoxLayout(contents, BoxLayout.Y_AXIS)); |
---|
| 144 | buttonBar.add(discoverButton); |
---|
| 145 | buttonBar.add(exitButton); |
---|
| 146 | buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT); |
---|
| 147 | |
---|
| 148 | //...stick them in a container named contents... |
---|
| 149 | frame.getContentPane().add(contents); |
---|
| 150 | contents.add(Box.createRigidArea(new Dimension(0,5))); |
---|
| 151 | contents.add(title); |
---|
| 152 | contents.add(Box.createRigidArea(new Dimension(0,5))); |
---|
| 153 | contents.add(listScroller); |
---|
| 154 | contents.add(buttonBar); |
---|
| 155 | //contents.setPreferredSize(dim); |
---|
| 156 | //contents.setMinimumSize(dim); |
---|
| 157 | |
---|
| 158 | //Finish setting up the frame, and show it. |
---|
| 159 | //frame.addWindowListener(...); |
---|
| 160 | frame.pack(); |
---|
| 161 | frame.setLocation(new Point(100,100)); |
---|
| 162 | frame.setVisible(true); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | |
---|