1. web.xml添加如下配置
<security-constraint>
<web-resource-collection> <web-resource-name>All resources</web-resource-name> <description>Protects all resources</description> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>role_name</role-name> </auth-constraint> </security-constraint><login-config>
<auth-method>BASIC</auth-method> <realm-name>sample</realm-name> </login-config><security-role>
<role-name>role_name</role-name> </security-role>
2. jboss-web.xml添加如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web> <context-root>/</context-root> <security-domain>java:/jaas/httpbasicauth</security-domain> </jboss-web>
3. login-config.xml添加:
<application-policy name="httpbasicauth">
<authentication> <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"> <module-option name="usersProperties">props/httpbasicauth-users.properties</module-option> <module-option name="rolesProperties">props/httpbasicauth-roles.properties</module-option> </login-module> </authentication> </application-policy>
4. props/httpbasicauth-users.properties
username=role_name
5. props/httpbasicauth-roles.properties
username=password