Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring安全认证简单登录_Java_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Java Spring安全认证简单登录

Java Spring安全认证简单登录,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我在app-config.xml中配置了以下内容: <security:http auto-config="true" /> <security:global-method-security secured-annotations="enabled" /> <security:authentication-manager> <security:authentication-provider>

我在app-config.xml中配置了以下内容:

<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>

谢谢

参数名
用户用户名查询
意味着查询将只按用户名进行搜索,因此我建议将SQL查询修改为如下内容:

users-by-username-query="select login, password, 'true' as enabled from accounts where login=? limit 1"

正如Slava指出的,您需要指示用户是否启用。以下是Spring Security 3.2.6.0版本的文档参考:。它是这样说的:

返回的UserDetails是一个接口,它提供的getter可以保证身份验证信息的非空提供,例如用户名、密码、授予的权限以及用户帐户是启用还是禁用

如果您只阅读以下内容的文档,则有点误导:

它利用UserDetailsService(作为DAO)来查找用户名、密码和授权。它只需将用户名PasswordAuthenticationToken中提交的密码与UserDetailsService加载的密码进行比较,即可对用户进行身份验证


我也试过了,得到了这样的信息:原因:PreparedStatementCallback;SQL的未分类SQLException[选择登录名,登录名为?限制1的帐户的密码];SQL状态[90008];错误代码[90008];参数“columnIndex”[90008-170]的值“3”无效;嵌套异常为org.h2.jdbc.JdbcSQLException:参数“columnIndex”[90008-170]P.S.的值“3”无效。我用我的DB架构更新了原始帖子。@john sam我已更新了答案。查询必须返回3个值:
login
password
enabled
属性。因为您的方案缺少
enabled
属性,所以我将SQL查询修改为始终返回
true
users-by-username-query="select login, password, 'true' as enabled from accounts where login=? limit 1"