【问题标题】:How to disable write operation for Jolokia in Spring boot?如何在 Spring Boot 中禁用 Jolokia 的写操作?
【发布时间】:2018-06-01 14:36:49
【问题描述】:

我有一个基于 Spring boot (v1.5.9) 的应用程序,其中包含 Spring boot actuator 提供的 Jolokia。

Jolokia 工作正常。我可以读取值,例如:

http://localhost:8080/jolokia/read/java.lang:type=ClassLoading/Verbose

给我:

{"request":{"mbean":"java.lang:type=ClassLoading","attribute":"Verbose","type":"read"},"value":false,"timestamp":1527859447,"status":200}

我想要的是禁用写操作,例如:

http://localhost:8080/jolokia/write/java.lang:type=ClassLoading/Verbose/true

spring boot 配置如下:

management.security.enabled=false
management.endpoints.jmx.exposure.exclude=* 
management.endpoints.web.exposure.include=jolokia,metrics
management.endpoint.jolokia.config.policyLocation=classpath:/jolokia.xml

并且 WEB-INF\classes\jolokia.xml 中的 Jolokia 政策(根据https://jolokia.org/reference/html/security.html 导致的战争)包含:

<restrict>
    <commands>
        <command>read</command>
        <command>list</command>
        <command>version</command>
        <command>search</command>
    </commands>
</restrict>

尽管如此,我在应用程序的日志中看到以下注释:

jolokia: No access restrictor found, access to any MBean is allowed

上面示例中的写操作工作正常。

我做错了什么?我应该将策略文件放在其他地方吗?是否可以直接从 Spring boot 配置中配置 Jolokia 的策略?

【问题讨论】:

  • 您确定您使用的是 Spring Boot 1.5.9 吗?如果您使用的是 Spring Boot 1.5.9,那么您的配置属性是错误的,因为它们都来自 2.0.x。例如,如果你想在 Spring Boot 1.5.x 中配置 Jolokia,你应该使用jolokia.config.*reference documentation 中有更多信息。
  • @AndyWilkinson 好点!我在我的 1.5.9 应用程序中使用了 spring boot 2.0.x 的配置 :( 更改 policyLocation 配置键解决了我的问题。在日志中,终于有“jolokia:使用策略访问限制器类路径:/jolokia.xml”写入操作已禁用。请将您的评论复制到答案中,以便我接受。谢谢。

标签: java spring-boot spring-boot-actuator jolokia


【解决方案1】:

您似乎无意中将 Spring Boot 2.0 配置属性与 Spring Boot 1.5.x 一起使用。在 1.5 中,您应该使用 jolokia.config.policyLocationreference documentation 有更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2019-03-20
    • 1970-01-01
    • 2016-09-07
    • 2016-09-27
    相关资源
    最近更新 更多