1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Add UsernamePasswordAuthenticationToken factory methods

- unauthenticated factory method
 - authenticated factory method
 - test for unauthenticated factory method
 - test for authenticated factory method
 - make existing constructor protected
 - use newly factory methods in rest of the project
 - update copyright dates

Closes gh-10790
This commit is contained in:
Norbert Nowak
2022-03-08 11:33:13 +01:00
committed by Josh Cummings
parent d2f24ae5f5
commit ac9c29b2a0
99 changed files with 476 additions and 378 deletions
@@ -118,7 +118,7 @@ public class ContextPropagatingRemoteInvocation extends RemoteInvocation {
* Creates the server-side authentication request object.
*/
protected Authentication createAuthenticationRequest(String principal, String credentials) {
return new UsernamePasswordAuthenticationToken(principal, credentials);
return UsernamePasswordAuthenticationToken.unauthenticated(principal, credentials);
}
}
@@ -48,7 +48,8 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
@Test
public void testNormalOperation() throws Exception {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("Aladdin", "open sesame");
Authentication clientSideAuthentication = UsernamePasswordAuthenticationToken.unauthenticated("Aladdin",
"open sesame");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
// Create a connection and ensure our executor sets its
// properties correctly
@@ -56,7 +56,7 @@ public class ContextPropagatingRemoteInvocationTests {
@Test
public void testContextIsResetEvenIfExceptionOccurs() throws Exception {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
Authentication clientSideAuthentication = UsernamePasswordAuthenticationToken.unauthenticated("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
// Set up the wrong arguments.
@@ -70,7 +70,7 @@ public class ContextPropagatingRemoteInvocationTests {
@Test
public void testNormalOperation() throws Exception {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
Authentication clientSideAuthentication = UsernamePasswordAuthenticationToken.unauthenticated("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
// Set to null, as ContextPropagatingRemoteInvocation already obtained
@@ -95,7 +95,7 @@ public class ContextPropagatingRemoteInvocationTests {
// SEC-1867
@Test
public void testNullCredentials() throws Exception {
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", null);
Authentication clientSideAuthentication = UsernamePasswordAuthenticationToken.unauthenticated("rod", null);
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
assertThat(ReflectionTestUtils.getField(remoteInvocation, "credentials")).isNull();