@Override public Object instantiate(String className) throws ReflectionException, MBeanException { Throwable error = null; MBeanServerPlugin delegate = rootMBeanServer; final boolean readOnly = false; try { //Special authorization authorizeClassloadingOperation(delegate, INSTANTIATE); return delegate.instantiate(className); } catch (Exception e) { error = e; if (e instanceof ReflectionException) throw (ReflectionException)e; if (e instanceof MBeanException) throw (MBeanException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).instantiate(className); } } }
@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 @Deprecated public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException { Throwable error = null; MBeanServerPlugin delegate = rootMBeanServer; final boolean readOnly = true; try { //Special authorization authorizeClassloadingOperation(delegate, DESERIALIZE); return delegate.deserialize(className, data); } catch (Exception e) { error = e; if (e instanceof OperationsException) throw (OperationsException)e; if (e instanceof ReflectionException) throw (ReflectionException)e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).deserialize(className, data); } } }
@Override public String getDefaultDomain() { Throwable error = null; MBeanServerPlugin delegate = rootMBeanServer; final boolean readOnly = true; try { //No authorization needed to get the name of the default domain return delegate.getDefaultDomain(); } catch (Exception e) { error = e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getDefaultDomain(); } } }
@Override public String[] getDomains() { Throwable error = null; final boolean readOnly = true; try { //No authorization needed to get the names of the domains ArrayList<String> result = new ArrayList<String>(); if (delegates.size() > 0) { for (MBeanServerPlugin delegate : delegates) { String[] domains = delegate.getDomains(); if (domains.length > 0) { result.addAll(Arrays.asList(domains)); } } } result.addAll(Arrays.asList(rootMBeanServer.getDomains())); return result.toArray(new String[result.size()]); } catch (Exception e) { error = e; throw makeRuntimeException(e); } finally { //This should always audit log new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getDomains(); } }
@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); } } }
@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); if (delegate.shouldAuthorize()) { authorizeSensitiveOperation(CREATE_MBEAN, readOnly, true); } return delegate.createMBean(className, name); } 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 ClassLoaderRepository getClassLoaderRepository() { Throwable error = null; MBeanServerPlugin delegate = rootMBeanServer; final boolean readOnly = true; try { //Special authorization authorizeClassloadingOperation(delegate, GET_CLASSLOADER_REPOSITORY); return delegate.getClassLoaderRepository(); } catch (Exception e) { error = e; throw makeRuntimeException(e); } finally { if (shouldAuditLog(delegate, readOnly)) { new MBeanServerAuditLogRecordFormatter(this, error, readOnly).getClassLoaderRepository(); } } }
@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 ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegateForNewObject(mbeanName); //Special authorization authorizeClassloadingOperation(delegate, mbeanName, GET_CLASSLOADER_FOR); return delegate.getClassLoaderFor(mbeanName); } 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).getClassLoaderFor(mbeanName); } } }
@Override public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException { Throwable error = null; MBeanServerPlugin delegate = null; final boolean readOnly = true; try { delegate = findDelegate(loaderName); //Special authorization authorizeClassloadingOperation(delegate, loaderName, GET_CLASSLOADER); return delegate.getClassLoader(loaderName); } 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).getClassLoader(loaderName); } } }
@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 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 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 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 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); } } }
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 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 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 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); } } }