How limit access to JMX attributes

930 views Asked by At

Our application has requirement to limit user access to subset of JMX attributes and operations for a given MBean. e.g. the C3P0 MBean exposes a lot of attributes/operations. Let's say we don't want users to change min pool size. Hence we would like to suppress the setter of that attribute in the JMX console.

Looking at the Spring doc, I thought it would be possible: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jmx.html

Below is my tryst with Hibernate MBean:

    <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
     <property name="statisticsEnabled" value="true" />
  <property name="sessionFactory" value="#{myEntityManagerFactory.sessionFactory}" />
 </bean>
 
 <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
     <property name="locateExistingServerIfPossible" value="true" />
 </bean>
 
 <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
     <property name="server" ref="mbeanServer" />
     <property name="beans">
         <map>               
             <entry key="Hibernate:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" />
         </map>
     </property>
     <property name="assembler">
         <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
             <property name="managedMethods">
              <list>
                 <value>clear</value>
              </list>
             </property>
         </bean>
     </property>
 </bean>

I was hoping that only clear method will show up for Hibernate MBean in JMX console. However the above config is exposing all the original Hibernate MBean methods.

Secondly, C3P0 Mbean is exposed by default, and I do not need Spring bean to expose it. That MBean shows up in console as "PooledDataSource[2spw3u98bqgqeg1697gnx|73302995]". I am not sure what would be the right way to expose only a subset of attributes & operations for that MBean.

Your help/pointers are appreciated. Thanks.

1

There are 1 answers

0
Gary Russell On BEST ANSWER

If a bean is a "true" MBean (implements <class>MBean) then it is exported as-is. The attributes/operations that are exposed are those intended by the developer of that MBean.

The MBeanInfoAssembler is only used to construct a ModelMBean for the bean if it's not already an MBean according to the JMX spec.

You could write your own bean that delegates to the hibernateStatisticsMBean for just the methods you want to expose.

From your description, it appears that C3PO registers its own MBean outside of Spring, so there's nothing you can do there without digging into their code to see if there is some way to disable the export and, again, use a delegating MBean.