spring security - 在 UserDetailsService 实现中访问请求参数 [英] spring security - access request parameters inside UserDetailsService implementation
本文介绍了spring security - 在 UserDetailsService 实现中访问请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个 java spring mvc 应用程序.我已经实现了这样的 UserDetailsService
接口:
I'm working on a java spring mvc application. I have implemented the UserDetailsService
interface like this:
@Component
@Transactional
public class SecurityDAO implements UserDetailsService{
@Override
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
...
}
....
}
我需要在 loadUserByUsername
方法中找到用户登录网址(因为项目有多个登录网址).事实上,我想访问UserDetailsService
实现中的请求参数.
I need to find the user login url inside loadUserByUsername
method(because the project has multiple login urls). In fact, I want to access request parameters inside UserDetailsService
implementation.
推荐答案
只需将请求注入您的服务:
Just inject the request on your service:
@Autowired
private HttpServletRequest request;
为了让它工作,你需要先注册 RequestContextListener,不过:
For it to work you need to register RequestContextListener previously, though:
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
这篇关于spring security - 在 UserDetailsService 实现中访问请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文