简体   繁体   English

如何限制对JMX属性的访问

[英]How limit access to JMX attributes

Our application has requirement to limit user access to subset of JMX attributes and operations for a given MBean. 我们的应用程序要求限制用户对给定MBean的JMX属性和操作子集的访问。 eg the C3P0 MBean exposes a lot of attributes/operations. 例如C3P0 MBean公开了很多属性/操作。 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. 因此,我们想在JMX控制台中隐藏该属性的设置器。

Looking at the Spring doc, I thought it would be possible: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jmx.html 查看Spring文档,我认为这是有可能的: http : //docs.spring.io/spring/docs/current/spring-framework-reference/html/jmx.html

Below is my tryst with Hibernate MBean: 以下是我对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. 我希望在JMX控制台中为Hibernate MBean仅显示一种清晰的方法。 However the above config is exposing all the original Hibernate MBean methods. 但是,上述配置公开了所有原始的Hibernate MBean方法。

Secondly, C3P0 Mbean is exposed by default, and I do not need Spring bean to expose it. 其次,默认情况下,C3P0 Mbean是公开的,并且我不需要Spring bean来公开它。 That MBean shows up in console as "PooledDataSource[2spw3u98bqgqeg1697gnx|73302995]". 该MBean在控制台中显示为“ PooledDataSource [2spw3u98bqgqeg1697gnx | 73302995]”。 I am not sure what would be the right way to expose only a subset of attributes & operations for that MBean. 我不确定什么是只公开该MBean属性和操作子集的正确方法。

Your help/pointers are appreciated. 感谢您的帮助/指针。 Thanks. 谢谢。

If a bean is a "true" MBean (implements <class>MBean ) then it is exported as-is. 如果bean是“ true” MBean(实现<class>MBean ),则按原样导出。 The attributes/operations that are exposed are those intended by the developer of that MBean. 公开的属性/操作是该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. 根据JMX规范,如果MBeanInfoAssembler还不是MBean,则仅用于为其构造ModelMBean

You could write your own bean that delegates to the hibernateStatisticsMBean for just the methods you want to expose. 您可以编写自己的Bean,仅将要公开的方法委托给hibernateStatisticsMBean

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. 从您的描述看来,C3PO似乎在Spring外部注册了自己的MBean,因此如果不深入研究它们的代码以查看是否有某种方法可以禁用导出并再次使用委派的MBean,您将无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM