Description
Henrik Baastrup (Migrated from SEC-2078) said:
The problem occurs when using pre-authentication with "check for principal change" set and the class there extends org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter using non String principals but e.g. java.security.Principal.
The problem is that the authentication manager will always authenticate even the principal has no changed, this can give problems with the authentication provider, and performance in the code.
The error is in line 145 in the AbstractPreAuthenticatedProcessingFilter class, the code:
if (currentUser.getName().equals(principal)) {
return false;
}
should be changed to something like:
if (principal instanceof Principal) {
return !currentUser.getName().equals(((Principal)principal).getName());
}
else {
return !currentUser.getName().equals(principal.toString());
}
The original code will only function when the passed principal parameter is of the type String. The code suggested will function for all type of objects there either implements the java.security.Principal interface or override the toString method.