Results 1 to 3 of 3

Thread: Getting ServletContext headers in an Authentication event

  1. #1
    Join Date
    Jul 2006
    Posts
    9

    Question Getting ServletContext headers in an Authentication event

    Greetings all.

    Ultimately, I need to get the user-agent from the servlet context.

    I'm using AuthenticationSuccessEvent and AbstractAuthenticationFailureEvent to handle successful and unsuccessful login attempts. Inside of those handlers I create a new object which contains details about the login attempt. However, in those events I can't seem to get a hold of the servlet context in order to get at the headers. It's always null. The WebAuthenticationDetails object from Authentication.getDetails() doesn't seem to contain any of this information, either.

    So: in these event handlers, how can I get a hold of the user-agent?

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    You can implement your own AuthenticationDetailsSource which could create an object that contains the necessary information. You can wire it in using form-login@authentication-details-source-ref. Keep in mind this is the information at time of login (it is not updated for every request). You could also access the current information using Spring's RequestContext. If you are accessing it within Spring MVC this is automatically populated. Otherwise you will need to use either RequestContextFilter or RequestContextListener to ensure the RequestContext is populated.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3
    Join Date
    Mar 2007
    Posts
    561

    Default

    The event does not contain the ServletContext, this would be weird.
    What headers?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •