【发布时间】:2016-11-21 22:10:51
【问题描述】:
我在登录时遇到问题。如果我的用户名和密码相同,登录成功但如果用户名和密码不同,我有错误Reason: Bad credentials
这是配置安全类中的配置方法:
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 =?");
}
我在 DB 用户中有用户名和密码。
如果我在数据库中插入用户,如 "user","user" 或 "usernameandpasswordsame","usernameandpasswordsame" 一切正常,我可以登录并获得正确的 user_role,但如果在数据库中插入用户名和密码不同的用户,如 "user","userpass",我有错误。
这也是同一个配置安全类中的另一个配置方法:
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();
}
谁能告诉我有什么问题或问题?
【问题讨论】:
-
我猜你在某个地方犯了一个错误,并用用户名值填充了密码变量。你的查询看起来是正确的,所以我会检查前端(jsp,....)并确保变量没有混合。
标签: java mysql spring spring-security authorization