spring boot + spring security做的用户登录验证问题
spring吧
全部回复
仅看楼主
level 1
10duwang 楼主
WebSecurityConfig里
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(customPasswordEncoder);
}
2016年02月27日 02点02分 1
level 1
10duwang 楼主
@Service
public class CustomPasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence rawPassword) {
return null;
}
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
try {
if(encodedPassword.equals(Helper.md5(rawPassword.toString()+salt))) {
return true;
}
return false;
}catch(Exception e){
return false;
}
}
}
2016年02月27日 02点02分 2
level 1
10duwang 楼主
CustomPasswordEncoder 里md5加密的salt是通过用户名去数据库查出来的,这里如何获取用户名呢
2016年02月27日 02点02分 3
level 1
10duwang 楼主
获取用户名是CustomUserDetailsService的loadUserByUsername(String username)方法
两个类是分开的了
2016年02月27日 02点02分 4
level 1
10duwang 楼主
spring security真蛋疼,就不能一次性获取到用户输入的用户名和密码吗
2016年02月27日 02点02分 5
level 1
最近我也遇到这个问题了,不知道楼主解决了吗 分享一下
2016年05月06日 06点05分 6
用个静态变量保存一下用户名,其它要用的类获取这个变量
2016年05月06日 09点05分
@10duwang 如果多个用户同时登陆不是就有问题了啊
2016年05月09日 06点05分
level 2
路过
程序猿+程序媛的世界,一个不辣么神奇的网站!http://www.ai-coding.cn
2017年07月21日 06点07分 7
level 4
路过,楼主不使用autho2可以直接用spring的拦截器然后直接赋值给SecurityContext,不用实现它规范的那个类,可以参考:http://www.leftso.com/blog/127.htmlhttp://www.leftso.com/blog/129.html 通过自定义的方式来实现安全拦截[吐舌]
2017年07月21日 15点07分 8
1