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 java.util.Iterator; |
28 import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; |
29 import java.util.logging.Level; |
29 import com.sun.jmx.interceptor.NamespaceDispatchInterceptor; |
30 import java.util.Set; |
30 |
31 import java.io.ObjectInputStream; |
31 import java.io.ObjectInputStream; |
32 import java.security.AccessController; |
32 import java.security.AccessController; |
33 import java.security.Permission; |
33 import java.security.Permission; |
34 import java.security.PrivilegedExceptionAction; |
34 import java.security.PrivilegedExceptionAction; |
35 |
35 import java.util.Iterator; |
36 // RI import |
36 import java.util.Set; |
37 import javax.management.MBeanPermission; |
37 import java.util.logging.Level; |
38 import javax.management.AttributeNotFoundException; |
38 |
39 import javax.management.MBeanException; |
|
40 import javax.management.ReflectionException; |
|
41 import javax.management.MBeanInfo; |
|
42 import javax.management.QueryExp; |
|
43 import javax.management.NotificationListener; |
|
44 import javax.management.NotificationFilter; |
|
45 import javax.management.ListenerNotFoundException; |
|
46 import javax.management.IntrospectionException; |
|
47 import javax.management.OperationsException; |
|
48 import javax.management.InstanceNotFoundException; |
|
49 import javax.management.NotCompliantMBeanException; |
|
50 import javax.management.MBeanRegistrationException; |
|
51 import javax.management.InstanceAlreadyExistsException; |
|
52 import javax.management.InvalidAttributeValueException; |
|
53 import javax.management.ObjectName; |
|
54 import javax.management.ObjectInstance; |
|
55 import javax.management.Attribute; |
39 import javax.management.Attribute; |
56 import javax.management.AttributeList; |
40 import javax.management.AttributeList; |
57 import javax.management.RuntimeOperationsException; |
41 import javax.management.AttributeNotFoundException; |
|
42 import javax.management.InstanceAlreadyExistsException; |
|
43 import javax.management.InstanceNotFoundException; |
|
44 import javax.management.IntrospectionException; |
|
45 import javax.management.InvalidAttributeValueException; |
|
46 import javax.management.ListenerNotFoundException; |
|
47 import javax.management.MBeanException; |
|
48 import javax.management.MBeanInfo; |
|
49 import javax.management.MBeanPermission; |
|
50 import javax.management.MBeanRegistrationException; |
58 import javax.management.MBeanServer; |
51 import javax.management.MBeanServer; |
59 import javax.management.MBeanServerDelegate; |
52 import javax.management.MBeanServerDelegate; |
|
53 import javax.management.NotCompliantMBeanException; |
|
54 import javax.management.NotificationFilter; |
|
55 import javax.management.NotificationListener; |
|
56 import javax.management.ObjectInstance; |
|
57 import javax.management.ObjectName; |
|
58 import javax.management.OperationsException; |
|
59 import javax.management.QueryExp; |
|
60 import javax.management.ReflectionException; |
|
61 import javax.management.RuntimeOperationsException; |
60 import javax.management.loading.ClassLoaderRepository; |
62 import javax.management.loading.ClassLoaderRepository; |
61 |
|
62 import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; |
|
63 import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor; |
|
64 import com.sun.jmx.interceptor.MBeanServerInterceptor; |
|
65 |
63 |
66 /** |
64 /** |
67 * This is the base class for MBean manipulation on the agent side. It |
65 * This is the base class for MBean manipulation on the agent side. It |
68 * contains the methods necessary for the creation, registration, and |
66 * contains the methods necessary for the creation, registration, and |
69 * deletion of MBeans as well as the access methods for registered MBeans. |
67 * deletion of MBeans as well as the access methods for registered MBeans. |
100 private final SecureClassLoaderRepository secureClr; |
98 private final SecureClassLoaderRepository secureClr; |
101 |
99 |
102 /** true if interceptors are enabled **/ |
100 /** true if interceptors are enabled **/ |
103 private final boolean interceptorsEnabled; |
101 private final boolean interceptorsEnabled; |
104 |
102 |
105 /** Revisit: transient ??? **/ |
103 private final MBeanServer outerShell; |
106 private final transient MBeanServer outerShell; |
104 |
107 |
105 private volatile MBeanServer mbsInterceptor = null; |
108 /** Revisit: transient ??? **/ |
106 |
109 private transient MBeanServerInterceptor mbsInterceptor = null; |
|
110 |
|
111 /** Revisit: transient ??? **/ |
|
112 /** The MBeanServerDelegate object representing the MBean Server */ |
107 /** The MBeanServerDelegate object representing the MBean Server */ |
113 private final transient MBeanServerDelegate mBeanServerDelegateObject; |
108 private final MBeanServerDelegate mBeanServerDelegateObject; |
|
109 |
|
110 private final String mbeanServerName; |
114 |
111 |
115 /** |
112 /** |
116 * <b>Package:</b> Creates an MBeanServer with the |
113 * <b>Package:</b> Creates an MBeanServer with the |
117 * specified default domain name, outer interface, and delegate. |
114 * specified default domain name, outer interface, and delegate. |
118 * <p>The default domain name is used as the domain part in the ObjectName |
115 * <p>The default domain name is used as the domain part in the ObjectName |
241 this.mBeanServerDelegateObject = delegate; |
238 this.mBeanServerDelegateObject = delegate; |
242 this.outerShell = outer; |
239 this.outerShell = outer; |
243 |
240 |
244 final Repository repository = new Repository(domain,fairLock); |
241 final Repository repository = new Repository(domain,fairLock); |
245 this.mbsInterceptor = |
242 this.mbsInterceptor = |
246 new DefaultMBeanServerInterceptor(outer, delegate, instantiator, |
243 new NamespaceDispatchInterceptor(outer, delegate, instantiator, |
247 repository); |
244 repository); |
248 this.interceptorsEnabled = interceptors; |
245 this.interceptorsEnabled = interceptors; |
|
246 this.mbeanServerName = Util.getMBeanServerSecurityName(delegate); |
249 initialize(); |
247 initialize(); |
250 } |
248 } |
251 |
249 |
252 /** |
250 /** |
253 * Tell whether {@link MBeanServerInterceptor}s are enabled on this |
251 * Tell whether {@link MBeanServerInterceptor}s are enabled on this |
976 public Object instantiate(String className, ObjectName loaderName) |
975 public Object instantiate(String className, ObjectName loaderName) |
977 throws ReflectionException, MBeanException, |
976 throws ReflectionException, MBeanException, |
978 InstanceNotFoundException { |
977 InstanceNotFoundException { |
979 |
978 |
980 /* Permission check */ |
979 /* Permission check */ |
981 checkMBeanPermission(className, null, null, "instantiate"); |
980 checkMBeanPermission(mbeanServerName, className, null, |
|
981 null, "instantiate"); |
982 |
982 |
983 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
983 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
984 return instantiator.instantiate(className, loaderName, myLoader); |
984 return instantiator.instantiate(className, loaderName, myLoader); |
985 } |
985 } |
986 |
986 |
1014 public Object instantiate(String className, Object params[], |
1014 public Object instantiate(String className, Object params[], |
1015 String signature[]) |
1015 String signature[]) |
1016 throws ReflectionException, MBeanException { |
1016 throws ReflectionException, MBeanException { |
1017 |
1017 |
1018 /* Permission check */ |
1018 /* Permission check */ |
1019 checkMBeanPermission(className, null, null, "instantiate"); |
1019 checkMBeanPermission(mbeanServerName, className, null, null, |
|
1020 "instantiate"); |
1020 |
1021 |
1021 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
1022 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
1022 return instantiator.instantiate(className, params, signature, |
1023 return instantiator.instantiate(className, params, signature, |
1023 myLoader); |
1024 myLoader); |
1024 } |
1025 } |
1057 Object params[], String signature[]) |
1058 Object params[], String signature[]) |
1058 throws ReflectionException, MBeanException, |
1059 throws ReflectionException, MBeanException, |
1059 InstanceNotFoundException { |
1060 InstanceNotFoundException { |
1060 |
1061 |
1061 /* Permission check */ |
1062 /* Permission check */ |
1062 checkMBeanPermission(className, null, null, "instantiate"); |
1063 checkMBeanPermission(mbeanServerName, className, null, |
|
1064 null, "instantiate"); |
1063 |
1065 |
1064 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
1066 ClassLoader myLoader = outerShell.getClass().getClassLoader(); |
1065 return instantiator.instantiate(className,loaderName,params,signature, |
1067 return instantiator.instantiate(className,loaderName,params,signature, |
1066 myLoader); |
1068 myLoader); |
1067 } |
1069 } |
1290 * {@link MBeanServerInterceptor}s |
1292 * {@link MBeanServerInterceptor}s |
1291 * are not enabled on this object. |
1293 * are not enabled on this object. |
1292 * @see #interceptorsEnabled |
1294 * @see #interceptorsEnabled |
1293 **/ |
1295 **/ |
1294 public synchronized void |
1296 public synchronized void |
1295 setMBeanServerInterceptor(MBeanServerInterceptor interceptor) { |
1297 setMBeanServerInterceptor(MBeanServer interceptor) { |
1296 if (!interceptorsEnabled) throw new UnsupportedOperationException( |
1298 if (!interceptorsEnabled) throw new UnsupportedOperationException( |
1297 "MBeanServerInterceptors are disabled."); |
1299 "MBeanServerInterceptors are disabled."); |
1298 if (interceptor == null) throw new |
1300 if (interceptor == null) throw new |
1299 IllegalArgumentException("MBeanServerInterceptor is null"); |
1301 IllegalArgumentException("MBeanServerInterceptor is null"); |
1300 mbsInterceptor = interceptor; |
1302 mbsInterceptor = interceptor; |
1328 * <p>Return the ClassLoaderRepository for that MBeanServer. |
1330 * <p>Return the ClassLoaderRepository for that MBeanServer. |
1329 * @return The ClassLoaderRepository for that MBeanServer. |
1331 * @return The ClassLoaderRepository for that MBeanServer. |
1330 **/ |
1332 **/ |
1331 public ClassLoaderRepository getClassLoaderRepository() { |
1333 public ClassLoaderRepository getClassLoaderRepository() { |
1332 /* Permission check */ |
1334 /* Permission check */ |
1333 checkMBeanPermission(null, null, null, "getClassLoaderRepository"); |
1335 checkMBeanPermission(mbeanServerName, null, null, |
|
1336 null, "getClassLoaderRepository"); |
1334 return secureClr; |
1337 return secureClr; |
1335 } |
1338 } |
1336 |
1339 |
1337 public MBeanServerDelegate getMBeanServerDelegate() { |
1340 public MBeanServerDelegate getMBeanServerDelegate() { |
1338 if (!interceptorsEnabled) throw new UnsupportedOperationException( |
1341 if (!interceptorsEnabled) throw new UnsupportedOperationException( |