• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Spring MVC + Spring security - I wonder....  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi good people,

I'm coding a simple blogging portal using Spring MVC and Spring Security + Hibernate. Im stuck on problem I don't know how to solve. The problem is in create blog functionality. User inputs title of new blog and description. Now to succesfully store the new blog in DB (I want to do this from within controller) i need UserId property of Blog object to be filled in with current user in session id. But I've got no idea how to get to the id from within controller. From jsp i can use request.GetUserPrincipal().getName() and execute it agains dao, but I don't think that using dao from jsp level is a good idea. I've got this feeling that I can't see the solution which probably is simple. Help!
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Spring Security docs give the following code to get user details -



You could call this code in a controller or service and pass the information to your dao.
 
Jay Chmiel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine, thanks for help .
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!