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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:40:50+00:00 2026-06-07T21:40:50+00:00

I am developing an application using the Spring Security (3.1) and I encoutered the

  • 0

I am developing an application using the Spring Security (3.1) and I encoutered the following problem. When user logs out, I want to redirect to some custom URL depending if he logs out from a secure page or not. I wrote a custom LogoutHandler, that looks as follow:

@Override
public void onLogoutSuccess(HttpServletRequest request,
        HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {


    String refererUrl = request.getHeader("Referer");
    if (requiredAuthentication(refererUrl, authentication)) {
        response.sendRedirect(request.getContextPath());
    } else {
        response.sendRedirect(refererUrl);
    }
}

private boolean requiredAuthentication(String url, Authentication authentication){
    return !getPrivilegeEvaluator().isAllowed(url, authentication);
}

So, when the user is logging out from the non-secure page he is logged out and redirected to the same URL, and if he is logging ouf from secure page, he goes to index page.
The problem is, that Authentication object that comes to the method is always authenticated (even though, the method is called AFTER loggin out the user, acording to the specification).
My security context:

<http use-expressions="true" disable-url-rewriting="true" request-matcher-ref="requestMatcher" >


    <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" requires-channel="https" />
    <intercept-url pattern="/dashboard/**" access="hasRole('ROLE_OWNER')" requires-channel="https" />
    <intercept-url pattern="/**" access="permitAll"/>

    <form-login login-page="/login"
                authentication-success-handler-ref="successHandler"
                authentication-failure-url="/login"
                login-processing-url="/validate"  />

    <logout logout-url="/logout" invalidate-session="true" success-handler-ref="logoutSuccessHandler" />

    <remember-me services-ref="rememberMeServices" key="KEY"  use-secure-cookie="false" />

    <session-management session-fixation-protection="migrateSession">
        <concurrency-control max-sessions="1" />
    </session-management>

</http>

Do you have any idea, why received Authentication is still valid, when gettig to the logoutSuccessHandler? I can’t edit this object, because it’s fields are final (except the isAuthenticated, but it’s not checked by isAllowed() method..)

  • 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-07T21:40:51+00:00Added an answer on June 7, 2026 at 9:40 pm

    Looking at Spring Security source code, the LogoutFilter gets the Authentication object from the SecurityContextHolder, keeps it on a local variable, and removes it from the holder, via SecurityContextLogoutHandler. After all LogoutHandlers are called, it calls your LogoutSuccessHandler, and passes the Authentication object.

    Even that it says it is valid, it is not anymore in the SecurityContextHolder, so for Spring, the user is logged out.

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

Sidebar

Related Questions

I am developing a GWT application which im using Spring Security to handle the
I'm developing a web application using Spring, JSF 2 and Primefaces 3. I want
I'm developing a Grails (Version 1.3.3) Web-Application using the Grails Spring-Security Plugin, Spring-Security-Core-1.0.1 (which,
We are developing a web application using Spring framework and Hibernate ORM. As far
I am using spring 3.0.2 for developing a simple web based application like twitter.
I am developing a Java Web Application using JSF, Spring and Hibernate. I need
I'm developing an Android 3.1 and above application. I'm using Spring Framework 1.0.0.0RC1 for
I'm developing web application supported by Spring Integration. I'm using 1.0.4.RELEASE. I use CGLib
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I am developing a web application using Spring JS and Dojo Toolkit. In this

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.