com.sun.jmx.remote.opt.security
Class MBeanServerAccessController

java.lang.Object
  extended by com.sun.jmx.remote.opt.security.MBeanServerAccessController
All Implemented Interfaces:
MBeanServer, MBeanServerConnection, MBeanServerForwarder
Direct Known Subclasses:
MBeanServerFileAccessController

public abstract class MBeanServerAccessController
extends Object
implements MBeanServerForwarder

An object of this class implements the MBeanServer interface and, for each of its methods, calls an appropriate checking method and then forwards the request to a wrapped MBeanServer object. The checking method may throw a RuntimeException if the operation is not allowed; in this case the request is not forwarded to the wrapped object.

A typical use of this class is to insert it between a connector server such as the RMI connector and the MBeanServer with which the connector is associated. Requests from the connector client can then be filtered and those operations that are not allowed, or not allowed in a particular context, can be rejected by throwing a SecurityException in the corresponding check* method.

This is an abstract class, because in its implementation none of the checking methods does anything. To be useful, it must be subclassed and at least one of the checking methods overridden to do some checking. Some or all of the MBeanServer methods may also be overridden, for instance if the default checking behaviour is inappropriate.

If there is no SecurityManager, then the access controller will refuse to create an MBean that is a ClassLoader, which includes MLets, or to execute the method addURL on an MBean that is an MLet. This prevents people from opening security holes unintentionally. Otherwise, it would not be obvious that granting write access grants the ability to download and execute arbitrary code in the target MBean server. Advanced users who do want the ability to use MLets are presumably advanced enough to handle policy files and security managers.


Constructor Summary
MBeanServerAccessController()
           
 
Method Summary
 void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
          Call checkRead(), then forward this method to the wrapped object.
 void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback)
          Call checkRead(), then forward this method to the wrapped object.
protected abstract  void checkRead()
          Check if the caller can do read operations.
protected abstract  void checkWrite()
          Check if the caller can do write operations.
 ObjectInstance createMBean(String className, ObjectName name)
          Call checkWrite(), then forward this method to the wrapped object.
 ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature)
          Call checkWrite(), then forward this method to the wrapped object.
 ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
          Call checkWrite(), then forward this method to the wrapped object.
 ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature)
          Call checkWrite(), then forward this method to the wrapped object.
 ObjectInputStream deserialize(ObjectName name, byte[] data)
          Call checkRead(), then forward this method to the wrapped object.
 ObjectInputStream deserialize(String className, byte[] data)
          Call checkRead(), then forward this method to the wrapped object.
 ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data)
          Call checkRead(), then forward this method to the wrapped object.
 Object getAttribute(ObjectName name, String attribute)
          Call checkRead(), then forward this method to the wrapped object.
 AttributeList getAttributes(ObjectName name, String[] attributes)
          Call checkRead(), then forward this method to the wrapped object.
 ClassLoader getClassLoader(ObjectName loaderName)
          Call checkRead(), then forward this method to the wrapped object.
 ClassLoader getClassLoaderFor(ObjectName mbeanName)
          Call checkRead(), then forward this method to the wrapped object.
 ClassLoaderRepository getClassLoaderRepository()
          Call checkRead(), then forward this method to the wrapped object.
 String getDefaultDomain()
          Call checkRead(), then forward this method to the wrapped object.
 String[] getDomains()
          Call checkRead(), then forward this method to the wrapped object.
 Integer getMBeanCount()
          Call checkRead(), then forward this method to the wrapped object.
 MBeanInfo getMBeanInfo(ObjectName name)
          Call checkRead(), then forward this method to the wrapped object.
 MBeanServer getMBeanServer()
           
 ObjectInstance getObjectInstance(ObjectName name)
          Call checkRead(), then forward this method to the wrapped object.
 Object instantiate(String className)
          Call checkWrite(), then forward this method to the wrapped object.
 Object instantiate(String className, Object[] params, String[] signature)
          Call checkWrite(), then forward this method to the wrapped object.
 Object instantiate(String className, ObjectName loaderName)
          Call checkWrite(), then forward this method to the wrapped object.
 Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature)
          Call checkWrite(), then forward this method to the wrapped object.
 Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
          Call checkWrite(), then forward this method to the wrapped object.
 boolean isInstanceOf(ObjectName name, String className)
          Call checkRead(), then forward this method to the wrapped object.
 boolean isRegistered(ObjectName name)
          Call checkRead(), then forward this method to the wrapped object.
 Set queryMBeans(ObjectName name, QueryExp query)
          Call checkRead(), then forward this method to the wrapped object.
 Set queryNames(ObjectName name, QueryExp query)
          Call checkRead(), then forward this method to the wrapped object.
 ObjectInstance registerMBean(Object object, ObjectName name)
          Call checkWrite(), then forward this method to the wrapped object.
 void removeNotificationListener(ObjectName name, NotificationListener listener)
          Call checkRead(), then forward this method to the wrapped object.
 void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
          Call checkRead(), then forward this method to the wrapped object.
 void removeNotificationListener(ObjectName name, ObjectName listener)
          Call checkRead(), then forward this method to the wrapped object.
 void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback)
          Call checkRead(), then forward this method to the wrapped object.
 void setAttribute(ObjectName name, Attribute attribute)
          Call checkWrite(), then forward this method to the wrapped object.
 AttributeList setAttributes(ObjectName name, AttributeList attributes)
          Call checkWrite(), then forward this method to the wrapped object.
 void setMBeanServer(MBeanServer mbs)
           
 void unregisterMBean(ObjectName name)
          Call checkWrite(), then forward this method to the wrapped object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MBeanServerAccessController

