private void authorizeMBeanOperation(MBeanServerPlugin delegate, ObjectName name, String methodName, String attributeName, JmxAction.Impact impact) throws MBeanException { authorizeMBeanOperation(delegate, name, methodName, attributeName, impact, true); }
@Override public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, SET_ATTRIBUTE, attribute.getName(), JmxAction.Impact.WRITE); delegate.setAttribute(name, attribute); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof AttributeNotFoundException) throw (AttributeNotFoundException)e; if (e instanceof InvalidAttributeValueException) throw (InvalidAttributeValueException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).setAttribute(name, attribute); } } }
@Override public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegate(name); for( Attribute attribute : attributes.asList()) { authorizeMBeanOperation(delegate, name, SET_ATTRIBUTES, attribute.getName(), JmxAction.Impact.WRITE); } return delegate.setAttributes(name, attributes); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).setAttributes(name, attributes); } } }
@Override public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, UNREGISTER_MBEAN, null, JmxAction.Impact.WRITE); delegate.unregisterMBean(name); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof MBeanRegistrationException) throw (MBeanRegistrationException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).unregisterMBean(name); } } }
@Override public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, ADD_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.addNotificationListener(name, listener, filter, handback); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof RuntimeException) throw (RuntimeException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).addNotificationListener(name, listener, filter, handback); } } }
@Override public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, REMOVE_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.removeNotificationListener(name, listener, filter, handback); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ListenerNotFoundException) throw (ListenerNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).removeNotificationListener(name, listener, filter, handback); } } }
@Override public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, REMOVE_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.removeNotificationListener(name, listener); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ListenerNotFoundException) throw (ListenerNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).removeNotificationListener(name, listener); } } }
@Override public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, GET_OBJECT_INSTANCE, null, JmxAction.Impact.READ_ONLY); return delegate.getObjectInstance(name); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getObjectInstance(name); } } }
@Override public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, IS_INSTANCE_OF, null, JmxAction.Impact.READ_ONLY); return delegate.isInstanceOf(name, className); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).isInstanceOf(name, className); } } }
@Override public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, REMOVE_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.removeNotificationListener(name, listener, filter, handback); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ListenerNotFoundException) throw (ListenerNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).removeNotificationListener(name, listener, filter, handback); } } }
private MBeanInfo getMBeanInfo(ObjectName name, boolean logAndAuthorize, boolean nullIfNotFound) throws InstanceNotFoundException, IntrospectionException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegate(name); if (logAndAuthorize) { authorizeMBeanOperation(delegate, name, GET_MBEAN_INFO, null, JmxAction.Impact.READ_ONLY); } return delegate.getMBeanInfo(name); } catch (Exception e) { if (nullIfNotFound) { return null; } error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof IntrospectionException) throw (IntrospectionException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (logAndAuthorize && shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getMBeanInfo(name); } } }
@Override public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, REMOVE_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.removeNotificationListener(name, listener); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ListenerNotFoundException) throw (ListenerNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).removeNotificationListener(name, listener); } } }
@Override public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { // findDelegate does not work for a pattern ObjectName delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, ADD_NOTIFICATION_LISTENER, null, JmxAction.Impact.READ_ONLY); delegate.addNotificationListener(name, listener, filter, handback); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof RuntimeException) throw (RuntimeException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).addNotificationListener(name, listener, filter, handback); } } }
@Override public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, GET_ATTRIBUTE, attribute, JmxAction.Impact.READ_ONLY); return delegate.getAttribute(name, attribute); } catch (Exception e) { error = e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof AttributeNotFoundException) throw (AttributeNotFoundException)e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getAttribute(name, attribute); } } }
@Override public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, REGISTER_MBEAN, null, JmxAction.Impact.WRITE); return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.registerMBean(object, name), delegate); } catch (Exception e) { error = e; if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e; if (e instanceof MBeanRegistrationException) throw (MBeanRegistrationException)e; if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).registerMBean(object, name); } } }
@Override public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegate(name); if (delegate.shouldAuthorize()) { for(String attribute : attributes) { authorizeMBeanOperation(delegate, name, GET_ATTRIBUTES, attribute, JmxAction.Impact.READ_ONLY); } } return delegate.getAttributes(name, attributes); } catch (Exception e) { error = e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getAttributes(name, attributes); } } }
@Override public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanException, NotCompliantMBeanException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, CREATE_MBEAN, null, JmxAction.Impact.WRITE); return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.createMBean(className, name), delegate); } catch (Exception e) { error = e; if (e instanceof ReflectionException) throw (ReflectionException)e; if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).createMBean(className, name); } } }
@Override public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanException, NotCompliantMBeanException { params = nullAsEmpty(params); signature = nullAsEmpty(signature); Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, CREATE_MBEAN, null, JmxAction.Impact.WRITE); return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.createMBean(className, name, params, signature), delegate); } catch (Exception e) { error = e; if (e instanceof ReflectionException) throw (ReflectionException)e; if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).createMBean(className, name, params, signature); } } }
@Override public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException { params = nullAsEmpty(params); signature = nullAsEmpty(signature); Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = false; try { delegate = findDelegateForNewObject(name); authorizeMBeanOperation(delegate, name, CREATE_MBEAN, null, JmxAction.Impact.WRITE); return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.createMBean(className, name, loaderName, params, signature), delegate); } catch (Exception e) { error = e; if (e instanceof ReflectionException) throw (ReflectionException)e; if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).createMBean(className, name, params, signature); } } }
@Override public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException, ReflectionException { params = nullAsEmpty(params); signature = nullAsEmpty(signature); Throwable error = null; MBeanServerPlugin delegate = findDelegate(name); boolean readOnly = false; try { //Need to determine impact of the operation readOnly = isOperationReadOnly(name, operationName, signature); delegate = findDelegate(name); authorizeMBeanOperation(delegate, name, INVOKE, null, readOnly ? JmxAction.Impact.READ_ONLY : JmxAction.Impact.WRITE); return delegate.invoke(name, operationName, params, signature); } catch (Exception e) { error = e; if (e instanceof ReflectionException) throw (ReflectionException)e; if (e instanceof MBeanException) throw (MBeanException)e; if (e instanceof InstanceNotFoundException) throw (InstanceNotFoundException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).invoke(name, operationName, params, signature); } } }