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.