This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Keeping the user acegi retrieved

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I've got a question about using acegi. Supose I configure it to use basic or form authentication, and to use my users DB. Spring will retrieve the user from the DB. In the rest of the application I'll need to know the user in order to show only that user data (sales, messages...). But how can I access the user data Spring retrieved.

I don't want that first Spring access the databse and later, in the same request my code access the databse again to retrieve the same data. Is there a way I can access DB only once? Is there a way to access the info Tomcat stores in session?

That's absolutely necessary. Otherwise I'd have to ask the user to login once again as I know the user is logged but I don't know wich user is it.

Thank you very much.

Antonio
 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use Spring Security, the Principal(user) is stored in the SecurityContext. And I believe that there is a helper class that has a method that you can call to get the Principal, I just don't remember the class name.

WebContextUtils or something like that.

Mark
 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is SecurityContextHolder. To get the principal you can do:
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. That's what I needed to know.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!