Java Spring安全性-无效列索引异常
我想使用spring安全性。但是我得到了SQLException。我仍然没有找到任何解决方案 我的表格结构: 应用程序用户(ID\U应用程序用户、名称、密码) 应用程序角色(ID角色、名称) 应用程序用户角色(ID用户角色、ID用户、ID角色) 我的Spring配置文件:Java Spring安全性-无效列索引异常,java,spring,spring-mvc,spring-security,spring-data-jpa,Java,Spring,Spring Mvc,Spring Security,Spring Data Jpa,我想使用spring安全性。但是我得到了SQLException。我仍然没有找到任何解决方案 我的表格结构: 应用程序用户(ID\U应用程序用户、名称、密码) 应用程序角色(ID角色、名称) 应用程序用户角色(ID用户角色、ID用户、ID角色) 我的Spring配置文件: <!-- enable use-expressions --> <http auto-config="true" use-expressions="true"> <intercept-
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login
login-page="/login"
default-target-url="/index"
authentication-failure-url="/login?error"
username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf/>
</http>
<!-- Select users and user_roles from database -->
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"select name as username,password from app_user where name=?"
authorities-by-username-query=
"SELECT app_user.name as username, app_role.name as role
FROM app_user
INNER JOIN app_user_role ON app_user.id_app_user = app_user_role.id_user
INNER JOIN app_role ON app_user_role.id_role = app_role.id_role
WHERE app_user.name = ? " />
</authentication-provider>
</authentication-manager>
我得到以下错误:
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin**" access="hasRole('ROLE_ADMIN')" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login
login-page="/login"
default-target-url="/index"
authentication-failure-url="/login?error"
username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf/>
</http>
<!-- Select users and user_roles from database -->
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"select name as username,password from app_user where name=?"
authorities-by-username-query=
"SELECT app_user.name as username, app_role.name as role
FROM app_user
INNER JOIN app_user_role ON app_user.id_app_user = app_user_role.id_user
INNER JOIN app_role ON app_user_role.id_role = app_role.id_role
WHERE app_user.name = ? " />
</authentication-provider>
</authentication-manager>
20:36:55.281[http-nio-8089-exec-10]调试o.s.j.s.SQLErrorCodeSQLExceptionTranslator-转换SQL状态为“99999”、错误代码为“17003”的SQLException,消息[无效列索引];SQL为任务[PreparedStatementCallback]的[select name as username,password from app_user,其中name=?]
20:36:55.282[http-nio-8089-exec-10]调试o.s.s.w.a.UsernamePasswordAuthenticationFilter-身份验证请求失败:org.springframework.security.Authentication.AuthenticationServiceException:PreparedStatementCallback;SQL的结果集访问无效[选择名称作为用户名,密码来自app_user,其中名称=?];嵌套异常为java.sql.SQLException:列索引无效
20:36:55.282[http-nio-8089-exec-10]调试o.s.s.w.a.UsernamePasswordAuthenticationFilter-更新SecurityContextHolder以包含空身份验证
20:36:55.282[http-nio-8089-exec-10]调试o.s.s.w.a.UsernamePasswordAuthenticationFilter-委托给身份验证失败处理程序org.springframework.security.web.authentication。SimpleUrlAuthenticationFailureHandler@2f483b1e
20:36:55.282[http-nio-8089-exec-10]调试o.s.s.w.a.SimpleRulAuthenticationFailureHandler-重定向到/登录?错误
20:36:55.282[http-nio-8089-exec-10]调试o.s.s.web.DefaultRedirectStrategy-重定向到“/FNDWEB/login?错误”
怎么了?请帮助我:/提前谢谢。我终于找到了解决办法。我们需要将“,1作为已启用的””添加到查询中
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"select name as username,password,1 as enabled from app_user where name=?"
authorities-by-username-query=
"SELECT app_user.name as username, app_role.name as role
FROM app_user
INNER JOIN app_user_role ON app_user.id_app_user = app_user_role.id_user
INNER JOIN app_role ON app_user_role.id_role = app_role.id_role
WHERE app_user.name = ? " />
</authentication-provider>