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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:22:39+00:00 2026-06-15T14:22:39+00:00

I have an object that’s marked as @ConversationScoped and is used between many steps

  • 0

I have an object that’s marked as @ConversationScoped and is used between many steps of a wizard.

This works perfectly except that when my user’s are login in, the SessionFixationProtectionStrategy of Spring calls the session.invalidate() method to recreate a new session with a new id. It then goes and reattach the attributes of the invalidated session to the new one.

The problem is that there’s a WeldListener instance that is bound to the sessionDestroyed event and that will kill @ConversationScoped instances that are bound to the HttpSession object.

I have disabled the SessionFixationProtectionStrategy and am now using NullAuthenticatedSessionStrategy which does nothing, but I would still like to keep the Session Fixation strategy to protect my site from this.

Any suggestions on how to work around this?

  • 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-15T14:22:41+00:00Added an answer on June 15, 2026 at 2:22 pm

    Here’s a strategy I’m using:

    1. Detach the weld contexts (session and conversation) from the current session.
    2. After copying all session attributes, remove them from the session before invalidating it (for some reason not doing this doesn’t work, probably a session destruction listener somewhere in weld)
    3. Create new session, copy in attributes from previous session
    4. Reattach weld contexts.

    You need to copy the SessionFixationProtectionStrategy class to be able to implement this since there are no appropriate hooks already in place. Here’s the onAuthenticate.

    public void onAuthentication(Authentication authentication, HttpServletRequest request, HttpServletResponse response) {
            boolean hadSessionAlready = request.getSession(false) != null;
    
            if (!hadSessionAlready && !alwaysCreateSession) {
                // Session fixation isn't a problem if there's no session
    
                return;
            }
    
            // Create new session if necessary
            HttpSession session = request.getSession();
    
            if (hadSessionAlready && request.isRequestedSessionIdValid()) {
                // We need to migrate to a new session
                String originalSessionId = session.getId();
    
                if (logger.isDebugEnabled()) {
                    logger.debug("Invalidating session with Id '" + originalSessionId +"' " + (migrateSessionAttributes ?
                            "and" : "without") +  " migrating attributes.");
                }
    
                String id = weldAwareSessionFixationProtectionStrategyHelper.beforeInvalidateSession( request );
    
                Map<String, Object> attributesToMigrate = extractAttributes(session);
    
                for( String key : attributesToMigrate.keySet() ) {
                    session.removeAttribute( key );
                }
    
    
                session.invalidate();
                session = request.getSession(true); // we now have a new session
    
                if (logger.isDebugEnabled()) {
                    logger.debug("Started new session: " + session.getId());
                }
    
    
                if (originalSessionId.equals(session.getId())) {
                    logger.warn("Your servlet container did not change the session ID when a new session was     created. You will" +
                            " not be adequately protected against session-fixation attacks");
                }
    
                transferAttributes(attributesToMigrate, session);
    
                weldAwareSessionFixationProtectionStrategyHelper.afterCreateNewSession( request, id );
    
                onSessionChange(originalSessionId, session, authentication);
            }
        }
    

    … and here’s the WeldAwareSessionFixationProtectionStrategyHelper

    @ApplicationScoped
    public class WeldAwareSessionFixationProtectionStrategyHelper {
    
        @Inject
        private HttpSessionContext httpSessionContext;
    
        @Inject
        private HttpConversationContext httpConversationContext;
    
        public String beforeInvalidateSession( HttpServletRequest httpServletRequest ) {
    
            String currentId = null;
    
            if( !httpConversationContext.getCurrentConversation().isTransient() ) {
                currentId = httpConversationContext.getCurrentConversation().getId();
            }
    
            httpConversationContext.deactivate();
            httpConversationContext.dissociate( httpServletRequest );
    
            httpSessionContext.deactivate();
            httpSessionContext.dissociate( httpServletRequest );
    
            return currentId;
        }
    
        public void afterCreateNewSession( HttpServletRequest httpServletRequest, String cid ) {
    
            httpSessionContext.associate( httpServletRequest );
            httpSessionContext.activate();
    
            httpConversationContext.associate( httpServletRequest );
    
            if( cid == null ) {
                httpConversationContext.activate();
            } else {
                httpConversationContext.activate( cid );            
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that has pairs of replacement values used for simple encoding
I have an object that looks like this { AF : { name :
I have an object that I am developing a controller for that has many
I have JSON Object that looks something like the below object, this object can
I have an object that I need to serialize in C#, however this object
I have an object that looks like this. { par1: 'par1value', par2: 'par2value', par3:
i have an object that is something like this with a full namespace. MyDomainModel.Model.Application
i have an object that, at its most basic level, looks like this: #include
I have an object that I want to segue between two MVC's. Do the
I have an object that looks like this: StandardFormat({ HeaderFont: 'greentext2', HeaderLinkFont: 'bluelink3', Backcolor:

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.