UserDetailsS​​ervice

UserDetailsS​​ervice

本文介绍了spring security - 访问UserDetailsS​​ervice实现中的请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个java spring mvc应用程序。我已经实现了 UserDetailsS​​ervice 界面,如下所示:

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 方法中找到用户登录URL(因为该项目有多个登录URL)。事实上,我想访问 UserDetailsS​​ervice 实现中的请求参数。

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 - 访问UserDetailsS​​ervice实现中的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 07:58