public MBeanServerAccessController()
Method Detail

getMBeanServer

public MBeanServer getMBeanServer()
Specified by:
getMBeanServer in interface MBeanServerForwarder

setMBeanServer

public void setMBeanServer(MBeanServer mbs)
Specified by:
setMBeanServer in interface MBeanServerForwarder

checkRead

protected abstract void checkRead()
Check if the caller can do read operations. This method does nothing if so, otherwise throws SecurityException.


checkWrite

protected abstract void checkWrite()
Check if the caller can do write operations. This method does nothing if so, otherwise throws SecurityException.


addNotificationListener

public void addNotificationListener(ObjectName name,
                                    NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
                             throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
addNotificationListener in interface MBeanServer
Specified by:
addNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException

addNotificationListener

public void addNotificationListener(ObjectName name,
                                    ObjectName listener,
                                    NotificationFilter filter,
                                    Object handback)
                             throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
addNotificationListener in interface MBeanServer
Specified by:
addNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException

createMBean

public ObjectInstance createMBean(String className,
                                  ObjectName name)
                           throws ReflectionException,
                                  InstanceAlreadyExistsException,
                                  MBeanRegistrationException,
                                  MBeanException,
                                  NotCompliantMBeanException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
createMBean in interface MBeanServer
Specified by:
createMBean in interface MBeanServerConnection
Throws:
ReflectionException
InstanceAlreadyExistsException
MBeanRegistrationException
MBeanException
NotCompliantMBeanException

createMBean

public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  Object[] params,
                                  String[] signature)
                           throws ReflectionException,
                                  InstanceAlreadyExistsException,
                                  MBeanRegistrationException,
                                  MBeanException,
                                  NotCompliantMBeanException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
createMBean in interface MBeanServer
Specified by:
createMBean in interface MBeanServerConnection
Throws:
ReflectionException
InstanceAlreadyExistsException
MBeanRegistrationException
MBeanException
NotCompliantMBeanException

createMBean

public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName)
                           throws ReflectionException,
                                  InstanceAlreadyExistsException,
                                  MBeanRegistrationException,
                                  MBeanException,
                                  NotCompliantMBeanException,
                                  InstanceNotFoundException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
createMBean in interface MBeanServer
Specified by:
createMBean in interface MBeanServerConnection
Throws:
ReflectionException
InstanceAlreadyExistsException
MBeanRegistrationException
MBeanException
NotCompliantMBeanException
InstanceNotFoundException

createMBean

