diff --git a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java index f322af0f2bc..9449210e897 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java +++ b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java @@ -25,6 +25,30 @@ package javax.management.remote.rmi; +import java.io.IOException; +import java.rmi.MarshalledObject; +import java.rmi.UnmarshalException; +import java.rmi.server.Unreferenced; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.security.ProtectionDomain; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import javax.management.*; +import javax.management.remote.JMXServerErrorException; +import javax.management.remote.NotificationResult; +import javax.management.remote.TargetedNotification; +import javax.security.auth.Subject; + import static com.sun.jmx.mbeanserver.Util.cast; import com.sun.jmx.remote.internal.ServerCommunicatorAdmin; import com.sun.jmx.remote.internal.ServerNotifForwarder; @@ -35,44 +59,6 @@ import com.sun.jmx.remote.util.ClassLogger; import com.sun.jmx.remote.util.EnvHelp; import com.sun.jmx.remote.util.OrderClassLoaders; -import java.io.IOException; -import java.rmi.MarshalledObject; -import java.rmi.UnmarshalException; -import java.rmi.server.Unreferenced; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.InvalidAttributeValueException; -import javax.management.ListenerNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanRegistrationException; -import javax.management.MBeanServer; -import javax.management.NotCompliantMBeanException; -import javax.management.NotificationFilter; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import javax.management.QueryExp; -import javax.management.ReflectionException; -import javax.management.RuntimeOperationsException; -import javax.management.remote.JMXServerErrorException; -import javax.management.remote.NotificationResult; -import javax.management.remote.TargetedNotification; -import javax.security.auth.Subject; - /** *

Implementation of the {@link RMIConnection} interface. User * code will not usually reference this class.

@@ -143,6 +129,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { this.mbeanServer = rmiServer.getMBeanServer(); final ClassLoader dcl = defaultClassLoader; + this.classLoaderWithRepository = AccessController.doPrivileged( new PrivilegedAction() { @@ -151,13 +138,29 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { mbeanServer.getClassLoaderRepository(), dcl); } - }); + }, + + withPermissions( new MBeanPermission("*", "getClassLoaderRepository"), + new RuntimePermission("createClassLoader")) + ); + serverCommunicatorAdmin = new RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env)); this.env = env; } + private static AccessControlContext withPermissions(Permission ... perms){ + Permissions col = new Permissions(); + + for (Permission thePerm : perms ) { + col.add(thePerm); + } + + final ProtectionDomain pd = new ProtectionDomain(null, col); + return new AccessControlContext( new ProtectionDomain[] { pd }); + } + private synchronized ServerNotifForwarder getServerNotifFwd() { // Lazily created when first use. Mainly when // addNotificationListener is first called. @@ -1330,7 +1333,9 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { public ClassLoader run() throws InstanceNotFoundException { return mbeanServer.getClassLoader(name); } - }); + }, + withPermissions(new MBeanPermission("*", "getClassLoader")) + ); } catch (PrivilegedActionException pe) { throw (InstanceNotFoundException) extractException(pe); } @@ -1345,7 +1350,9 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced { public Object run() throws InstanceNotFoundException { return mbeanServer.getClassLoaderFor(name); } - }); + }, + withPermissions(new MBeanPermission("*", "getClassLoaderFor")) + ); } catch (PrivilegedActionException pe) { throw (InstanceNotFoundException) extractException(pe); }