繁体   English   中英

Spring Security和数据库授权

[英]Spring Security and DB authorization

我登录有问题。 如果我的用户名和密码相同,则登录成功,但如果用户名和密码不同,则出现错误Reason: Bad credentials错误

这是“配置安全性”类中的configure方法:

protected void configure(AuthenticationManagerBuilder auth)
        throws Exception {
    auth
    .jdbcAuthentication()
    .dataSource(dataSource)
    .usersByUsernameQuery("select username,password, enabled from users where username=? ")
    .authoritiesByUsernameQuery("select u.username, r.name from users u, security_role r, users_security_role uhr where u.id_user = uhr.id and r.id = uhr.security_role_id and u.username =?");
}

我在数据库用户中有用户名和密码的Tabe。 如果我在数据库中插入用户,例如"user","user""usernameandpasswordsame","usernameandpasswordsame"一切正常,我可以登录并获取正确的user_role,但是如果在用户名和密码不同的数据库中插入user,例如"user","userpass" ,我有错误。

这也是同一配置安全性类中的另一种configure方法:

        protected void configure(HttpSecurity http) throws Exception {
         http.csrf().disable()
         .authorizeRequests()
            .expressionHandler(webExpressionHandler())
            .anyRequest().authenticated()
            .and()
         .formLogin()
            .and()
         .logout()
         .deleteCookies("remove")
            .invalidateHttpSession(true)
            .logoutUrl("/logout")
         .permitAll();
    }

有人可以告诉我什么是错或问题吗?

发生这种情况的唯一情况是将表单的用户名字段保存到密码列。 尝试将用户名和密码直接插入表中。 如果您使用的是H2,请检查您的SQL文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM