SEC-688: java.lang.NullPointerException in AbstractAuthenticationToken.equals()

http://jira.springframework.org/browse/SEC-688
This commit is contained in:
Luke Taylor 2008-02-28 11:44:15 +00:00
parent e6e1f2586f
commit 709f78e481
3 changed files with 14 additions and 4 deletions

View File

@ -110,9 +110,16 @@ public abstract class AbstractAuthenticationToken implements Authentication {
if ((this.getCredentials() != null) && !this.getCredentials().equals(test.getCredentials())) {
return false;
}
if (this.getPrincipal() == null && test.getPrincipal() != null) {
return false;
}
return (this.getPrincipal().equals(test.getPrincipal())
&& (this.isAuthenticated() == test.isAuthenticated()));
if (this.getPrincipal() != null && !this.getPrincipal().equals(test.getPrincipal())) {
return false;
}
return this.isAuthenticated() == test.isAuthenticated();
}
return false;

View File

@ -45,4 +45,8 @@ public class X509AuthenticationTokenTests extends TestCase {
token.setAuthenticated(true);
assertTrue(token.isAuthenticated());
}
public void testEquals() throws Exception {
assertEquals(X509TestUtils.createToken(), X509TestUtils.createToken());
}
}

View File

@ -100,8 +100,7 @@ public class X509TestUtils {
return (X509Certificate) cf.generateCertificate(in);
}
public static X509AuthenticationToken createToken()
throws Exception {
public static X509AuthenticationToken createToken() throws Exception {
return new X509AuthenticationToken(buildTestCertificate());
}
}