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
28c7a4be11
commit
abd33389be
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -96,7 +96,7 @@ public class AuthenticationPayloadExchangeConverter implements PayloadExchangeAu
|
||||
String username = rawUsername.toString(StandardCharsets.UTF_8);
|
||||
ByteBuf rawPassword = AuthMetadataCodec.readPassword(rawAuthentication);
|
||||
String password = rawPassword.toString(StandardCharsets.UTF_8);
|
||||
return new UsernamePasswordAuthenticationToken(username, password);
|
||||
return UsernamePasswordAuthenticationToken.unauthenticated(username, password);
|
||||
}
|
||||
|
||||
private Authentication bearer(ByteBuf rawAuthentication) {
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,9 +49,8 @@ public class BasicAuthenticationPayloadExchangeConverter implements PayloadExcha
|
||||
return Mono.fromCallable(() -> this.metadataExtractor.extract(exchange.getPayload(), this.metadataMimetype))
|
||||
.flatMap((metadata) -> Mono
|
||||
.justOrEmpty(metadata.get(UsernamePasswordMetadata.BASIC_AUTHENTICATION_MIME_TYPE.toString())))
|
||||
.cast(UsernamePasswordMetadata.class)
|
||||
.map((credentials) -> new UsernamePasswordAuthenticationToken(credentials.getUsername(),
|
||||
credentials.getPassword()));
|
||||
.cast(UsernamePasswordMetadata.class).map((credentials) -> UsernamePasswordAuthenticationToken
|
||||
.unauthenticated(credentials.getUsername(), credentials.getPassword()));
|
||||
}
|
||||
|
||||
private static MetadataExtractor createDefaultExtractor() {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,8 +89,8 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
interceptor.intercept(exchange, authenticationPayloadChain).block();
|
||||
Authentication authentication = authenticationPayloadChain.getAuthentication();
|
||||
verify(this.authenticationManager).authenticate(this.authenticationArg.capture());
|
||||
assertThat(this.authenticationArg.getValue())
|
||||
.isEqualToComparingFieldByField(new UsernamePasswordAuthenticationToken("user", "password"));
|
||||
assertThat(this.authenticationArg.getValue()).isEqualToComparingFieldByField(
|
||||
UsernamePasswordAuthenticationToken.unauthenticated("user", "password"));
|
||||
assertThat(authentication).isEqualTo(expectedAuthentication);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user