SEC-2571: Improve wording of UsernamePasswordAuthenticationToken#setAuthenticated() error

This commit is contained in:
Rob Winch 2014-04-24 17:03:34 -05:00
parent 414289d466
commit 13c5750f5d
2 changed files with 4 additions and 1 deletions

View File

@ -85,7 +85,7 @@ public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationT
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
if (isAuthenticated) {
throw new IllegalArgumentException(
"Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
"Once created you cannot set this token to authenticated. Create a new instance using the constructor which takes a GrantedAuthority list will mark this as authenticated.");
}
super.setAuthenticated(false);

View File

@ -15,6 +15,7 @@
package org.springframework.security.authentication;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -58,6 +59,8 @@ public class UsernamePasswordAuthenticationTokenTests {
token.setAuthenticated(true);
fail("Should have prohibited setAuthenticated(true)");
} catch (IllegalArgumentException expected) {
// SEC-2540
assertThat(expected).hasMessage("Once created you cannot set this token to authenticated. Create a new instance using the constructor which takes a GrantedAuthority list will mark this as authenticated.");
}
}