1 31 package org.objectweb.proactive.core.body.jini; 32 33 import java.io.IOException ; 34 import java.rmi.RemoteException ; 35 import java.security.PublicKey ; 36 import java.security.cert.X509Certificate ; 37 import java.util.ArrayList ; 38 39 import org.objectweb.proactive.core.ProActiveException; 40 import org.objectweb.proactive.core.UniqueID; 41 import org.objectweb.proactive.core.body.UniversalBody; 42 import org.objectweb.proactive.core.body.reply.Reply; 43 import org.objectweb.proactive.core.body.request.Request; 44 import org.objectweb.proactive.ext.security.Communication; 45 import org.objectweb.proactive.ext.security.CommunicationForbiddenException; 46 import org.objectweb.proactive.ext.security.Policy; 47 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 48 import org.objectweb.proactive.ext.security.RenegotiateSessionException; 49 import org.objectweb.proactive.ext.security.SecurityContext; 50 import org.objectweb.proactive.ext.security.SecurityNotAvailableException; 51 import org.objectweb.proactive.ext.security.crypto.AuthenticationException; 52 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket; 53 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException; 54 55 56 61 public class JiniBodyAdapter implements UniversalBody, java.io.Serializable { 62 63 66 protected JiniBody proxiedJiniBody; 67 68 71 protected UniqueID bodyID; 72 73 public JiniBodyAdapter() { 77 } 78 79 public JiniBodyAdapter(JiniBody jiniBody) throws ProActiveException { 80 this.proxiedJiniBody = jiniBody; 81 try { 82 this.bodyID = jiniBody.getID(); 83 } catch (java.rmi.RemoteException e) { 84 throw new ProActiveException(e); 85 } 86 } 87 88 public JiniBodyAdapter(UniversalBody body) throws ProActiveException { 89 try { 90 this.proxiedJiniBody = new JiniBodyImpl(body); 91 } catch (java.rmi.RemoteException e) { 92 throw new ProActiveException(e); 93 } 94 this.bodyID = body.getID(); 95 } 96 97 101 109 public static void register(JiniBodyAdapter bodyAdapter, String url) 110 throws java.io.IOException { 111 java.rmi.Naming.rebind(url, bodyAdapter.proxiedJiniBody); 112 } 113 114 119 public static void unregister(String url) throws java.io.IOException { 120 try { 121 java.rmi.Naming.unbind(url); 122 } catch (java.rmi.NotBoundException e) { 123 throw new java.io.IOException ( 124 "No object is bound to the given url : " + url); 125 } 126 } 127 128 137 public static UniversalBody lookup(String url) throws java.io.IOException { 138 Object o = null; 139 140 try { 142 o = java.rmi.Naming.lookup(url); 143 } catch (java.rmi.NotBoundException e) { 144 throw new java.io.IOException ("The url " + url + 145 " is not bound to any known object"); 146 } 147 if (o instanceof JiniBody) { 148 try { 149 return new JiniBodyAdapter((JiniBody) o); 150 } catch (ProActiveException e) { 151 throw new java.io.IOException ("Cannot build a Jini Adapter" + 152 e.toString()); 153 } 154 } else { 155 throw new java.io.IOException ( 156 "The given url does exist but doesn't point to a jini body url=" + 157 url + " class found is " + o.getClass().getName()); 158 } 159 } 160 161 public boolean equals(Object o) { 162 if (!(o instanceof JiniBodyAdapter)) { 163 return false; 164 } 165 JiniBodyAdapter rba = (JiniBodyAdapter) o; 166 return proxiedJiniBody.equals(rba.proxiedJiniBody); 167 } 168 169 public int hashCode() { 170 return proxiedJiniBody.hashCode(); 171 } 172 173 public void receiveRequest(Request r) throws java.io.IOException , RenegotiateSessionException { 177 proxiedJiniBody.receiveRequest(r); 178 } 179 180 public void receiveReply(Reply r) throws java.io.IOException { 181 proxiedJiniBody.receiveReply(r); 182 } 183 184 public String getNodeURL() { 185 try { 186 return proxiedJiniBody.getNodeURL(); 187 } catch (java.rmi.RemoteException e) { 188 return "cannot contact the body to get the nodeURL"; 189 } 190 } 191 192 public UniqueID getID() { 193 return bodyID; 194 } 195 196 public void updateLocation(UniqueID id, UniversalBody jiniBody) 197 throws java.io.IOException { 198 proxiedJiniBody.updateLocation(id, jiniBody); 199 } 200 201 public UniversalBody getRemoteAdapter() { 202 return this; 203 } 204 205 public void enableAC() throws java.io.IOException { 206 proxiedJiniBody.enableAC(); 207 } 208 209 public void disableAC() throws java.io.IOException { 210 proxiedJiniBody.disableAC(); 211 } 212 213 public void setImmediateService(String methodName) 214 throws java.io.IOException { 215 proxiedJiniBody.setImmediateService(methodName); 216 } 217 218 220 public void initiateSession(int type,UniversalBody body) 221 throws RemoteException , IOException , CommunicationForbiddenException, 222 AuthenticationException, RenegotiateSessionException, 223 SecurityNotAvailableException { 224 proxiedJiniBody.initiateSession(type, body); 225 } 226 227 public void terminateSession(long sessionID) 228 throws java.io.IOException , SecurityNotAvailableException { 229 proxiedJiniBody.terminateSession(sessionID); 230 } 231 232 public X509Certificate getCertificate() 233 throws java.io.IOException , SecurityNotAvailableException { 234 return proxiedJiniBody.getCertificate(); 235 } 236 237 public ProActiveSecurityManager getProActiveSecurityManager() 238 throws java.io.IOException , SecurityNotAvailableException { 239 return proxiedJiniBody.getProActiveSecurityManager(); 240 } 241 242 public Policy getPolicyFrom(X509Certificate certificate) 243 throws java.io.IOException , SecurityNotAvailableException { 244 return proxiedJiniBody.getPolicyFrom(certificate); 245 } 246 247 public long startNewSession(Communication policy) 248 throws IOException , RenegotiateSessionException, 249 SecurityNotAvailableException { 250 return proxiedJiniBody.startNewSession(policy); 251 } 252 253 public ConfidentialityTicket negociateKeyReceiverSide( 254 ConfidentialityTicket confidentialityTicket, long sessionID) 255 throws java.io.IOException , KeyExchangeException, 256 SecurityNotAvailableException { 257 return proxiedJiniBody.negociateKeyReceiverSide(confidentialityTicket, 258 sessionID); 259 } 260 261 public PublicKey getPublicKey() 262 throws java.io.IOException , SecurityNotAvailableException { 263 return proxiedJiniBody.getPublicKey(); 264 } 265 266 public byte[] randomValue(long sessionID, byte[] cl_rand) 267 throws Exception , SecurityNotAvailableException { 268 return proxiedJiniBody.randomValue(sessionID, cl_rand); 269 } 270 271 public byte[][] publicKeyExchange(long sessionID, 272 UniversalBody distantBody, byte[] my_pub, byte[] my_cert, 273 byte[] sig_code) throws Exception , SecurityNotAvailableException { 274 return proxiedJiniBody.publicKeyExchange(sessionID, distantBody, 275 my_pub, my_cert, sig_code); 276 } 277 278 public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1, 279 byte[] tmp2, byte[] tmp3, byte[] tmp4) 280 throws Exception , SecurityNotAvailableException { 281 return proxiedJiniBody.secretKeyExchange(sessionID, tmp, tmp1, tmp2, 282 tmp3, tmp4); 283 } 284 285 public Communication getPolicyTo(String type, String from, String to) 286 throws java.io.IOException , SecurityNotAvailableException { 287 return proxiedJiniBody.getPolicyTo(type, from, to); 288 } 289 290 293 public String getVNName() throws IOException , SecurityNotAvailableException { 294 return proxiedJiniBody.getVNName(); 295 } 296 297 300 public byte[] getCertificateEncoded() 301 throws IOException , SecurityNotAvailableException { 302 return proxiedJiniBody.getCertificateEncoded(); 303 } 304 305 308 public SecurityContext getPolicy(SecurityContext securityContext) 309 throws SecurityNotAvailableException, IOException { 310 return proxiedJiniBody.getPolicy(securityContext); 311 } 312 313 public ArrayList getEntities() throws SecurityNotAvailableException, IOException { 314 return proxiedJiniBody.getEntities(); 315 } 316 317 318 } 322 | Popular Tags |