Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:00:31+00:00 2026-06-04T05:00:31+00:00

I am using Spring Security 3.0.6 and I would like to be able to

  • 0

I am using Spring Security 3.0.6 and I would like to be able to do the following:

If the user is a on a page and a session timeout occurs, the user will be taken to the log in page and on valid log in redirected back to the page the timeout occurred on.

I currently have the following in my security.xml file.

<http auto-config="true" use-expressions="true">
    <form-login
        login-page="/login" 
        default-target-url="/main" 
        always-use-default-target="false"
        authentication-failure-url="/login.html?error=true"
        authentication-success-handler-ref="authenticationSuccessHandler" />
    <remember-me/>
    <logout logout-success-url="/login" />
</http>

This is my authentication class:

public class AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {

    String url = "";

    HttpSession session = request.getSession(false);
    if (session != null) {
        SavedRequest savedRequest = (SavedRequest) session.getAttribute(WebAttributes.SAVED_REQUEST);
        if (savedRequest != null) {
            url = savedRequest.getRedirectUrl();
        }
    }

    System.out.println("url: "+ url);

    if (url == "") {
        response.sendRedirect(request.getContextPath()+"/main");
    } else {
        response.sendRedirect(url);
    }
}

}

I send the user back to the log in page via javascript like:

window.location.href="/login";

The url is always null in my authentication class. How can I make this work so Spring will redirect to the correct page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:00:32+00:00Added an answer on June 4, 2026 at 5:00 am

    You don’t need to write any custom code since Spring Security can do that by default. Take a look to the documentation regarding authentication-success-handler-ref here.

    authentication-success-handler-ref

    This can be used as an alternative to default-target-url and always-use-default-target, giving you full control over the navigation flow after a successful authentication. The value should be the name of an AuthenticationSuccessHandler bean in the application context. By default, an implementation of SavedRequestAwareAuthenticationSuccessHandler is used and injected with the default-target-url.

    Reference to an AuthenticationSuccessHandler bean which should be used to handle a successful authentication request. Should not be used in combination with default-target-url (or always-use-default-target) as the implementation should always deal with navigation to the subsequent destination.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to configure spring MVC application using Spring security the following way.
I am using Spring Security 3.0.6. for modularity reasons, I would like to use
I'm using Spring Security and I would like to know which users are currently
I am using Spring framework mvc 3 + spring security 3. I would like
I would like to base my Spring Security configuration depending on the user's context
I am trying to programatically validate a user login/pass using Spring Security, so I
This code get's the currently logged in user, using the Spring Security Plugin (acegi):
I'm using spring-security and jQuery in my application. Main page uses loading content dynamically
How can I implement following functionality in a project using or without using spring-security.
I am using Google Web Toolkit for a project and would like the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.