1.配置jboss
1.1打開standalone\configuration下的standalone.xml檔案,在security-domains标簽下新增一個安全域,code也可以是自己實作的一個類,
1.2在standalone\configuration目錄下建立users.properties,roles.properties兩個檔案,也就是上面配置的兩個檔案
users.properties中添加guan=123,也就是使用者名和密碼
roles.properties 中添加guan=JBossAdmin,也就是使用者名和角色,角色後面會用到
2.用eclipse開發工具建立一個Dynamic Web Project
3.配置web應用:
打開web應用中的web.xml檔案:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<security-role>
<role-name>JBossAdmin</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<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>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>JBoss JMX Console</realm-name>
</login-config>
<display-name>ServletTest</display-name>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
解釋一下:
配置該應用中的角色,可以多個
<security-role>
<role-name>JBossAdmin</role-name>
</security-role>
配置應用中哪些頁面可通路,哪些頁面不可通路,什麼方式(post,get)可以通路,什麼方式不可以通路,什麼角色可以通路等資訊。
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<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>
配置登入方式,有兩種一種是自定義的,一種為簡單類型,下面的是簡單類型
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>JBoss JMX Console</realm-name>
</login-config>
4.在WEB-INF下建立一個jboss-web.xml檔案,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>testJAAS</security-domain>
</jboss-web>
也就是指定使用jboss中的哪個安全域,testJAAS是一開始在jboss中配置的安全域
5.整個工程:
6.通路