Search in sources :

Example 11 with IntrospectionException

use of javax.management.IntrospectionException in project jdk8u_jdk by JetBrains.

the class Monitor method getAttribute.

Object getAttribute(MBeanServerConnection mbsc, ObjectName object, String attribute) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    // Check for "ObservedAttribute" replacement.
    // This could happen if a thread A called setObservedAttribute()
    // while other thread B was in the middle of the monitor() method
    // and received the old observed attribute value.
    //
    final boolean lookupMBeanInfo;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException("The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException("The observed attribute has been changed");
        lookupMBeanInfo = (firstAttribute == null && attribute.indexOf('.') != -1);
    }
    // Look up MBeanInfo if needed
    //
    final MBeanInfo mbi;
    if (lookupMBeanInfo) {
        try {
            mbi = mbsc.getMBeanInfo(object);
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        mbi = null;
    }
    // Check for complex type attribute
    //
    final String fa;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException("The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException("The observed attribute has been changed");
        if (firstAttribute == null) {
            if (attribute.indexOf('.') != -1) {
                MBeanAttributeInfo[] mbaiArray = mbi.getAttributes();
                for (MBeanAttributeInfo mbai : mbaiArray) {
                    if (attribute.equals(mbai.getName())) {
                        firstAttribute = attribute;
                        break;
                    }
                }
                if (firstAttribute == null) {
                    String[] tokens = attribute.split("\\.", -1);
                    firstAttribute = tokens[0];
                    for (int i = 1; i < tokens.length; i++) remainingAttributes.add(tokens[i]);
                    isComplexTypeAttribute = true;
                }
            } else {
                firstAttribute = attribute;
            }
        }
        fa = firstAttribute;
    }
    return mbsc.getAttribute(object, fa);
}
Also used : MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 12 with IntrospectionException

use of javax.management.IntrospectionException in project jdk8u_jdk by JetBrains.

the class XSheet method displayMBeanOperationsNode.

// Call on EDT
private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.OPERATIONS)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {

        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
            return mbean.getMBeanInfo();
        }

        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null) {
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    mbeanOperations.loadOperations(mbean, mbi);
                    invalidate();
                    mainPanel.removeAll();
                    JPanel borderPanel = new JPanel(new BorderLayout());
                    borderPanel.setBorder(BorderFactory.createTitledBorder(Messages.OPERATION_INVOCATION));
                    borderPanel.add(new JScrollPane(mbeanOperations));
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
                    southPanel.setVisible(false);
                    southPanel.removeAll();
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem displaying MBean " + "operations for MBean [" + mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MBeanInfo(javax.management.MBeanInfo) BorderLayout(java.awt.BorderLayout) SwingWorker(javax.swing.SwingWorker) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) IOException(java.io.IOException)

Example 13 with IntrospectionException

use of javax.management.IntrospectionException in project jdk8u_jdk by JetBrains.

the class DcmdMBeanPermissionsTest method main.

public static void main(final String[] args) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName on = null;
    try {
        on = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
    } catch (MalformedObjectNameException ex) {
        ex.printStackTrace();
        throw new RuntimeException("TEST FAILED");
    }
    MBeanInfo info = null;
    try {
        info = mbs.getMBeanInfo(on);
    } catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) {
        ex.printStackTrace();
        throw new RuntimeException("TEST FAILED");
    }
    CustomSecurityManager sm = new CustomSecurityManager();
    System.setSecurityManager(sm);
    // Set of permission required to run the test cleanly
    // Some permissions are required by the MBeanServer and other
    // platform services (RuntimePermission("createClassLoader"),
    // ReflectPermission("suppressAccessChecks"),
    // java.util.logging.LoggingPermission("control"),
    // RuntimePermission("exitVM.97")).
    // Other permissions are required by commands being invoked
    // in the test (for instance, RuntimePermission("modifyThreadGroup")
    // and RuntimePermission("modifyThread") are checked when
    // runFinalization() is invoked by the gcRunFinalization command.
    sm.grantPermission(new RuntimePermission("createClassLoader"));
    sm.grantPermission(new ReflectPermission("suppressAccessChecks"));
    sm.grantPermission(new java.util.logging.LoggingPermission("control", ""));
    sm.grantPermission(new java.lang.RuntimePermission("exitVM.97"));
    sm.grantPermission(new java.lang.RuntimePermission("modifyThreadGroup"));
    sm.grantPermission(new java.lang.RuntimePermission("modifyThread"));
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        Permission opPermission = new MBeanPermission(info.getClassName(), opInfo.getName(), on, "invoke");
        sm.grantPermission(opPermission);
        testOperation(mbs, sm, on, opInfo);
        sm.denyPermission(opPermission);
    }
    System.out.println("TEST PASSED");
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanPermission(javax.management.MBeanPermission) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) ObjectName(javax.management.ObjectName) ReflectPermission(java.lang.reflect.ReflectPermission) MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission) ReflectPermission(java.lang.reflect.ReflectPermission) MBeanServer(javax.management.MBeanServer)

Example 14 with IntrospectionException

use of javax.management.IntrospectionException in project geode by apache.

the class MBeanServerWrapper method getOperationContext.

// TODO: cache this
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException {
    MBeanInfo beanInfo = null;
    try {
        beanInfo = mbs.getMBeanInfo(objectName);
    } catch (IntrospectionException e) {
        throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
    }
    // If there is no annotation defined either in the class level or method level, we should
    // consider this operation/attribute freely accessible
    ResourcePermission result = null;
    // find the context in the beanInfo if defined in the class level
    result = getOperationContext(beanInfo.getDescriptor(), result);
    MBeanFeatureInfo[] featureInfos = null;
    if (isOp) {
        featureInfos = beanInfo.getOperations();
    } else {
        featureInfos = beanInfo.getAttributes();
    }
    // still look into the attributes/operations to see if it's defined in the method level
    for (MBeanFeatureInfo info : featureInfos) {
        if (info.getName().equals(featureName)) {
            // found the featureInfo of this method on the bean
            result = getOperationContext(info.getDescriptor(), result);
            break;
        }
    }
    return result;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) ResourcePermission(org.apache.geode.security.ResourcePermission) MBeanFeatureInfo(javax.management.MBeanFeatureInfo)

Aggregations

IntrospectionException (javax.management.IntrospectionException)14 MBeanInfo (javax.management.MBeanInfo)13 InstanceNotFoundException (javax.management.InstanceNotFoundException)11 ReflectionException (javax.management.ReflectionException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)7 ObjectName (javax.management.ObjectName)6 IOException (java.io.IOException)4 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 MBeanException (javax.management.MBeanException)3 RuntimeMBeanException (javax.management.RuntimeMBeanException)3 SwingWorker (javax.swing.SwingWorker)3 BorderLayout (java.awt.BorderLayout)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 Method (java.lang.reflect.Method)1