Nov 21st, 2012, 12:11 PM
Spring Security JUnit Question
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,
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,
Tags for this Thread