-
Nov 21st, 2012, 12:11 PM
#1
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules