📄 mbeanserveraccesscontroller.java
字号:
/** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public ClassLoaderRepository getClassLoaderRepository() { checkRead(); return getMBeanServer().getClassLoaderRepository(); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public String getDefaultDomain() { checkRead(); return getMBeanServer().getDefaultDomain(); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public String[] getDomains() { checkRead(); return getMBeanServer().getDomains(); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public Integer getMBeanCount() { checkRead(); return getMBeanServer().getMBeanCount(); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException { checkRead(); return getMBeanServer().getMBeanInfo(name); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException { checkRead(); return getMBeanServer().getObjectInstance(name); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public Object instantiate(String className) throws ReflectionException, MBeanException { checkWrite(); return getMBeanServer().instantiate(className); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public Object instantiate(String className, Object params[], String signature[]) throws ReflectionException, MBeanException { checkWrite(); return getMBeanServer().instantiate(className, params, signature); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public Object instantiate(String className, ObjectName loaderName) throws ReflectionException, MBeanException, InstanceNotFoundException { checkWrite(); return getMBeanServer().instantiate(className, loaderName); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public Object instantiate(String className, ObjectName loaderName, Object params[], String signature[]) throws ReflectionException, MBeanException, InstanceNotFoundException { checkWrite(); return getMBeanServer().instantiate(className, loaderName, params, signature); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public Object invoke(ObjectName name, String operationName, Object params[], String signature[]) throws InstanceNotFoundException, MBeanException, ReflectionException { checkWrite(); checkMLetMethods(name, operationName); return getMBeanServer().invoke(name, operationName, params, signature); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException { checkRead(); return getMBeanServer().isInstanceOf(name, className); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public boolean isRegistered(ObjectName name) { checkRead(); return getMBeanServer().isRegistered(name); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public Set queryMBeans(ObjectName name, QueryExp query) { checkRead(); return getMBeanServer().queryMBeans(name, query); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public Set queryNames(ObjectName name, QueryExp query) { checkRead(); return getMBeanServer().queryNames(name, query); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { checkWrite(); return getMBeanServer().registerMBean(object, name); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException { checkRead(); getMBeanServer().removeNotificationListener(name, listener); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException { checkRead(); getMBeanServer().removeNotificationListener(name, listener, filter, handback); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException { checkRead(); getMBeanServer().removeNotificationListener(name, listener); } /** * Call <code>checkRead()</code>, then forward this method to the * wrapped object. */ public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException { checkRead(); getMBeanServer().removeNotificationListener(name, listener, filter, handback); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { checkWrite(); getMBeanServer().setAttribute(name, attribute); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException { checkWrite(); return getMBeanServer().setAttributes(name, attributes); } /** * Call <code>checkWrite()</code>, then forward this method to the * wrapped object. */ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException { checkWrite(); getMBeanServer().unregisterMBean(name); } //---------------- // PRIVATE METHODS //---------------- private void checkClassLoader(Object object) { if (object instanceof ClassLoader) throw new SecurityException("Access denied! Creating an " + "MBean that is a ClassLoader " + "is forbidden unless a security " + "manager is installed."); } private void checkMLetMethods(ObjectName name, String operation) throws InstanceNotFoundException { // Check if security manager installed SecurityManager sm = System.getSecurityManager(); if (sm != null) { return; } // Check for addURL and getMBeansFromURL methods if (!operation.equals("addURL") && !operation.equals("getMBeansFromURL")) { return; } // Check if MBean is instance of MLet if (!getMBeanServer().isInstanceOf(name, "javax.management.loading.MLet")) { return; } // Throw security exception if (operation.equals("addURL")) { // addURL throw new SecurityException("Access denied! MLet method addURL " + "cannot be invoked unless a security manager is installed."); } else { // getMBeansFromURL // Whether or not calling getMBeansFromURL is allowed is controlled // by the value of the "jmx.remote.x.mlet.allow.getMBeansFromURL" // system property. If the value of this property is true, calling // the MLet's getMBeansFromURL method is allowed. The default value // for this property is false. final String propName = "jmx.remote.x.mlet.allow.getMBeansFromURL"; GetPropertyAction propAction = new GetPropertyAction(propName); String propValue = (String) AccessController.doPrivileged(propAction); boolean allowGetMBeansFromURL = "true".equalsIgnoreCase(propValue); if (!allowGetMBeansFromURL) { throw new SecurityException("Access denied! MLet method " + "getMBeansFromURL cannot be invoked unless a " + "security manager is installed or the system property " + "-Djmx.remote.x.mlet.allow.getMBeansFromURL=true " + "is specified."); } } } //------------------ // PRIVATE VARIABLES //------------------ private MBeanServer mbs;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -