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

  • Home
  • SEARCH
  • 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 8171699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:32:25+00:00 2026-06-06T21:32:25+00:00

I have a Web app using Spring 3.1.1 and Spring Security 3.1.0. I implemented

  • 0

I have a Web app using Spring 3.1.1 and Spring Security 3.1.0. I implemented an ApplicationListener that checks SessionDestroyedEvent(s) and should log the username and other data. However, the getSecurityContexts() always returns an empty Collection. I am authenticating against an LDAP server. I also checked the getSource() method and it returns session data which holds the Principal information. However, the objects are container specific implementations which differ and there is no interface/abstract class that I can use. My question is whether this is a bug in SpringSecurity, or can I do some additional configuration?

Here is some relevant code:

@Service
public class ApplicationSecurityListener implements ApplicationListener<ApplicationEvent>{

@Override
  public void onApplicationEvent(ApplicationEvent event)
  {
           else if ( event instanceof SessionDestroyedEvent )
    {
        SessionDestroyedEvent sessinEvent = ( SessionDestroyedEvent ) event;
        //System.out.println ( "SessionDestroyedEvent:" + sessinEvent.getId() );
        //load session if it is not empty
        if(sessinEvent.getSecurityContexts() != null && !sessinEvent.getSecurityContexts().isEmpty())
        {
            ...
            }}}}
  • 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-06T21:32:26+00:00Added an answer on June 6, 2026 at 9:32 pm

    This is a bug in 3.1.0 that will be released as part of 3.1.1 (see SEC-1870). Until 3.1.1 is released you can get around the issue by obtaining the SecurityContext’s in onApplicationEvent manually. Using the changeset from the previously mentioned JIRA as a guide you would come up with something like this:

    public void onApplicationEvent(ApplicationEvent event) {
        if(event instanceof SessionDestroyedEvent) {
            SessionDestroyedEvent sdEvent = (SessionDestroyedEvent) event;    
            HttpSession session = sdEvent.getSession();    
            Enumeration<String> attributes = session.getAttributeNames();    
            ArrayList<SecurityContext> contexts = new ArrayList<SecurityContext>();
    
            while(attributes.hasMoreElements()) {
                String attributeName = attributes.nextElement();
                Object attributeValue = session.getAttribute(attributeName);
                if (attributeValue instanceof SecurityContext) {
                    contexts.add((SecurityContext) attributeValue);
                }
            }
            /* ... do things with the contexts (may be empty) ...*/
        }
    
        /* ... handle other conditions ... */
    
    }
    

    If you know there is only a single SecurityContext and you haven’t changed the attribute name the SecurityContext is stored in (typical) you can also obtain it using the following:

    public void onApplicationEvent(ApplicationEvent event) {
        if(event instanceof SessionDestroyedEvent) {
            SessionDestroyedEvent sdEvent = (SessionDestroyedEvent) event;    
            HttpSession session = sdEvent.getSession();
            String attrName = HttpSessionSecurityContextRepository
                .SPRING_SECURITY_CONTEXT_KEY;
            SecurityContext context = session.getAttribute(attrName);
    
            /* ... do things with the context (may be null) ...*/
        }
    
        /* ... handle other conditions ... */
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Tomcat 6.0.32, Spring Security 3.0.5 In my web app some users have
I have a problem applying css to the web pages, using spring security (3.0.7
I am using spring mvc and spring security. In my security-app-context.xml I have: <authentication-manager>
I am trying to use Spring Security 3.1 in my web app. I have
I'm writing a web app using grails and spring-security 3.0.3 which requires me to
I have implemented a web service(.asmx) using .NET framework that returns me a hash
I am using Spring Security 3.0 with JSPs. I have created a RequireVerificationFilter that
I have set up i18n to my web app using Spring.It works fine.But I
I have a web app running Spring 3.0 and using Spring-MVC. I have a
I'm using Spring 3.1.1.Release, Security 3.1.0.Release. I've added login/logout to my web app, however

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.