public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName,
                                  Object[] params,
                                  String[] signature)
                           throws ReflectionException,
                                  InstanceAlreadyExistsException,
                                  MBeanRegistrationException,
                                  MBeanException,
                                  NotCompliantMBeanException,
                                  InstanceNotFoundException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
createMBean in interface MBeanServer
Specified by:
createMBean in interface MBeanServerConnection
Throws:
ReflectionException
InstanceAlreadyExistsException
MBeanRegistrationException
MBeanException
NotCompliantMBeanException
InstanceNotFoundException

deserialize

public ObjectInputStream deserialize(ObjectName name,
                                     byte[] data)
                              throws InstanceNotFoundException,
                                     OperationsException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
deserialize in interface MBeanServer
Throws:
InstanceNotFoundException
OperationsException

deserialize

public ObjectInputStream deserialize(String className,
                                     byte[] data)
                              throws OperationsException,
                                     ReflectionException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
deserialize in interface MBeanServer
Throws:
OperationsException
ReflectionException

deserialize

public ObjectInputStream deserialize(String className,
                                     ObjectName loaderName,
                                     byte[] data)
                              throws InstanceNotFoundException,
                                     OperationsException,
                                     ReflectionException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
deserialize in interface MBeanServer
Throws:
InstanceNotFoundException
OperationsException
ReflectionException

getAttribute

public Object getAttribute(ObjectName name,
                           String attribute)
                    throws MBeanException,
                           AttributeNotFoundException,
                           InstanceNotFoundException,
                           ReflectionException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getAttribute in interface MBeanServer
Specified by:
getAttribute in interface MBeanServerConnection
Throws:
MBeanException
AttributeNotFoundException
InstanceNotFoundException
ReflectionException

getAttributes

public AttributeList getAttributes(ObjectName name,
                                   String[] attributes)
                            throws InstanceNotFoundException,
                                   ReflectionException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getAttributes in interface MBeanServer
Specified by:
getAttributes in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ReflectionException

getClassLoader

public ClassLoader getClassLoader(ObjectName loaderName)
                           throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getClassLoader in interface MBeanServer
Throws:
InstanceNotFoundException

getClassLoaderFor

public ClassLoader getClassLoaderFor(ObjectName mbeanName)
                              throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getClassLoaderFor in interface MBeanServer
Throws:
InstanceNotFoundException

getClassLoaderRepository

public ClassLoaderRepository getClassLoaderRepository()
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getClassLoaderRepository in interface MBeanServer

getDefaultDomain

public String getDefaultDomain()
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getDefaultDomain in interface MBeanServer
Specified by:
getDefaultDomain in interface MBeanServerConnection

getDomains

public String[] getDomains()
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getDomains in interface MBeanServer
Specified by:
getDomains in interface MBeanServerConnection

getMBeanCount

public Integer getMBeanCount()
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getMBeanCount in interface MBeanServer
Specified by:
getMBeanCount in interface MBeanServerConnection

getMBeanInfo

public MBeanInfo getMBeanInfo(ObjectName name)
                       throws InstanceNotFoundException,
                              IntrospectionException,
                              ReflectionException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getMBeanInfo in interface MBeanServer
Specified by:
getMBeanInfo in interface MBeanServerConnection
Throws:
InstanceNotFoundException
IntrospectionException
ReflectionException

getObjectInstance

public ObjectInstance getObjectInstance(ObjectName name)
                                 throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
getObjectInstance in interface MBeanServer
Specified by:
getObjectInstance in interface MBeanServerConnection
Throws:
InstanceNotFoundException

instantiate

public Object instantiate(String className)
                   throws ReflectionException,
                          MBeanException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
instantiate in interface MBeanServer
Throws:
ReflectionException
MBeanException

instantiate

public Object instantiate(String className,
                          Object[] params,
                          String[] signature)
                   throws ReflectionException,
                          MBeanException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
instantiate in interface MBeanServer
Throws:
ReflectionException
MBeanException

instantiate

public Object instantiate(String className,
                          ObjectName loaderName)
                   throws ReflectionException,
                          MBeanException,
                          InstanceNotFoundException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
