wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes Spring MVC + Spring security - I wonder.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring MVC + Spring security - I wonder...." Watch "Spring MVC + Spring security - I wonder...." New topic

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

Jay Chmiel

Joined: Mar 13, 2009
Posts: 8
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

Joined: Oct 18, 2000
Posts: 4121

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.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jay Chmiel

Joined: Mar 13, 2009
Posts: 8
Works fine, thanks for help .
I agree. Here's the link: http://aspose.com/file-tools
subject: Spring MVC + Spring security - I wonder....
Similar Threads
Spring + MVC pattern in non-web application
Need some general help regarding MVC design.
Redirecting to an outside URL from HandlerInterceptor
Basic multi-player game questions
Send/receive request from jsp to a Spring portlet.