• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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, -
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic