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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:50:42+00:00 2026-05-31T04:50:42+00:00

I am attempting to @Inject a @SessionScoped bean into a Filter @WebFilter(/*) public class

  • 0

I am attempting to @Inject a @SessionScoped bean into a Filter

@WebFilter("/*")
public class IdentityFilter implements Filter, Serializable {

    @Inject
    private LoginUser loginUser;
...

where LoginUser is @SessionScoped

The intention is for loginUser to represent the logged in user for the session.

The problem is it appears that I am not always getting the loginUser from the current session, I am getting ‘leakage’ between sessions as one session’s LoginUser object is being shared with another session. Obviously this isn’t good.

I am wondering if this is because the Filter object is a singleton, or at least reused between requests and sessions by the container (glassfish). (Right?)

Is there a better way to obtain the LoginUser object for the current session without using a property on the Filter?

  • 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-05-31T04:50:43+00:00Added an answer on May 31, 2026 at 4:50 am

    My problem is that there is only one instance of the Filter in the container, effectively a singleton. It seems that CDI injects the first session level object into the Filter at first use and then the Filter stores that reference forever, even for other sessions.

    I’ve found this solution, to inject a factory object (Instance) which I can use to get the session instance each time the Filter runs, i.e.

     @WebFilter("/*")
     public class IdentityFilter implements Filter, Serializable {
    
          @Inject 
          private Instance<LoginUser> loginUserSource;
    

    And in

     @Override
     public void doFilter(...)
          LoginUser login   = loginUserSource.get();
    

    This seems to fix my problem.

    Thanks

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

Sidebar

Related Questions

I am attempting to inject an annotated variable into the REQUEST scope: Map<Key<?>, Object>
I am receiving the following error when attempting to inject my dao into a
I'm attempting to use Ninject to inject repositories into controllers of my MVC project.
I am attempting to inject an object into my saga. Using the following endpoint,
Attempting to insert an escape character into a table results in a warning. For
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
Attempting to run a MIB based SNMP script and I running into an issue.
Trying to integrate Spring 2.5.5 with Xfire 1.2.6, I'm attempting to inject one of
Attempting to create a filter select to find schedules with coursedates within a given
I have a service bean (annotated with @Service) which implements the ApplicationListener inteface for

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.