instantiate in interface MBeanServer
Throws:
ReflectionException
MBeanException
InstanceNotFoundException

instantiate

public Object instantiate(String className,
                          ObjectName loaderName,
                          Object[] params,
                          String[] signature)
                   throws ReflectionException,
                          MBeanException,
                          InstanceNotFoundException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
instantiate in interface MBeanServer
Throws:
ReflectionException
MBeanException
InstanceNotFoundException

invoke

public Object invoke(ObjectName name,
                     String operationName,
                     Object[] params,
                     String[] signature)
              throws InstanceNotFoundException,
                     MBeanException,
                     ReflectionException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
invoke in interface MBeanServer
Specified by:
invoke in interface MBeanServerConnection
Throws:
InstanceNotFoundException
MBeanException
ReflectionException

isInstanceOf

public boolean isInstanceOf(ObjectName name,
                            String className)
                     throws InstanceNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
isInstanceOf in interface MBeanServer
Specified by:
isInstanceOf in interface MBeanServerConnection
Throws:
InstanceNotFoundException

isRegistered

public boolean isRegistered(ObjectName name)
Call checkRead(), then forward this method to the wrapped object.

Specified by:
isRegistered in interface MBeanServer
Specified by:
isRegistered in interface MBeanServerConnection

queryMBeans

public Set queryMBeans(ObjectName name,
                       QueryExp query)
Call checkRead(), then forward this method to the wrapped object.

Specified by:
queryMBeans in interface MBeanServer
Specified by:
queryMBeans in interface MBeanServerConnection

queryNames

public Set queryNames(ObjectName name,
                      QueryExp query)
Call checkRead(), then forward this method to the wrapped object.

Specified by:
queryNames in interface MBeanServer
Specified by:
queryNames in interface MBeanServerConnection

registerMBean

public ObjectInstance registerMBean(Object object,
                                    ObjectName name)
                             throws InstanceAlreadyExistsException,
                                    MBeanRegistrationException,
                                    NotCompliantMBeanException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
registerMBean in interface MBeanServer
Throws:
InstanceAlreadyExistsException
MBeanRegistrationException
NotCompliantMBeanException

removeNotificationListener

public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener)
                                throws InstanceNotFoundException,
                                       ListenerNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
removeNotificationListener in interface MBeanServer
Specified by:
removeNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
                                throws InstanceNotFoundException,
                                       ListenerNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
removeNotificationListener in interface MBeanServer
Specified by:
removeNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(ObjectName name,
                                       ObjectName listener)
                                throws InstanceNotFoundException,
                                       ListenerNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
removeNotificationListener in interface MBeanServer
Specified by:
removeNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
                                throws InstanceNotFoundException,
                                       ListenerNotFoundException
Call checkRead(), then forward this method to the wrapped object.

Specified by:
removeNotificationListener in interface MBeanServer
Specified by:
removeNotificationListener in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ListenerNotFoundException

setAttribute

public void setAttribute(ObjectName name,
                         Attribute attribute)
                  throws InstanceNotFoundException,
                         AttributeNotFoundException,
                         InvalidAttributeValueException,
                         MBeanException,
                         ReflectionException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
setAttribute in interface MBeanServer
Specified by:
setAttribute in interface MBeanServerConnection
Throws:
InstanceNotFoundException
AttributeNotFoundException
InvalidAttributeValueException
MBeanException
ReflectionException

setAttributes

public AttributeList setAttributes(ObjectName name,
                                   AttributeList attributes)
                            throws InstanceNotFoundException,
                                   ReflectionException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
setAttributes in interface MBeanServer
Specified by:
setAttributes in interface MBeanServerConnection
Throws:
InstanceNotFoundException
ReflectionException

unregisterMBean

public void unregisterMBean(ObjectName name)
                     throws InstanceNotFoundException,
                            MBeanRegistrationException
Call checkWrite(), then forward this method to the wrapped object.

Specified by:
unregisterMBean in interface MBeanServer
Specified by:
unregisterMBean in interface MBeanServerConnection
Throws:
InstanceNotFoundException
MBeanRegistrationException


Copyright © 2014 Terracotta, Inc.. All rights reserved.