如何在 Spring 启动时禁用 Jolokia 的写操作?

How to disable write operation for Jolokia in Spring boot?

我有一个基于 Spring 引导 (v1.5.9) 的应用程序,由 Spring 引导执行器提供 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 引导配置如下所示:

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 政策(结果 war,根据 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 引导配置配置 Jolokia 的策略?

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

中有更多信息