,我有以下我的应用程序-config.xml中配置:Spring Security认证简单的登录
<security:http auto-config="true" />
<security:global-method-security secured-annotations="enabled" />
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select login, password
from accounts where login=? and password=?"
authorities-by-username-query="
select a.login, ar.authority from accounts a, account_roles ar
where a.account_id = ar.account_id and a.login =? "
/>
</security:authentication-provider>
</security:authentication-manager>
但是当我开始我的应用程序,它显示我收到以下错误信息登录:
原因:PreparedStatementCallback;未分类SQL的SQLException [选择登录名,>登录名=>帐户的密码和 password =?]; SQL状态[90012];错误代码[90012];参数“#2”未设置为 ; SQL语句:选择登录名,密码从 login =?和密码=? [90012-170];嵌套的异常是 org.h2.jdbc.JdbcSQLException:参数“#2”未设置; SQL 声明:选择登录,密码从帐户登录=?和 password =? [90012-170]
任何想法什么是错的?
我不完全确定安全:jdbc-user-service是如何工作的?它在我的select查询中如何填入=?
我的数据库定义为:
CREATE TABLE accounts (
account_id VARCHAR NOT NULL,
login VARCHAR NOT NULL,
password VARCHAR NOT NULL,
PRIMARY KEY (account_id)
);
CREATE TABLE account_roles (
account_id VARCHAR NOT NULL,
authority VARCHAR NOT NULL,
PRIMARY KEY (account_id),
CONSTRAINT FK_account_roles FOREIGN KEY (account_id) REFERENCES accounts (account_id)
);
感谢
我也试过,并且得到这个消息: 原因:PreparedStatementCallback;未归类SQLException for SQL [选择登录名,密码从帐户登录=?限制1]; SQL状态[90008];错误代码[90008];参数“columnIndex”的值“3”无效[90008-170];嵌套异常是org.h2.jdbc.JdbcSQLException:参数“columnIndex”的值“3”无效[90008-170] P.S.我用我的数据库模式更新了原文。 – 2013-05-12 13:04:37
这是通过应用程序配置,如果这有帮助:http://pastebin.com/NqptCiS4 – 2013-05-12 15:00:50
@ john-sam我已经更新了我的答案。查询必须返回3个值:'login','password'和'enabled'属性。因为你的方案缺少'enabled'属性,所以我修改了SQL查询以始终返回'true'。 – 2013-05-12 16:13:13