如何为 Web 应用程序中的摘要式身份验证配置 JBoss DatabaseServerLoginModule [英] How to configure JBoss DatabaseServerLoginModule for Digest Authentication in a Web Application
问题描述
一句话,我想将 JBoss 4.2.2 配置为使用 DatabaseServerLoginModule 作为通过 Digest Authentication 保护的 Web 应用程序的登录模块.我遇到的问题是密码无法验证.我怀疑问题出在我如何定义应用程序策略或密码如何存储在数据库中.
In a sentence, I want to configure JBoss 4.2.2 to use DatabaseServerLoginModule as the login-module for a Web application that is secured via Digest Authentication. The problem I am having is that the passwords fail to validate. I suspect the issue is either in how I've defined the application policy or in how the passwords are stored in the database.
以下是所有相关文件.我有一个 MySQL 数据库,其中用户和角色使用以下模式定义:
Below are all the relevant files. I have a MySQL database with users and roles defined using the following schema:
CREATE TABLE SR_USER (
ID BIGINT(19) NOT NULL AUTO_INCREMENT,
USERNAME VARCHAR(20) NOT NULL,
PASSWORD VARCHAR(255) NOT NULL,
PRIMARY KEY (ID)
)
CHARACTER SET utf8;
CREATE TABLE SR_ROLE (
ID BIGINT(19) NOT NULL AUTO_INCREMENT,
ROLE_NAME VARCHAR(20) NOT NULL,
PRIMARY KEY (ID)
)
CHARACTER SET utf8;
CREATE TABLE SR_USER_ROLE (
FK_USER_ID BIGINT(19) NOT NULL,
FK_ROLE_ID BIGINT(19) NOT NULL,
FOREIGN KEY (FK_USER_ID) REFERENCES SR_USER (ID),
FOREIGN KEY (FK_ROLE_ID) REFERENCES SR_ROLE (ID)
)
CHARACTER SET utf8;
对于 login-config.xml 文件中的应用程序策略,我定义了以下内容:
for the application policy in the login-config.xml file I have the following defined:
<application-policy name="secrest">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule"
flag="required">
<module-option name="dsJndiName">java:/SecRestDS</module-option>
<module-option name="principalsQuery">
SELECT PASSWORD FROM SR_USER WHERE USERNAME=?
</module-option>
<module-option name="rolesQuery">
SELECT r.ROLE_NAME FROM SR_ROLE r, SR_USER_ROLE ur, SR_USER u WHERE
u.USERNAME=? AND u.ID=ur.FK_USER_ID AND ur.FK_ROLE_ID=r.ID
</module-option>
<module-option name="hashAlgorithm">MD5</module-option>
<module-option name="hashEncoding">hex</module-option>
</login-module>
</authentication>
</application-policy>
这是我的网络应用程序的 web.xml 文件:
here is the web.xml file for my web application:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.acme.samples.SecureRESTApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>secrest</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>DIGEST</auth-method>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
</web-app>
最后,这里是 jboss-web.xml:
and finally, here is the jboss-web.xml:
<jboss-web>
<security-domain>java:/jaas/secrest</security-domain>
</jboss-web>
我还应该补充一点,我用以下内容填充数据库:
I should also add that I populate the data base with the following content:
INSERT INTO SR_ROLE (ROLE_NAME) VALUES ('admin');
INSERT INTO SR_ROLE (ROLE_NAME) VALUES ('apiuser');
INSERT INTO SR_USER (USERNAME, PASSWORD) VALUES ('user1', PASSWORD('p455w0rd'));
INSERT INTO SR_USER (USERNAME, PASSWORD) VALUES ('user2', 'p455w0rd');
INSERT INTO SR_USER (USERNAME, PASSWORD) VALUES ('user3', 'a4fd8e6fa9fbf9a6f2c99e7b70aa9ef2');
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (1, 1);
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (1, 2);
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (2, 1);
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (2, 2);
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (3, 1);
INSERT INTO SR_USER_ROLE (FK_USER_ID, FK_ROLE_ID) VALUES (3, 2);
正如您在上面看到的,所有三个用户(例如 user1、user2、user3)都具有相同的密码;但在每种情况下,密码都使用 MD5 哈希编码(或不编码).然而,以上都不起作用.这是我认为问题的核心.
As you can see above, all three users (e.g. user1, user2, user3) all have the same password; but in each case the password is encoded (or not) using MD5 hash. None of the above, however, work. This is at the core of the issue I think.
推荐答案
所以我终于想出了这个.关键是:
So I finally figured this one out. The key was the following:
<application-policy name="secrest">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
<module-option name="dsJndiName">java:/SecRestDS</module-option>
<module-option name="principalsQuery">
SELECT PASSWORD FROM SR_USER WHERE USERNAME=?
</module-option>
<module-option name="rolesQuery">
SELECT r.ROLE_NAME, 'Roles' FROM SR_ROLE r, SR_USER_ROLE ur, SR_USER u WHERE
u.USERNAME=? AND u.ID=ur.FK_USER_ID AND ur.FK_ROLE_ID=r.ID
</module-option>
<module-option name="hashAlgorithm">MD5</module-option>
<module-option name="hashEncoding">rfc2617</module-option>
<module-option name="ignorePasswordCase">false</module-option>
<module-option name="hashStorePassword">true</module-option>
<module-option name="hashUserPassword">false</module-option>
<module-option name="storeDigestCallback">org.jboss.security.auth.spi.RFC2617Digest</module-option>
</login-module>
</authentication>
这篇关于如何为 Web 应用程序中的摘要式身份验证配置 JBoss DatabaseServerLoginModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!