SEC-1867: Perform null check on Authentication.getCredentials() prior to calling toString()
This commit is contained in:
+5
-1
@@ -66,13 +66,17 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
|
||||
|
||||
if (currentUser != null) {
|
||||
principal = currentUser.getName();
|
||||
credentials = currentUser.getCredentials().toString();
|
||||
Object userCredentials = currentUser.getCredentials();
|
||||
credentials = userCredentials == null ? null : userCredentials.toString();
|
||||
} else {
|
||||
principal = credentials = null;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("RemoteInvocation now has principal: " + principal);
|
||||
if(credentials == null) {
|
||||
logger.debug("RemoteInvocation now has null credentials.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -22,6 +22,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -95,4 +96,13 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
|
||||
|
||||
assertEquals("some_string Authentication empty", remoteInvocation.invoke(new TargetObject()));
|
||||
}
|
||||
|
||||
// SEC-1867
|
||||
public void testNullCredentials() throws Exception {
|
||||
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", null);
|
||||
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
|
||||
|
||||
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
|
||||
assertEquals(null, ReflectionTestUtils.getField(remoteInvocation, "credentials"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user