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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:54:24+00:00 2026-06-14T18:54:24+00:00

I created a simple session scoped bean in Spring 3.1. It is supposed to

  • 0

I created a simple session scoped bean in Spring 3.1. It is supposed to give me easy access to the Company of the currently logged in user.

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class SessionData {

    private Company company;

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }
}

I am populating this bean with a Company in my custom authentication provider’s authenticate() method.

@Component(value = "authenticationProvider")
public class ProduxAuthenticationProvider implements AuthenticationProvider {

    private SessionData sessionData;
    private CompanyService companyService;

    @Autowired
    public ProduxAuthenticationProvider(SessionData sessionData, CompanyService companyService) {
        this.sessionData = sessionData;
        this.companyService = companyService;
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {

        // Authentication logic (token creation) removed for readability....

        Company company = companyService.findByUserProfile(profile);

        // Set company on session bean
        sessionData.setCompany(company);

        return token;
    }
}

And then I am trying to access the company field in ManagementHomeController, which runs after authentication has finished successfully.

@Controller
@RequestMapping(value = "/manage/home")
public class ManagementHomeController {

    private CourseService userService;
    private CompanyService companyService;
    private SessionData sessionData;

    @Autowired
    public ManagementHomeController(CourseService userService, CompanyService companyService, SessionData sessionData) {
        this.userService = userService;
        this.companyService = companyService;
        this.sessionData = sessionData;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String get(Model model) {
        model.addAttribute("mainContent", "content/managementHome");

        // sessionData.company is null here! Object id is same as in ProduxAuthenticationProvider

        return "main";
    }
}

Somehow in the ManagementHomeController the company field of SessionData is null, but it is the same object. I can see that because sessionData’s object ID is the same in ProduxAuthenticationProvider and ManagementHomeController.

Any idea why SessionData is losing its company along the way?

  • 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-14T18:54:25+00:00Added an answer on June 14, 2026 at 6:54 pm

    Not completely sure if this will work, but from I understand since you are injecting a session scoped bean into a filter which is called prior to the Spring Dispatcher servlet being called certain request attributes required for the scoped proxy to work correctly may not have been set correctly.

    The fix will be to move this logic to either a Spring Interceptor or to register a RequestContextListener in your web.xml

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

Sidebar

Related Questions

I created a simple Sudoku application, where each 3x3 squares is a user control,
Maybe someone can help me out. I have created a simple web user control,
I've created a simple script that allows a user to post a message, question
I created a simple component in my Yii project and there is a text
I'm doing a simple user with profile application. User registers and are automatically logged
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
Hello I`ve created simple WFC DataService and connected entit model with my database. This
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple

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.