1 7 8 package javax.management.remote.rmi; 9 10 import java.io.IOException ; 11 import java.rmi.Remote ; 12 import java.security.AccessControlContext ; 13 import java.security.AccessController ; 14 import java.security.PrivilegedActionException ; 15 import java.security.PrivilegedExceptionAction ; 16 import java.util.Map ; 17 import java.util.Collections ; 18 import javax.rmi.PortableRemoteObject ; 19 import javax.security.auth.Subject ; 20 21 31 public class RMIIIOPServerImpl extends RMIServerImpl { 32 41 public RMIIIOPServerImpl(Map <String ,?> env) 42 throws IOException { 43 super(env); 44 45 this.env = (env == null) ? Collections.EMPTY_MAP : env; 46 47 callerACC = AccessController.getContext(); 48 } 49 50 protected void export() throws IOException { 51 PortableRemoteObject.exportObject(this); 52 } 53 54 protected String getProtocol() { 55 return "iiop"; 56 } 57 58 66 public Remote toStub() throws IOException { 67 final Remote stub = PortableRemoteObject.toStub(this); 70 return (Remote ) stub; 76 } 77 78 94 protected RMIConnection makeClient(String connectionId, Subject subject) 95 throws IOException { 96 97 if (connectionId == null) 98 throw new NullPointerException ("Null connectionId"); 99 100 RMIConnection client = 101 new RMIConnectionImpl (this, connectionId, getDefaultClassLoader(), 102 subject, env); 103 PortableRemoteObject.exportObject(client); 104 return client; 105 } 106 107 protected void closeClient(RMIConnection client) throws IOException { 108 PortableRemoteObject.unexportObject(client); 109 } 110 111 119 protected void closeServer() throws IOException { 120 PortableRemoteObject.unexportObject(this); 121 } 122 123 @Override 124 RMIConnection doNewClient(final Object credentials) throws IOException { 125 if (callerACC == null) { 126 throw new SecurityException ("AccessControlContext cannot be null"); 127 } 128 try { 129 return AccessController.doPrivileged( 130 new PrivilegedExceptionAction <RMIConnection >() { 131 public RMIConnection run() throws IOException { 132 return superDoNewClient(credentials); 133 } 134 }, callerACC); 135 } catch (PrivilegedActionException pae) { 136 throw (IOException ) pae.getCause(); 137 } 138 } 139 140 RMIConnection superDoNewClient(Object credentials) throws IOException { 141 return super.doNewClient(credentials); 142 } 143 144 private final Map env; 145 private final AccessControlContext callerACC; 146 } 147 | Popular Tags |