编写 Java EE 6 应用程序我需要一些使用 DatabaseServerLoginModule 和 md5 散列的帮助。
设置:
登录-config.xml:
<application-policy name = "app">
<authentication>
<login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
<module-option name = "dsJndiName">java:/MySQLDS</module-option>
<module-option name = "principalsQuery">Select password from user where email_current=?</module-option>
<module-option name="rolesQuery">
SELECT r.name, 'Roles' FROM role r, user_2_role ur, user u WHERE
u.email_current=? AND u.id_user=ur.id_user AND ur.id_role=r.id_role
</module-option>
<module-option name ="hashAlgorithm">md5</module-option>
<module-option name="hashEncoding">base64</module-option>
<module-option name="ignorePasswordCase">false</module-option>
<module-option name="hashStorePassword">false</module-option>
<module-option name="hashUserPassword">true</module-option>
</login-module>
<!-- login-module code="org.jboss.security.ClientLoginModule" flag="required" /-->
</authentication>
</application-policy>
网页.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>Customer Content</web-resource-name>
<url-pattern>/customer/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>AuthorizedUser</role-name>
<role-name>customer</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>DIGEST</auth-method>
<realm-name>The Restricted Zone</realm-name>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/login.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>The role required to access restricted content </description>
<role-name>customer</role-name>
</security-role>
登录实现(重要部分):
// login
WebAuthentication pwl = new WebAuthentication();
if (pwl.login(aEmail, aPassword)) {
return "customer/dashboard?faces-redirect=true";
} else {
throw new IncorrectCredentialsException();
}
我使用以下实现存储密码:
final byte[] md5Hash = DigestUtils.md5(newPassword);
md5NewPassword = Hex.encodeHexString(md5Hash);
我使用来自互联网的一些 md5 生成器检查了写入数据库的值,例如http://www.miraclesalad.com/webtools/md5.php
写的都一样。
使用完全没有 md5 散列并且使用表单而不是配置的摘要的身份验证方法。任何想法?
提前致谢