Results 1 to 9 of 9

Thread: login returning 200 instead of 302

  1. #1

    Default login returning 200 instead of 302

    I'm building a REST based API and I am trying to get the login REST call to return 200 instead of 302. Is there any example of such a Spring Security configuration?
    Any help is appreciated.
    Thanks.
    Eugen.

  2. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Use a custom AuthenticationSuccessHandler to control the post-login behaviour.
    Spring - by Pivotal
    twitter @tekul

  3. #3

    Default

    Yes, I was rather hoping I wouldn't have to.
    The problem with that is that my app is in fact a REST API - I am not using the <form-login> element, so I cannot just provide a AuthenticationSuccessHandler.
    The only other way I'm aware of is to define another customer filter to replace the standard UsernamePasswordAuthenticationFilter and provide my AuthenticationSuccessHandler there.
    The other problem is that I need to check if I have this filter in my chain right now - it's javadoc says "Processes an authentication form submission" and seeing how there's no form submission in play and no <form-login> element to create it, it may simply not there. What's more, I could add it but I'm unsure if that's the right way to go just to change the http response code.
    Is there a simpler way I'm missing or is this the recommended way of achieving what I'm after?
    Thanks for the help.
    Eugen.
    Last edited by eugenparaschiv; Jul 4th, 2011 at 08:52 AM.

  4. #4
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Ok, well it would help if you could explain what you are using for authentication or attach your configuration.
    Spring - by Pivotal
    twitter @tekul

  5. #5

    Default

    I have resolved this - attaching my notes for reference if anyone else stumbles upon this:

    - note: because it’s a REST API, there’s not <login-form> element
    - specify a custom filter for the FORM_LOGIN_FILTER position
    <http ...>
    ...
    <custom-filter ref="myFilter" position="FORM_LOGIN_FILTER" />
    ...
    </http>

    - define the filter and point to a custom success handler:
    <beans:bean id="myFilter" class="org.springframework.security.web.authentica tion.UsernamePasswordAuthenticationFilter">

    <beansroperty name="authenticationManager" ref="authenticationManager" />

    <beansroperty name="authenticationSuccessHandler" ref="mySuccessHandler" />
    </beans:bean>
    <beans:bean id="mySuccessHandler" class="com.avaya.thunder.server.security.MySavedRe questAwareAuthenticationSuccessHandler" />

    - define the MySavedRequestAwareAuthenticationSuccessHandler bean:
    extends AbstractAuthenticationTargetUrlRequestHandler implements AuthenticationSuccessHandler
    - the handle method overrides the handle from AbstractAuthenticationTargetUrlRequestHandler but doesn’t do redirect

    - the response code is now 200 instead of 302

  6. #6
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    You don't need to add the filter explicitly - you can inject an AuthenticationSuccessHandler using the namespace.
    Spring - by Pivotal
    twitter @tekul

  7. #7

    Default

    Could you please point me to an example?
    Thanks.

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

    Default

    You can find the documentation in the appendix. A short example would be:
    Code:
    <http ..>
      <form-login authentication-success-handler-ref="authSuccessHandler"/>
    </http>
    <b:bean id="authSuccessHandler" class="MyAuthenticationSuccessHandler"/>
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  9. #9

    Default

    Yes, I am aware of that, but as I mentioned, being a REST API only, there is no <form-login> element.
    Eugen.

Tags for this Thread

Posting Permissions

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