0

in Spring, I need to do additional verification in custom MyUserDetailsService when user login in, and I need the domain name where the user is login from. any idea ?

Here is what worked out from me How do I get the Session Object in Spring?

Community
  • 1
  • 1
Nabil Sham
  • 2,305
  • 4
  • 26
  • 38
  • here is what worked for me http://stackoverflow.com/questions/1629211/how-do-i-get-the-session-object-in-spring – Nabil Sham Jun 20 '14 at 05:26

1 Answers1

0

Yon can inject (@Autowired) the HttpServletRequest into your MyUserDetailsService similar to the code below, I believe getRemoteHost() is what you are looking for?

@RestController
public class WebOneController {


    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/")
    public String hello() {
        return "host " + request.getRemoteHost();
    }
}
ebell
  • 127
  • 1
  • 3
  • The class I am working with is from Spring Security http://docs.spring.io/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/core/userdetails/UserDetailsService.html?is-external=true – Nabil Sham Jun 19 '14 at 15:56
  • How are you calling your "MyUserDetailsService" implementation of UserDetailsService? – ebell Jun 19 '14 at 16:12
  • I do not call it. Spring call that class as part of authentication. It is set as preAuthenticationProvider in Application-security.xml – Nabil Sham Jun 19 '14 at 16:18