180.7. 隐藏敏感信息
从 Camel 2.12 开始提供
默认情况下,Camel enlists MBeans in JMX,如使用 URI 配置的端点。在此配置中,可能存在敏感信息,如密码。
可以通过启用 掩码
选项来隐藏这些信息,如下所示:
使用 Java DSL,您可以通过以下方法打开此打开:
// only enable routes when Camel starts context.getManagementStrategy().getManagementAgent().setMask(true);
// only enable routes when Camel starts
context.getManagementStrategy().getManagementAgent().setMask(true);
在 Spring DSL 中:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <jmxAgent id="agent" mask="true"/> ... </camelContext>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" mask="true"/>
...
</camelContext>
这将屏蔽带有密码和密码短语等选项的 URI,并使用 xxxxxx
作为替换值。
180.7.1. 声明要屏蔽的 JMX 属性和操作
在 org.apache.camel.api.management.ManagedAttribute
和 org.apache.camel.api.management.ManagedOperation
上,属性 mask
可以被设置为 true
,以指示此 JMX 属性/操作的结果应该被屏蔽(如果在 JMX 代理中启用,请参阅上述)。
例如,在 camel-core org.apache.camel.api.management.mbean.ManagedEndpointMBean
的默认受管端点上,我们声明 EndpointUri
JMX 属性已被屏蔽:
@ManagedAttribute(description = "Endpoint URI", mask = true) String getEndpointUri();
@ManagedAttribute(description = "Endpoint URI", mask = true)
String getEndpointUri();