File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How do I get a UserDetails object from a Principal object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How do I get a UserDetails object from a Principal object?" Watch "How do I get a UserDetails object from a Principal object?" New topic
Author

How do I get a UserDetails object from a Principal object?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Spring 3.1.0.RELEASE and Spring security 3.1. To better help with JUnit testing, I was told I can inject my Princpal object into my controller methods ...



The problem is I can no longer get back to my original UserDetails object that I logged in with. I get a ClassCastException on the "final Registration currentUser = (Registration) principal" line above. Before, I used



and everything worked like a dream, except I couldn't easily do JUnit testing. How do I get my UserDetails object from an injected Principal? Here is the domain object I'm logging in with ...

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
To get a UserDetails object from a Principal object use



Now with all the extra time you've saved by finding this answer, you can go back to checking your MyLife account, -
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17256
    
    6

Dave Alvarado wrote:To get a UserDetails object from a Principal object use



Now with all the extra time you've saved by finding this answer, you can go back to checking your MyLife account, -


Who uses MyLife???

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I get a UserDetails object from a Principal object?