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 9234119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:42:54+00:00 2026-06-18T06:42:54+00:00

Update : I’d expected this problem was related to the specific Spring version I

  • 0

Update: I’d expected this problem was related to the specific Spring version I was using, but Rob’s answer indicates it’s probably something specific to my environment. We’ve found a workaround for this particular issue (a filter that manually clears the session on login), so I’ve marked Rob’s answer as correct.


In my Spring application, my sessions are being persisted between logins. I’d like for the session to be cleared on login.

I am using Spring Security 2.0.4 (don’t ask), and my security configuration looks something like this

<security:http ...
session-fixation-protection="newSession">
...
        <security:logout invalidate-session="true" logout-success-url="/login.html" />
</security:http>

I was under the impression that session-fixation-protection=”newSession” would clear sessions on user logins. Another interesting point is that sessions are being cleared on logout, so invalidate-session=”true” has the desired effect.

When testing, I use the following methods:

@RequestMapping(value = "writeSession")
String writeSession(HttpServletRequest request) {
  request.getSession().setAttribute("username", MySecurityService.getLoggedInUsername());
  ...
}

@RequestMapping(value = "readSession")
String readSession(HttpServletRequest request) {
  log.info("Current username: " + request.getSession().getAttribute("username");
  ...
}

Then I:

  1. Login as user1
  2. Visit writeSession (sets session username to “user1”)
  3. Visit readSession (log output: Current username: user1)
  4. Login as user2 (without logging out)
  5. Visit readSession (log output: Current username: user1)

Note that if I logout between steps 3 and 4, I get the expected results (Current username: null)

  • 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-18T06:42:55+00:00Added an answer on June 18, 2026 at 6:42 am

    I created a sample that demonstrates that in general this should work. See the the so-clear-spring-session-on-login branch of this git repo for a working example.

    There could be a few things that may cause you issues depending on the rest of your configuration.

    • Can you share the rest of your Spring Security configuration? For example, if you are switching between HTTP and HTTPS it may be switching which session is being used. You might refer to the Spring Security FAQ for more details on what can go wrong with sessions.

    • What does the implementation of MySecurityService look like?

    • What does your web.xml look like?

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

Sidebar

Related Questions

Update : I edited the code, but the problem persists... Hi everyone, this is
(Update: Problem caused by zsh, see accepted answer) Long ago, I followed this great
Update: I posted my own answer below And there's a longer version of this
Update: This only seems to be a problem at some computers. The normal, intuitive
[update: I am using MySQL 4.1.25 ] I think this must be a simple
Update: I was able to solve this problem. I just remembered VBA use *
Update : answer on how to draw one using Superformula is at the end
UPDATE May this post be helpful for coders using RichTextBoxes. The Match is correct
UPDATE: Hopefully this is a better explanation of the problem: I'm trying to pass
Update Mr Wizard's answer gives pixel-perfect results, but it is Windows-only and destroys the

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.