下午看到一篇文章,說是JBOSS服務器可以通過遠程的方式關閉服務,因為默認情況控制臺的用戶密碼都為空,見前一篇文章,看到這個消息后,吃了一驚,因為我們有個東東正在用JBOSS做服務器,測試了一下,確實存在這樣的問題,趕緊照著材料補了一下
我用的JBOSS版本是Version: 4.0.4CR2,操作如下
一、為jms-console加上認證
修改jboss4\server\default\deploy\jmx-console.war\WEB-INF下的web.xml和jboss-web.xml
在web.xml中把<security-constraint>的注釋去掉
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<description>An example security config that only allows users with the
role JBossAdmin to access the HTML JMX console web application
</description>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>JBossAdmin</role-name>
</auth-constraint>
</security-constraint>
在jboss-web.xml中把<security-domain>注釋去掉
<jboss-web>
<!-- Uncomment the security-domain to enable security. You will
need to edit the htmladaptor login configuration to setup the
login modules used to authentication users.
-->
<security-domain>java:/jaas/jmx-console</security-domain>
</jboss-web>
然后修改jboss4\server\default\conf\props下的兩個配置文件jmx-console-roles.properties和jmx-console-users.properties,添加用戶和密碼,搞定上面的配置之后,訪問jms-console就需要認證了,下面繼續web-console的配置
二、為web-console加上認證
在deploy目錄下面沒有看到web-console,就通過查找,結果找到了兩個地方,分別是
jboss4\server\default\deploy\management\console-mgr.sar\web-console.war\
jboss4\server\all\deploy\management\console-mgr.sar\web-console.war\
我也沒搞清楚倒底是哪個起作用,我改了其中一個試試,沒效果,干脆兩個都改了,改的步驟都是相同的,下面就對其中一個的配置進行說明了
找到 WEB-INF\下面的jboss-web.xml和web.xml,修改的方法同上,去掉兩個注釋
認證的文件放在了 WEB-INF\classes\下面,分別是web-console-roles.properties和web-console-users.properties,把用戶的認證信息添加到里面即可,重新啟動JBOSS,此時登錄控制臺會要求輸入密碼,我測試后發現有效的密碼是default下面的配置,也搞不懂為什么要兩個都改了才會彈出要求身份認證的對話框
先暫時就記在這里吧,如果哪位有做深入的研究,希望可以多提意見完善這個文檔