預設安裝的 JBoss 管理控制台(JMX Console、Web Console)無任何密碼保護,極具安全風險。本文記錄在 JBoss 4.x/5.x 環境下,為兩個控制台設定認證的完整步驟。
修改 jboss_home/server/default/deploy/jbossweb-tomcat55.sar/conf/web.xml,將 listings 參數設為 false,防止目錄瀏覽洩露資訊。
<param-name>listings</param-name>
<param-value>false</param-value>
JBOSS_HOME/server/default/deploy/jmx-console.war/WEB-INF/web.xml,取消註解 <security-constraint> 區塊。jboss-web.xml,取消註解 <security-domain> 區塊。JBOSS_HOME/server/default/conf/props/:jmx-console-users.properties:修改 admin=admin 為 你的用戶名=你的密碼。jmx-console-roles.properties:將 admin 改為上述設定的用戶名。JBOSS_HOME/server/default/deploy/management/console-mgr.sar/web-console.war/WEB-INF/web.xml,取消註解 <security-constraint>。jboss-web.xml,取消註解 <security-domain>。../class 目錄(即 web-console.war/WEB-INF/classes):web-console-users.properties:修改 admin=admin 為 你的用戶名=你的密碼。web-console-roles.properties:將 admin 改為上述用戶名。將上述兩個 .properties 檔案複製到 JBOSS_HOME/server/default/conf/props/ 統一管理。
編輯 JBOSS_HOME/server/default/conf/login-config.xml,確認 web-console application-policy 指向正確的屬性檔:
<application-policy name="web-console">
<authentication>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
<module-option name="usersProperties">props/web-console-users.properties</module-option>
<module-option name="rolesProperties">props/web-console-roles.properties</module-option>
</login-module>
</authentication>
</application-policy>
修改 jboss_home/server/default/conf/jboss-service.xml,將 ScanEnabled 設為 false,可提升效能但需手動重新部署。
<attribute name="ScanEnabled">false</attribute>
重新啟動 JBoss,瀏覽 https://your_domain:8080/jmx-console 或 /web-console 即會彈出基本認證對話框。