defaultmbeanserverinterceptor.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,774 行 · 第 1/4 页
JAVA
1,774 行
checkMBeanPermission(null, null, null, "queryMBeans"); // Perform query without "query". // Set list = queryMBeansImpl(name, null); // Check if the caller has the right to invoke 'queryMBeans' // on each specific classname/objectname in the list. // Set allowedList = new HashSet(list.size()); for (Iterator i = list.iterator(); i.hasNext(); ) { try { ObjectInstance oi = (ObjectInstance) i.next(); checkMBeanPermission(oi.getClassName(), null, oi.getObjectName(), "queryMBeans"); allowedList.add(oi); } catch (SecurityException e) { // OK: Do not add this ObjectInstance to the list } } // Apply query to allowed MBeans only. // return filterListOfObjectInstances(allowedList, query); } else { // Perform query. // return queryMBeansImpl(name, query); } } private Set queryMBeansImpl(ObjectName name, QueryExp query) { // Query the MBeans on the repository // Set list = null; synchronized(this) { list = repository.query(name, query); } // The repository performs the filtering // if (queryByRepo) { return list; } else { // The filtering will be performed by the MBeanServer // return (filterListOfObjects(list, query)); } } public Set queryNames(ObjectName name, QueryExp query) { /* Permission check */ SecurityManager sm = System.getSecurityManager(); if (sm != null) { // Check if the caller has the right to invoke 'queryNames' // checkMBeanPermission(null, null, null, "queryNames"); // Perform query without "query". // Set list = queryMBeansImpl(name, null); // Check if the caller has the right to invoke 'queryNames' // on each specific classname/objectname in the list. // Set allowedList = new HashSet(list.size()); for (Iterator i = list.iterator(); i.hasNext(); ) { try { ObjectInstance oi = (ObjectInstance) i.next(); checkMBeanPermission(oi.getClassName(), null, oi.getObjectName(), "queryNames"); allowedList.add(oi); } catch (SecurityException e) { // OK: Do not add this ObjectInstance to the list } } // Apply query to allowed MBeans only. // Set queryList = filterListOfObjectInstances(allowedList, query); Set result = new HashSet(queryList.size()); for (Iterator i = queryList.iterator(); i.hasNext(); ) { ObjectInstance oi = (ObjectInstance) i.next(); result.add(oi.getObjectName()); } return result; } else { // Perform query. // Set queryList = queryMBeansImpl(name, query); Set result = new HashSet(queryList.size()); for (Iterator i = queryList.iterator(); i.hasNext(); ) { ObjectInstance oi = (ObjectInstance) i.next(); result.add(oi.getObjectName()); } return result; } } public boolean isRegistered(ObjectName name) { if (name == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Object name cannot be null"), "Object name cannot be null"); } name = nonDefaultDomain(name);// /* Permission check */// checkMBeanPermission(null, null, name, "isRegistered"); synchronized(this) { return (repository.contains(name)); } } public String[] getDomains() { /* Permission check */ SecurityManager sm = System.getSecurityManager(); if (sm != null) { // Check if the caller has the right to invoke 'getDomains' // checkMBeanPermission(null, null, null, "getDomains"); // Return domains // String[] domains = repository.getDomains(); // Check if the caller has the right to invoke 'getDomains' // on each specific domain in the list. // ArrayList result = new ArrayList(domains.length); for (int i = 0; i < domains.length; i++) { try { ObjectName domain = new ObjectName(domains[i] + ":x=x"); checkMBeanPermission(null, null, domain, "getDomains"); result.add(domains[i]); } catch (MalformedObjectNameException e) { // Should never occur... But let's log it just in case. error("getDomains", "Failed to check permission for domain=" + domains[i] + ". Error is: " + e); debugX("getDomains",e); } catch (SecurityException e) { // OK: Do not add this domain to the list } } // Make an array from result. // return (String[]) result.toArray(new String[result.size()]); } else { return repository.getDomains(); } } public Integer getMBeanCount() { return (repository.getCount()); } public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Object name cannot be null"), "Exception occured trying to invoke the getter on the MBean"); } if (attribute == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occured trying to invoke the getter on the MBean"); } name = nonDefaultDomain(name); if (isTraceOn()) { trace("getAttribute", "Attribute= " + attribute + ", obj= " + name); } /* Permission check */ Object instance = getMBean(name); String classname = null; try { classname = meta.getMBeanClassName(instance); } catch (IntrospectionException e) { classname = null; } catch (NotCompliantMBeanException e) { classname = null; } checkMBeanPermission(classname, attribute, name, "getAttribute"); return meta.getAttribute(instance, attribute); } public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occured trying to invoke the getter on the MBean"); } if (attributes == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attributes cannot be null"), "Exception occured trying to invoke the getter on the MBean"); } name = nonDefaultDomain(name); if (isTraceOn()) { trace("getAttributes", "Object= " + name); } Object instance = getMBean(name); SecurityManager sm = System.getSecurityManager(); if (sm != null) { /* Permission check */ String classname = null; try { classname = meta.getMBeanClassName(instance); } catch (IntrospectionException e) { classname = null; } catch (NotCompliantMBeanException e) { classname = null; } // Check if the caller has the right to invoke 'getAttribute' // checkMBeanPermission(classname, null, name, "getAttribute"); // Check if the caller has the right to invoke 'getAttribute' // on each specific attribute // ArrayList allowedList = new ArrayList(attributes.length); for (int i = 0; i < attributes.length; i++) { try { checkMBeanPermission(classname, attributes[i], name, "getAttribute"); allowedList.add(attributes[i]); } catch (SecurityException e) { // OK: Do not add this attribute to the list } } String[] allowedAttributes = (String[]) allowedList.toArray(new String[0]); return meta.getAttributes(instance, allowedAttributes); } else { return meta.getAttributes(instance, attributes); } } public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occured trying to invoke the setter on the MBean"); } if (attribute == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occured trying to invoke the setter on the MBean"); } name = nonDefaultDomain(name); if (isTraceOn()) { trace("setAttribute", "Object= " + name + ", attribute=" + attribute.getName()); } /* Permission check */ Object instance = getMBean(name); String classname = null; try { classname = meta.getMBeanClassName(instance); } catch (IntrospectionException e) { classname = null; } catch (NotCompliantMBeanException e) { classname = null; } checkMBeanPermission(classname, attribute.getName(), name, "setAttribute"); final Object o = meta.setAttribute(instance, attribute); } public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occured trying to invoke the setter on the MBean"); } if (attributes == null) { throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList cannot be null"), "Exception occured trying to invoke the setter on the MBean"); } name = nonDefaultDomain(name); Object instance = getMBean(name); SecurityManager sm = System.getSecurityManager(); if (sm != null) { /* Permission check */ String classname = null; try { classname = meta.getMBeanClassName(instance); } catch (IntrospectionException e) { classname = null; } catch (NotCompliantMBeanException e) { classname = null; } // Check if the caller has the right to invoke 'setAttribute' // checkMBeanPermission(classname, null, name, "setAttribute"); // Check if the caller has the right to invoke 'setAttribute' // on each specific attribute // AttributeList allowedAttributes = new AttributeList(attributes.size()); for (Iterator i = attributes.iterator(); i.hasNext();) { try { Attribute attribute = (Attribute) i.next(); checkMBeanPermission(classname, attribute.getName(), name, "setAttribute"); allowedAttributes.add(attribute); } catch (SecurityException e) { // OK: Do not add this attribute to the list } } return meta.setAttributes(instance, allowedAttributes); } else { return meta.setAttributes(instance, attributes); } } public Object invoke(ObjectName name, String operationName, Object params[], String signature[]) throws InstanceNotFoundException, MBeanException, ReflectionException { name = nonDefaultDomain(name); /* Permission check */ Object instance = getMBean(name); String classname = null; try { classname = meta.getMBeanClassName(instance); } catch (IntrospectionException e) { classname = null; } catch (NotCompliantMBeanException e) { classname = null; } checkMBeanPermission(classname, operationName, name, "invoke"); return meta.invoke(instance, operationName, params, signature); } /** * Return the MetaData service object used by this interceptor. * **/ protected MetaData meta() { return meta; } /** * Builds an ObjectInstance. * <ul> * <li> If the given <code>object</code> implements DynamicMBean, * then ask its MBeanInfo for the class name.</li> * <li> Otherwise, uses the provided <code>className</code></li> * </ul> * * @return A new ObjectInstance for the given <code>object</code>. * @exception NotCompliantMBeanException if the <code>object</code> * implements DynamicMBean but the class name can't be * retrieved from its MBeanInfo. **/ protected ObjectInstance makeObjectInstance(String className, Object object, ObjectName name) throws NotCompliantMBeanException { // if the MBean is a dynamic MBean ask its MBeanInfo for the // class name if (object instanceof DynamicMBean) { try { className = meta.getMBeanClassName(object); } catch (SecurityException x) { debugX("makeObjectInstance",x); throw x; } catch (IntrospectionException x) { debugX("makeObjectInstance",x); throw new NotCompliantMBeanException( "Can't obtain class name for " + name + ": " + x); } catch (JMRuntimeException x) { debugX("makeObjectInstance",x); throw new NotCompliantMBeanException( "Can't obtain class name for " + name + ": " + x); } } if (className == null) { throw new NotCompliantMBeanException( "The class Name returned is null"); } return(new ObjectInstance(nonDefaultDomain(name), className)); } /** * Register <code>object</code> in the repository, with the * given <code>name</code>. * This method is called by the various createMBean() flavours * and by registerMBean() after all MBean compliance tests * have been performed. * <p> * This method does not performed any kind of test compliance, * and the caller should make sure that the given <code>object</object> * is MBean compliant. * <p> * This methods performed all the basic steps needed for object * registration: * <ul> * <li>If the <code>object</code> implements the MBeanRegistration * interface, it invokes preRegister() on the object.</li> * <li>Then the object is added to the repository with the given * <code>name</code>.</li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?