JBoss AS 7 配置安全域方式之——数据库读入用户名和密码进行登陆验证

在如下标签中添加具体安全域:

<subsystem xmlns="urn:jboss:domain:security:1.1">
            <security-domains>

            </security-domains>
</subsystem>

添加完成后,子系统标签示例如下:

<subsystem xmlns="urn:jboss:domain:security:1.1">
            <security-domains>
 
                <security-domain name="taobeRealm" cache-type="default">
                    <authentication>
                        <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
                            <module-option name="principalsQuery" value="SELECT passwd FROM user where name=?"/>
                            <module-option name="rolesQuery" value="SELECT role_name,'Roles' FROM roleInfo where name=?"/>
                            <module-option name="dsJndiName" value="java:/taobe"/>
                            <module-option name="hashAlgorithm" value="SHA-256"/>
                            <module-option name="hashEncoding" value="base64"/>
                        </login-module>
                    </authentication>
                </security-domain>
            </security-domains>
        </subsystem>


淡蓝色是可配置的。

值得一提的是查询角色至少需要角色和角色组两个字段,没有角色组则必须虚拟一个默认的角色组出来。

比如例子中SELECT role_name,'Roles' FROM roleInfo where name=?中‘Roles’就是虚拟出来的角色组。

WEB工程下的jboss-web.xml:

即将配额只的<security-domain>添加进去。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <security-domain>taobeRealm</security-domain>
  <context-root>/taobe-eap</context-root>
</jboss-web>

你可能感兴趣的:(JBoss AS 7 配置安全域方式之——数据库读入用户名和密码进行登陆验证)