debug spring security authentication-manager

时间:2013-11-26 09:09:55

标签: spring-mvc spring-security

我正试图通过湄公河网站上的一个例子来获得Spring的安全性...... http://www.mkyong.com/spring-security/spring-security-form-login-using-database/

我使用简单的MySQL表工作,但现在我正在尝试使用db2将密码存储在使用md5加密的数据库中。

以下是我设置的方式......

<authentication-manager>
    <authentication-provider>
        <password-encoder hash="md5" />
        <jdbc-user-service data-source-ref="dataSource"

            users-by-username-query="
                select employeenumber, employeepassword 
                from employee where employeenumber like ? 
                and employeestatus = 'Active'"

            authorities-by-username-query="
                select employeenumber, securitygroupcode 
                from employee 
                where employeenumber like ? 
                and employeestatus = 'Active'" 
        />
    </authentication-provider>
</authentication-manager>

当我尝试登录我的应用程序并输入错误的登录详细信息时,它正确地告诉我......

您的登录尝试失败,请重试。 导致:用户名或密码无效

但是当我正确登录时,我输入了正确的登录详细信息......

您的登录尝试失败,请重试。 造成:PreparedStatementCallback; SQL的SQLException [select employeenumber作为用户名,employeepassword作为密码来自epos.employee,其中employeenumber喜欢?和sitedirectoryid = 10001和employeestatus ='活跃']; SQL状态[null];错误代码[-99999]; [ibm] [db2] [jcc] [10145] [10897]无效参数3:参数索引超出范围。嵌套异常是com.ibm.db2.jcc.b.SqlException:[ibm] [db2] [jcc] [10145] [10897]无效参数3:参数索引超出范围。

感谢所有

1 个答案:

答案 0 :(得分:0)

感谢您的帮助。我的问题是我没有在我的查询中包含启用列,这显然会导致参数3:参数索引超出范围。

无论如何,我决定给自己多一点控制权并扩展JdbcDaoImpl类并编写自己的setAuthoritiesByUsernameQuery()。我还没有测试过它,但是我对这种方法更开心,因为它允许开发人员通过执行查询的代码进行调试,我仍然可以将md5作为我的加密注入。它是两全其美的。希望我能让它发挥作用!