Results 1 to 3 of 3

Thread: failureHandler.defaultFailureUrl = LASTPAGE

  1. #1
    Join Date
    Jul 2012
    Posts
    5

    Default failureHandler.defaultFailureUrl = LASTPAGE

    Right now i leaved the ajax authentication and i'm using the sample login form.
    <form class="dropdown-menu pull-right"
    action="${resource(file: 'j_spring_security_check')}"
    method="POST">

    <g:textField class='span2' name='j_username' placeholder="E-mail" />
    <gasswordField class='span2' name='j_password'
    placeholder="Senha" />
    <label><g:checkBox class='pull-left'
    name='_spring_security_remember_me' /> Mantenha-me conectado</label>
    <a href="password-resend.php" class="pull-left">Esqueci minha senha</a>
    <button type="submit" name="login"
    class="btn btn-success btn-small pull-right">Entrar</button>

    </form>
    The only problem is that i want to return to the form page after submitting it, so i found the Config.groovy variables:

    grails.plugins.springsecurity.failureHandler.defau ltFailureUrl = '/'
    grails.plugins.springsecurity.successHandler.defau ltTargetUrl="/main.gsp"

    But i have the logging form in every page of the system... so i want to return to the last page... like a refresh.

    How can i do this? I crowled the web, but no awnser yet

  2. #2
    Join Date
    Nov 2012
    Posts
    1

    Default Did you ever manage to accomplish that?

    Quote Originally Posted by dertyu765 View Post
    But i have the logging form in every page of the system... so i want to return to the last page... like a refresh.
    I'm in a similar situation... only that I have the login page in just two different locations, the home page and a dedicated log in page; and I want to return the user to where he/she previously was, not to the dedicated page (wich is what I'm currently doing)

    Did you manage to accomplish what you wanted?

  3. #3
    Join Date
    Sep 2012
    Location
    Bangalore,India
    Posts
    4

    Default

    i was able to resolve it by writing my own custom AuthenticationSuccessHandler and LOgoutAuthenticationSuccessHandler classes by extending SimpleUrlAuthenticationSuccessHandler and SimpleUrlLogoutSuccessHandler.

    i need logotsuccesshandler because i wanted to user to stay in the same page he was in when he clicked logout(because logout is in all the pages.)
    for UsernamePasswordAuthenticationFilter set bean property name="authenticationSuccessHandler" as your CustomAuthSuccessHandle

    Code:
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.security.core.Authentication;
    import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
    import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
    import org.springframework.security.web.savedrequest.RequestCache;
    import org.springframework.security.web.savedrequest.SavedRequest;
    
    public class CustomAuthSuccessHandler extends
    		SimpleUrlAuthenticationSuccessHandler {
    	private RequestCache requestCache = new HttpSessionRequestCache();
    
    	@Override
    	public void onAuthenticationSuccess(HttpServletRequest request,
    			HttpServletResponse response, Authentication authentication)
    			throws IOException, ServletException {
            SavedRequest savedRequest = requestCache.getRequest(request, response);
    
            if (savedRequest != null) {
            	// Use the DefaultSavedRequest URL
                String targetUrl = savedRequest.getRedirectUrl();
                logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl);
                getRedirectStrategy().sendRedirect(request, response, targetUrl);
            }
            String redirectUrl=request.getHeader("Referer");
            getRedirectStrategy().sendRedirect(request, response, redirectUrl);
            
        }
    
    }

    here i have used requestCache because when an unauthorized user access a authorized page, spring will redirect him to login page and after success login, our Customauthsuccesshandler will redirect to the page which he initially wanted to access.

    For LogoutFilter set bean property name="logoutSuccessHandler" as CustomLogoutSuccessHandler
    Code:
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.security.core.Authentication;
    import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
    
    public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
    
    	@Override
    	public void onLogoutSuccess(HttpServletRequest request,
    			HttpServletResponse response, Authentication authentication)
    			throws IOException, ServletException {
    		String redirectUrl=request.getHeader("Referer");
            getRedirectStrategy().sendRedirect(request, response, redirectUrl);
    	}
    
    }
    Regards,
    Sunil

Posting Permissions

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