Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jay Chmiel
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!
 
Nathan Pruett
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic