1 31 package org.objectweb.proactive.core.body.rmi; 32 33 import java.io.IOException ; 34 import java.security.PublicKey ; 35 import java.security.cert.X509Certificate ; 36 import java.util.ArrayList ; 37 38 import org.apache.log4j.Logger; 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 public class RemoteBodyAdapter implements UniversalBody, java.io.Serializable { 57 protected static Logger logger = Logger.getLogger(RemoteBodyAdapter.class.getName()); 58 59 62 protected RemoteBody proxiedRemoteBody; 63 64 67 protected UniqueID bodyID; 68 69 public RemoteBodyAdapter() { 73 } 74 75 public RemoteBodyAdapter(RemoteBody remoteBody) throws ProActiveException { 76 this.proxiedRemoteBody = remoteBody; 79 if (logger.isDebugEnabled()) { 80 logger.debug(proxiedRemoteBody.getClass()); 81 } 82 try { 83 this.bodyID = remoteBody.getID(); 84 } catch (java.rmi.RemoteException e) { 85 throw new ProActiveException(e); 86 } 87 } 88 89 public RemoteBodyAdapter(UniversalBody body) throws ProActiveException { 90 try { 91 this.proxiedRemoteBody = new RemoteBodyImpl(body); 92 } catch (java.rmi.RemoteException e) { 93 throw new ProActiveException(e); 94 } 95 if (logger.isDebugEnabled()) { 96 logger.debug(proxiedRemoteBody.getClass()); 97 } 98 this.bodyID = body.getID(); 99 } 100 101 105 113 public static void register(RemoteBodyAdapter bodyAdapter, String url) 114 throws java.io.IOException { 115 java.rmi.Naming.rebind(url, bodyAdapter.proxiedRemoteBody); 116 } 117 118 123 public static void unregister(String url) throws java.io.IOException { 124 try { 125 java.rmi.Naming.unbind(url); 126 } catch (java.rmi.NotBoundException e) { 127 throw new java.io.IOException ( 128 "No object is bound to the given url : " + url); 129 } 130 } 131 132 141 public static UniversalBody lookup(String url) throws java.io.IOException { 142 Object o = null; 143 try { 145 o = java.rmi.Naming.lookup(url); 146 } catch (java.rmi.NotBoundException e) { 147 throw new java.io.IOException ("The url " + url + 148 " is not bound to any known object"); 149 } 150 if (o instanceof RemoteBody) { 151 try { 152 return new RemoteBodyAdapter((RemoteBody) o); 153 } catch (ProActiveException e) { 154 throw new java.io.IOException ("Cannot build a Remote Adapter" + 155 e.toString()); 156 } 157 } else { 158 throw new java.io.IOException ( 159 "The given url does exist but doesn't point to a remote body url=" + 160 url + " class found is " + o.getClass().getName()); 161 } 162 } 163 164 public boolean equals(Object o) { 165 if (!(o instanceof RemoteBodyAdapter)) { 166 return false; 167 } 168 RemoteBodyAdapter rba = (RemoteBodyAdapter) o; 169 return proxiedRemoteBody.equals(rba.proxiedRemoteBody); 170 } 171 172 public int hashCode() { 173 return proxiedRemoteBody.hashCode(); 174 } 175 176 public void receiveRequest(Request r) throws java.io.IOException , RenegotiateSessionException { 180 proxiedRemoteBody.receiveRequest(r); 181 } 182 183 public void receiveReply(Reply r) throws java.io.IOException { 184 proxiedRemoteBody.receiveReply(r); 185 } 186 187 public String getNodeURL() { 188 try { 189 return proxiedRemoteBody.getNodeURL(); 190 } catch (java.rmi.RemoteException e) { 191 return "cannot contact the body to get the nodeURL"; 192 } 193 } 194 195 public UniqueID getID() { 196 return bodyID; 197 } 198 199 public void updateLocation(UniqueID id, UniversalBody remoteBody) 200 throws java.io.IOException { 201 proxiedRemoteBody.updateLocation(id, remoteBody); 202 } 203 204 public UniversalBody getRemoteAdapter() { 205 return this; 206 } 207 208 public void enableAC() throws java.io.IOException { 209 proxiedRemoteBody.enableAC(); 210 } 211 212 public void disableAC() throws java.io.IOException { 213 proxiedRemoteBody.disableAC(); 214 } 215 216 public void setImmediateService(String methodName) 217 throws java.io.IOException { 218 proxiedRemoteBody.setImmediateService(methodName); 219 } 220 221 public void initiateSession(int type,UniversalBody body) 223 throws IOException , CommunicationForbiddenException, 224 AuthenticationException, RenegotiateSessionException, 225 SecurityNotAvailableException { 226 proxiedRemoteBody.initiateSession(type,body); 227 } 228 229 public void terminateSession(long sessionID) 230 throws java.io.IOException , SecurityNotAvailableException { 231 proxiedRemoteBody.terminateSession(sessionID); 232 } 233 234 public X509Certificate getCertificate() 235 throws java.io.IOException , SecurityNotAvailableException { 236 return proxiedRemoteBody.getCertificate(); 237 } 238 239 public ProActiveSecurityManager getProActiveSecurityManager() 240 throws java.io.IOException , SecurityNotAvailableException { 241 return proxiedRemoteBody.getProActiveSecurityManager(); 242 } 243 244 public Policy getPolicyFrom(X509Certificate certificate) 245 throws java.io.IOException , SecurityNotAvailableException { 246 return proxiedRemoteBody.getPolicyFrom(certificate); 247 } 248 249 public long startNewSession(Communication policy) 250 throws IOException , RenegotiateSessionException, 251 SecurityNotAvailableException { 252 return proxiedRemoteBody.startNewSession(policy); 253 } 254 255 public ConfidentialityTicket negociateKeyReceiverSide( 256 ConfidentialityTicket confidentialityTicket, long sessionID) 257 throws java.io.IOException , KeyExchangeException, 258 SecurityNotAvailableException { 259 return proxiedRemoteBody.negociateKeyReceiverSide(confidentialityTicket, 260 sessionID); 261 } 262 263 public PublicKey getPublicKey() 264 throws java.io.IOException , SecurityNotAvailableException { 265 return proxiedRemoteBody.getPublicKey(); 266 } 267 268 public byte[] randomValue(long sessionID, byte[] cl_rand) 269 throws Exception , SecurityNotAvailableException { 270 return proxiedRemoteBody.randomValue(sessionID, cl_rand); 271 } 272 273 public byte[][] publicKeyExchange(long sessionID, 274 UniversalBody distantBody, byte[] my_pub, byte[] my_cert, 275 byte[] sig_code) throws Exception , SecurityNotAvailableException { 276 return proxiedRemoteBody.publicKeyExchange(sessionID, distantBody, 277 my_pub, my_cert, sig_code); 278 } 279 280 public byte[][] secretKeyExchange(long sessionID, byte[] tmp, byte[] tmp1, 281 byte[] tmp2, byte[] tmp3, byte[] tmp4) 282 throws Exception , SecurityNotAvailableException { 283 return proxiedRemoteBody.secretKeyExchange(sessionID, tmp, tmp1, tmp2, 284 tmp3, tmp4); 285 } 286 287 public Communication getPolicyTo(String type, String from, String to) 288 throws java.io.IOException , SecurityNotAvailableException { 289 return proxiedRemoteBody.getPolicyTo(type, from, to); 290 } 291 292 295 public String getVNName() 296 throws java.io.IOException , SecurityNotAvailableException { 297 return proxiedRemoteBody.getVNName(); 298 } 299 300 303 public byte[] getCertificateEncoded() 304 throws java.io.IOException , SecurityNotAvailableException { 305 return proxiedRemoteBody.getCertificateEncoded(); 306 } 307 308 311 public SecurityContext getPolicy(SecurityContext securityContext) 312 throws SecurityNotAvailableException, IOException { 313 return proxiedRemoteBody.getPolicy(securityContext); 314 } 315 316 public ArrayList getEntities() throws SecurityNotAvailableException, IOException { 317 return proxiedRemoteBody.getEntities(); 318 } 319 320 321 } 325 | Popular Tags |