将JDBC安全领域迁移到WildFly 10

时间:2016-04-23 14:11:51

标签: java java-ee jboss wildfly

我试图在this guide之后将我的安全领域从GlassFish 4迁移到WildFly 10。

我有:

  • 将我的数据源设置为java:/RemindersDS并验证它是否正常工作。
  • 按以下方式设置我的域名:

    <security-domain name="RemindersDomain" cache-type="default">
        <authentication>
            <login-module code="Database" flag="required">
                <module-option name="dsJndiName" value="java:/RemindersDS"/>
                <module-option name="principalsQuery" value="SELECT password FROM Authentication WHERE username = ?"/>
                <module-option name="rolesQuery" value="SELECT rolename, 'Roles' FROM User_roles WHERE username = ?"/>
                <module-option name="hashAlgorithm" value="SHA-256"/>
                <module-option name="hashEncoding" value="BASE64"/>
            </login-module>
            <login-module code="RoleMapping" flag="required">
                <module-option name="rolesProperties" value="file:${jboss.server.config.dir}/reminders-domain.properties"/>
                <module-option name="replaceRole" value="false"/>
            </login-module>
        </authentication>
    </security-domain>
    
  • 验证了上述问题。

  • 配置目录中添加了 reminders-domain.properties 文件,其中包含以下内容:

    user=user
    admin=admin,user
    
  • 在我的 jboss-web.xml 中添加了<security-domain>RemindersDomain</security-domain>

  • 在我的 web.xml 中添加了以下内容:

    <security-constraint>
        <display-name>Update and delete users</display-name>
        <web-resource-collection>
            <web-resource-name>Users</web-resource-name>
            <description/>
            <url-pattern>/api/users/*</url-pattern>
            <http-method>PUT</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>admin</role-name>
            <role-name>user</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>RemindersDomain</realm-name>
    </login-config>
    <security-role>
        <description/>
        <role-name>admin</role-name>
    </security-role>
    <security-role>
        <description/>
        <role-name>user</role-name>
    </security-role>
    

应用程序部署成功,但每当我尝试执行受约束的请求时,我都会收到401 Unauthorized响应。我使用Postman发送这些请求(并生成HTTP基本身份验证的标头)。

我在这里缺少什么?我该怎么做来调试这个问题? WildFly的日志不会报告任何问题。

1 个答案:

答案 0 :(得分:0)

结果是hashEncoding必须是&#34; hex&#34;。我错误地认为BASE64引用了HTTP基本身份验证中使用的BASE64编码,但事实并非如此。