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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:17:57+00:00 2026-05-19T16:17:57+00:00

I am not sure how to solve the following problem/ realize my scenario. Maybe

  • 0

I am not sure how to solve the following problem/ realize my scenario. Maybe someone can give me some hints?

  1. I have a Spring MVC app with Spring Security. I also use a custom Login page. All works fine so far, I can authenticate and display the logged in user on my JSP using the following code.

    <sec:authorize ifAnyGranted="ROLE_USER">

    Logged in as <sec:authentication property="principal.username" />

    </sec:authorize>

  2. The users a re retreieved from a database right now. Code for that in XML is

    <jdbc-user-service data-source-ref="dataSource"
    users-by-username-query="SELECT username, password , '1' AS enabled FROM users WHERE username = ?"
    authorities-by-username-query="SELECT username, 'ROLE_USER' FROM users WHERE username = ?" />

All works fine. Problem is, I actually have a custom User class that I would like to use and probably keep in my session as later DB requests should filter the results according to the logged in User.id.

How would I do this?

  • What do I need to do to store my User object in my session? Is this the right way to do it?
  • I use Hibernate. What is Best pratice to filter request, e.g. for objects called “Task” (in a task manager), according to the logged in user? (I have a column and property user_id in the tasks-table in my MySQL DB)

Any help or hint is much appreciated. Just need some direction 🙂

  • 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-19T16:17:57+00:00Added an answer on May 19, 2026 at 4:17 pm

    If you are using Spring Security 3.x, you may want to check if Expression Based Access Control (@PostFilter, for instance) meets your requirement.

    For instance, if your Task objects has the username member, you could do something like this…

       @PostFilter("filterObject.username == authentication.name")
       public List<Task> getTasks() {
            ...
            tasks = TaskDao.findAll();
            return tasks;
        }
    

    This would return those tasks which belonged to the logged in user.

    This SO discussion is also possibly relevant.

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

Sidebar

Related Questions

i'm not sure how to solve the following problem: i have a triangle with
I have the following to solve and I'm not sure how to approach this:
I have a simple problem but I am not sure how to solve it.
I've got a problem I'm not sure how best to solve. I have an
So I have an issue that I'm not 100% sure on how to solve.
Not sure how to ask this, but i'll give it a try: I have
I am having the following problem that I cannot solve. Let's say I have
EDIT: Just to make sure someone is not breaking their head on the problem...
I have the following problem to solve: Currently we have a metadata tree of
I have some possibly ambiguous questions, I'm not sure if I'll get the right

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.