1 31 package org.objectweb.proactive.core.body.ibis; 32 33 34 39 import java.io.IOException ; 40 import java.security.PublicKey ; 41 import java.security.cert.X509Certificate ; 42 import java.util.ArrayList ; 43 44 import org.apache.log4j.Logger; 45 import org.objectweb.proactive.core.ProActiveException; 46 import org.objectweb.proactive.core.UniqueID; 47 import org.objectweb.proactive.core.body.UniversalBody; 48 import org.objectweb.proactive.core.body.reply.Reply; 49 import org.objectweb.proactive.core.body.request.Request; 50 import org.objectweb.proactive.ext.security.Communication; 51 import org.objectweb.proactive.ext.security.CommunicationForbiddenException; 52 import org.objectweb.proactive.ext.security.Policy; 53 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 54 import org.objectweb.proactive.ext.security.RenegotiateSessionException; 55 import org.objectweb.proactive.ext.security.SecurityContext; 56 import org.objectweb.proactive.ext.security.SecurityNotAvailableException; 57 import org.objectweb.proactive.ext.security.crypto.AuthenticationException; 58 import org.objectweb.proactive.ext.security.crypto.ConfidentialityTicket; 59 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException; 60 61 62 public class IbisRemoteBodyAdapter implements UniversalBody, 63 java.io.Serializable { 64 protected static Logger logger = Logger.getLogger(IbisRemoteBodyAdapter.class.getName()); 65 66 69 protected IbisRemoteBody proxiedRemoteBody; 70 71 74 protected UniqueID bodyID; 75 76 public IbisRemoteBodyAdapter() { 80 } 81 82 public IbisRemoteBodyAdapter(IbisRemoteBody remoteBody) 83 throws ProActiveException { 84 this.proxiedRemoteBody = remoteBody; 85 if (logger.isDebugEnabled()) { 86 logger.debug(" remote body = " + proxiedRemoteBody.getClass()); 87 } 88 try { 89 this.bodyID = remoteBody.getID(); 90 } catch (ibis.rmi.RemoteException e) { 91 throw new ProActiveException(e); 92 } 93 } 94 95 public IbisRemoteBodyAdapter(UniversalBody body) throws ProActiveException { 96 try { 97 this.proxiedRemoteBody = new IbisRemoteBodyImpl(body); 98 if (logger.isDebugEnabled()) { 99 logger.debug("proxiedRemoteBody = " + 100 proxiedRemoteBody.getClass()); 101 } 102 } catch (ibis.rmi.RemoteException e) { 103 throw new ProActiveException(e); 104 } 105 this.bodyID = body.getID(); 106 } 107 108 112 120 public static void register(IbisRemoteBodyAdapter bodyAdapter, String url) 121 throws java.io.IOException { 122 ibis.rmi.Naming.rebind(url, bodyAdapter.proxiedRemoteBody); 123 } 124 125 130 public static void unregister(String url) throws java.io.IOException { 131 try { 132 ibis.rmi.Naming.unbind(url); 133 } catch (ibis.rmi.NotBoundException e) { 134 throw new java.io.IOException ( 135 "No object is bound to the given url : " + url); 136 } 137 } 138 139 148 public static UniversalBody lookup(String url) throws java.io.IOException { 149 Object o = null; 150 151 try { 153 o = ibis.rmi.Naming.lookup(url); 154 } catch (ibis.rmi.NotBoundException e) { 155 throw new java.io.IOException ("The url " + url + 156 " is not bound to any known object"); 157 } 158 if (o instanceof IbisRemoteBody) { 159 try { 160 return new IbisRemoteBodyAdapter((IbisRemoteBody) o); 161 } catch (ProActiveException e) { 162 throw new java.io.IOException ("Cannot build a Remote Adapter" + 163 e.toString()); 164 } 165 } else { 166 throw new java.io.IOException ( 167 "The given url does exist but doesn't point to a remote body url=" + 168 url + " class found is " + o.getClass().getName()); 169 } 170 } 171 172 public boolean equals(Object o) { 173 if (!(o instanceof IbisRemoteBodyAdapter)) { 174 return false; 175 } 176 IbisRemoteBodyAdapter rba = (IbisRemoteBodyAdapter) o; 177 return proxiedRemoteBody.equals(rba.proxiedRemoteBody); 178 } 179 180 public int hashCode() { 181 return proxiedRemoteBody.hashCode(); 182 } 183 184 public void receiveRequest(Request r) throws java.io.IOException , RenegotiateSessionException { 188 proxiedRemoteBody.receiveRequest(r); 189 } 190 191 public void receiveReply(Reply r) throws java.io.IOException { 192 proxiedRemoteBody.receiveReply(r); 193 } 194 195 public String getNodeURL() { 196 try { 197 return proxiedRemoteBody.getNodeURL(); 198 } catch (ibis.rmi.RemoteException e) { 199 return "cannot contact the body to get the nodeURL"; 200 } 201 } 202 203 public UniqueID getID() { 204 return bodyID; 205 } 206 207 public void updateLocation(UniqueID id, UniversalBody remoteBody) 208 throws java.io.IOException { 209 proxiedRemoteBody.updateLocation(id, remoteBody); 210 } 211 212 public UniversalBody getRemoteAdapter() { 213 return this; 214 } 215 216 public void enableAC() throws java.io.IOException { 217 proxiedRemoteBody.enableAC(); 218 } 219 220 public void disableAC() throws java.io.IOException { 221 proxiedRemoteBody.disableAC(); 222 } 223 224 public void setImmediateService(String methodName) 225 throws java.io.IOException { 226 proxiedRemoteBody.setImmediateService(methodName); 227 } 228 229 233 public void initiateSession(int type,UniversalBody body) throws IOException , CommunicationForbiddenException, AuthenticationException, RenegotiateSessionException, SecurityNotAvailableException { 234 proxiedRemoteBody.initiateSession(type,body); 235 236 } 237 238 241 public void terminateSession(long sessionID) throws IOException , SecurityNotAvailableException { 242 proxiedRemoteBody.terminateSession(sessionID) ; 243 } 244 245 248 public X509Certificate getCertificate() throws SecurityNotAvailableException, IOException { 249 return proxiedRemoteBody.getCertificate(); 250 } 251 252 255 public ProActiveSecurityManager getProActiveSecurityManager() throws SecurityNotAvailableException, IOException { 256 return proxiedRemoteBody.getProActiveSecurityManager(); 257 } 258 259 262 public Policy getPolicyFrom(X509Certificate certificate) throws SecurityNotAvailableException, IOException { 263 return proxiedRemoteBody.getPolicyFrom(certificate); 264 } 265 266 269 public long startNewSession(Communication policy) throws SecurityNotAvailableException, IOException , RenegotiateSessionException { 270 return proxiedRemoteBody.startNewSession(policy); 271 } 272 273 276 public ConfidentialityTicket negociateKeyReceiverSide(ConfidentialityTicket confidentialityTicket, long sessionID) throws SecurityNotAvailableException, KeyExchangeException, IOException { 277 return proxiedRemoteBody.negociateKeyReceiverSide(confidentialityTicket,sessionID); 278 } 279 280 283 public PublicKey getPublicKey() throws SecurityNotAvailableException, IOException { 284 return proxiedRemoteBody.getPublicKey(); 285 } 286 287 290 public byte[] randomValue(long sessionID, byte[] cl_rand) throws SecurityNotAvailableException, Exception { 291 return proxiedRemoteBody.randomValue(sessionID,cl_rand); 292 } 293 294 297 public byte[][] publicKeyExchange(long sessionID, UniversalBody distantBody, byte[] my_pub, byte[] my_cert, byte[] sig_code) throws SecurityNotAvailableException, Exception , RenegotiateSessionException { 298 return proxiedRemoteBody.publicKeyExchange(sessionID,distantBody,my_pub,my_cert,sig_code); 299 } 300 301 304 public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1, byte[] tmp2, byte[] tmp3, byte[] tmp4) throws SecurityNotAvailableException, Exception , RenegotiateSessionException { 305 return proxiedRemoteBody.secretKeyExchange(sessionID,tmp,tmp1,tmp2,tmp3,tmp4); 306 } 307 308 311 public Communication getPolicyTo(String type, String from, String to) throws SecurityNotAvailableException, IOException { 312 return proxiedRemoteBody.getPolicyTo(type,from,to); 313 } 314 315 318 public SecurityContext getPolicy(SecurityContext securityContext) throws SecurityNotAvailableException, IOException { 319 return proxiedRemoteBody.getPolicy(securityContext); 320 } 321 322 325 public String getVNName() throws SecurityNotAvailableException, IOException { 326 return proxiedRemoteBody.getVNName(); 327 } 328 329 332 public byte[] getCertificateEncoded() throws SecurityNotAvailableException, IOException { 333 return proxiedRemoteBody.getCertificateEncoded(); 334 } 335 336 339 public ArrayList getEntities() throws SecurityNotAvailableException, IOException { 340 return proxiedRemoteBody.getEntities(); 341 } 342 343 } 347 | Popular Tags |