spring-projects/spring-security — pull request #47 by hkarakose (2013-10-02 17:12:57+00:00)
Title: fix for invalid exception after calling setAuthenticated() even though constructor which takes a GrantedAuthority list is used

Following code produces an exception with misleading exception message:
ArrayList authorities = new ArrayList();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication customAuthentication =
new UsernamePasswordAuthenticationToken("ROLE_USER", authentication, authorities);
customAuthentication.setAuthenticated(true);

Following is the exception the code produces:

java.lang.IllegalArgumentException: Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead
at org.springframework.security.authentication.UsernamePasswordAuthenticationToken.setAuthenticated(UsernamePasswordAuthenticationToken.java:87)
at com.gamenism.server.auth.CustomAuthenticationProvider.authenticate(CustomAuthenticationProvider.java:45)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)