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:
committed by
Josh Cummings
parent
d2f24ae5f5
commit
ac9c29b2a0
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
+3
-3
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user