Announcement Announcement Module
Collapse
No announcement yet.
Spring Security JUnit Question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Security JUnit Question

    Hello,

    We have a custom security implementation (userdetails service, user etc) for a Spring MVC application. I am trying to write a JUnit test without having to go through the controller. I am looking to test my service methods directly. I am using the below in a Junit setup before i call the service method.

    SecurityContextHolder.getContext().setAuthenticati on(new UsernamePasswordAuthenticationToken(username,
    password));

    However i get a classcastexception when one of the method is executing auth.getPrincipal(). Is there a sequence of code that i should write to set a custom user object after i run setAuthentication so a subsequent call to getPrincipal returns an instance of CustomUser.

    thanks in advance,
    Prasad.
Working...
X