jdk/src/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java
changeset 4156 acaa49a2768a
parent 1570 4165709c91e3
child 5506 202f599c92aa
equal deleted inserted replaced
4155:460e37d40f12 4156:acaa49a2768a
    23  * have any questions.
    23  * have any questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.jmx.mbeanserver;
    26 package com.sun.jmx.mbeanserver;
    27 
    27 
       
    28 import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
       
    29 import com.sun.jmx.interceptor.MBeanServerInterceptor;
    28 import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
    30 import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
    29 import com.sun.jmx.interceptor.NamespaceDispatchInterceptor;
       
    30 
    31 
    31 import java.io.ObjectInputStream;
    32 import java.io.ObjectInputStream;
    32 import java.security.AccessController;
    33 import java.security.AccessController;
    33 import java.security.Permission;
    34 import java.security.Permission;
    34 import java.security.PrivilegedExceptionAction;
    35 import java.security.PrivilegedExceptionAction;
    35 import java.util.Iterator;
       
    36 import java.util.List;
    36 import java.util.List;
    37 import java.util.Set;
    37 import java.util.Set;
    38 import java.util.logging.Level;
    38 import java.util.logging.Level;
    39 
    39 
    40 import javax.management.Attribute;
    40 import javax.management.Attribute;
   106     private volatile MBeanServer mbsInterceptor = null;
   106     private volatile MBeanServer mbsInterceptor = null;
   107 
   107 
   108     /** The MBeanServerDelegate object representing the MBean Server */
   108     /** The MBeanServerDelegate object representing the MBean Server */
   109     private final MBeanServerDelegate mBeanServerDelegateObject;
   109     private final MBeanServerDelegate mBeanServerDelegateObject;
   110 
   110 
   111     private final String mbeanServerName;
       
   112 
       
   113     /**
   111     /**
   114      * <b>Package:</b> Creates an MBeanServer with the
   112      * <b>Package:</b> Creates an MBeanServer with the
   115      * specified default domain name, outer interface, and delegate.
   113      * specified default domain name, outer interface, and delegate.
   116      * <p>The default domain name is used as the domain part in the ObjectName
   114      * <p>The default domain name is used as the domain part in the ObjectName
   117      * of MBeans if no domain is specified by the user.
   115      * of MBeans if no domain is specified by the user.
   239         this.mBeanServerDelegateObject = delegate;
   237         this.mBeanServerDelegateObject = delegate;
   240         this.outerShell   = outer;
   238         this.outerShell   = outer;
   241 
   239 
   242         final Repository repository = new Repository(domain);
   240         final Repository repository = new Repository(domain);
   243         this.mbsInterceptor =
   241         this.mbsInterceptor =
   244             new NamespaceDispatchInterceptor(outer, delegate, instantiator,
   242             new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
   245                                               repository);
   243                                               repository);
   246         this.interceptorsEnabled = interceptors;
   244         this.interceptorsEnabled = interceptors;
   247         this.mbeanServerName = Util.getMBeanServerSecurityName(delegate);
       
   248         initialize();
   245         initialize();
   249     }
   246     }
   250 
   247 
   251     /**
   248     /**
   252      * Tell whether {@link MBeanServerInterceptor}s are enabled on this
   249      * Tell whether {@link MBeanServerInterceptor}s are enabled on this
   938      */
   935      */
   939     public Object instantiate(String className)
   936     public Object instantiate(String className)
   940         throws ReflectionException, MBeanException {
   937         throws ReflectionException, MBeanException {
   941 
   938 
   942         /* Permission check */
   939         /* Permission check */
   943         checkMBeanPermission(mbeanServerName, className, null, null,
   940         checkMBeanPermission(className, null, null, "instantiate");
   944                 "instantiate");
       
   945 
   941 
   946         return instantiator.instantiate(className);
   942         return instantiator.instantiate(className);
   947     }
   943     }
   948 
   944 
   949     /**
   945     /**
   976     public Object instantiate(String className, ObjectName loaderName)
   972     public Object instantiate(String className, ObjectName loaderName)
   977         throws ReflectionException, MBeanException,
   973         throws ReflectionException, MBeanException,
   978                InstanceNotFoundException {
   974                InstanceNotFoundException {
   979 
   975 
   980         /* Permission check */
   976         /* Permission check */
   981         checkMBeanPermission(mbeanServerName, className, null,
   977         checkMBeanPermission(className, null, null, "instantiate");
   982                 null, "instantiate");
       
   983 
   978 
   984         ClassLoader myLoader = outerShell.getClass().getClassLoader();
   979         ClassLoader myLoader = outerShell.getClass().getClassLoader();
   985         return instantiator.instantiate(className, loaderName, myLoader);
   980         return instantiator.instantiate(className, loaderName, myLoader);
   986     }
   981     }
   987 
   982 
  1015     public Object instantiate(String className, Object params[],
  1010     public Object instantiate(String className, Object params[],
  1016                               String signature[])
  1011                               String signature[])
  1017         throws ReflectionException, MBeanException {
  1012         throws ReflectionException, MBeanException {
  1018 
  1013 
  1019         /* Permission check */
  1014         /* Permission check */
  1020         checkMBeanPermission(mbeanServerName, className, null, null,
  1015         checkMBeanPermission(className, null, null, "instantiate");
  1021                 "instantiate");
       
  1022 
  1016 
  1023         ClassLoader myLoader = outerShell.getClass().getClassLoader();
  1017         ClassLoader myLoader = outerShell.getClass().getClassLoader();
  1024         return instantiator.instantiate(className, params, signature,
  1018         return instantiator.instantiate(className, params, signature,
  1025                                         myLoader);
  1019                                         myLoader);
  1026     }
  1020     }
  1059                               Object params[], String signature[])
  1053                               Object params[], String signature[])
  1060         throws ReflectionException, MBeanException,
  1054         throws ReflectionException, MBeanException,
  1061                InstanceNotFoundException {
  1055                InstanceNotFoundException {
  1062 
  1056 
  1063         /* Permission check */
  1057         /* Permission check */
  1064         checkMBeanPermission(mbeanServerName, className, null,
  1058         checkMBeanPermission(className, null, null, "instantiate");
  1065                 null, "instantiate");
       
  1066 
  1059 
  1067         ClassLoader myLoader = outerShell.getClass().getClassLoader();
  1060         ClassLoader myLoader = outerShell.getClass().getClassLoader();
  1068         return instantiator.instantiate(className,loaderName,params,signature,
  1061         return instantiator.instantiate(className,loaderName,params,signature,
  1069                                         myLoader);
  1062                                         myLoader);
  1070     }
  1063     }
  1331      * <p>Return the ClassLoaderRepository for that MBeanServer.
  1324      * <p>Return the ClassLoaderRepository for that MBeanServer.
  1332      * @return The ClassLoaderRepository for that MBeanServer.
  1325      * @return The ClassLoaderRepository for that MBeanServer.
  1333      **/
  1326      **/
  1334     public ClassLoaderRepository getClassLoaderRepository() {
  1327     public ClassLoaderRepository getClassLoaderRepository() {
  1335         /* Permission check */
  1328         /* Permission check */
  1336         checkMBeanPermission(mbeanServerName, null, null,
  1329         checkMBeanPermission(null, null, null, "getClassLoaderRepository");
  1337                 null, "getClassLoaderRepository");
       
  1338         return secureClr;
  1330         return secureClr;
  1339     }
  1331     }
  1340 
  1332 
  1341     public MBeanServerDelegate getMBeanServerDelegate() {
  1333     public MBeanServerDelegate getMBeanServerDelegate() {
  1342         if (!interceptorsEnabled) throw new UnsupportedOperationException(
  1334         if (!interceptorsEnabled) throw new UnsupportedOperationException(
  1485     }
  1477     }
  1486 
  1478 
  1487     // SECURITY CHECKS
  1479     // SECURITY CHECKS
  1488     //----------------
  1480     //----------------
  1489 
  1481 
  1490     private static void checkMBeanPermission(String serverName,
  1482     private static void checkMBeanPermission(String classname,
  1491                                              String classname,
       
  1492                                              String member,
  1483                                              String member,
  1493                                              ObjectName objectName,
  1484                                              ObjectName objectName,
  1494                                              String actions)
  1485                                              String actions)
  1495         throws SecurityException {
  1486         throws SecurityException {
  1496         SecurityManager sm = System.getSecurityManager();
  1487         SecurityManager sm = System.getSecurityManager();
  1497         if (sm != null) {
  1488         if (sm != null) {
  1498             Permission perm = new MBeanPermission(serverName,
  1489             Permission perm = new MBeanPermission(classname,
  1499                                                   classname,
       
  1500                                                   member,
  1490                                                   member,
  1501                                                   objectName,
  1491                                                   objectName,
  1502                                                   actions);
  1492                                                   actions);
  1503             sm.checkPermission(perm);
  1493             sm.checkPermission(perm);
  1504         }
  1494         }