Apply updated Code Style

Closes gh-13881
This commit is contained in:
Marcus Da Coregio
2023-09-29 11:44:32 -03:00
parent 650692964e
commit 64e2a2ff8b
1172 changed files with 10805 additions and 8768 deletions

View File

@@ -106,7 +106,7 @@ public final class BearerTokenError extends OAuth2Error {
private static boolean isErrorUriValid(String errorUri) {
return errorUri == null || errorUri.chars()
.allMatch((c) -> c == 0x21 || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
.allMatch((c) -> c == 0x21 || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
}
private static boolean isScopeValid(String scope) {

View File

@@ -141,9 +141,9 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
"Authentication must be of type BearerTokenAuthenticationToken");
BearerTokenAuthenticationToken token = (BearerTokenAuthenticationToken) authentication;
return this.issuerConverter.convert(token)
.flatMap((issuer) -> this.issuerAuthenticationManagerResolver.resolve(issuer).switchIfEmpty(
Mono.error(() -> new InvalidBearerTokenException("Invalid issuer " + issuer))))
.flatMap((manager) -> manager.authenticate(authentication));
.flatMap((issuer) -> this.issuerAuthenticationManagerResolver.resolve(issuer)
.switchIfEmpty(Mono.error(() -> new InvalidBearerTokenException("Invalid issuer " + issuer))))
.flatMap((manager) -> manager.authenticate(authentication));
}
}

View File

@@ -123,15 +123,16 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
// relying solely on the authorization server to validate this token (not checking
// 'exp', for example)
return responseEntity.bodyToMono(STRING_OBJECT_MAP)
.filter((body) -> (boolean) body.compute(OAuth2TokenIntrospectionClaimNames.ACTIVE, (k, v) -> {
if (v instanceof String) {
return Boolean.parseBoolean((String) v);
}
if (v instanceof Boolean) {
return v;
}
return false;
})).switchIfEmpty(Mono.error(() -> new BadOpaqueTokenException("Provided token isn't active")));
.filter((body) -> (boolean) body.compute(OAuth2TokenIntrospectionClaimNames.ACTIVE, (k, v) -> {
if (v instanceof String) {
return Boolean.parseBoolean((String) v);
}
if (v instanceof Boolean) {
return v;
}
return false;
}))
.switchIfEmpty(Mono.error(() -> new BadOpaqueTokenException("Provided token isn't active")));
}
private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims) {

View File

@@ -55,7 +55,7 @@ public final class DefaultBearerTokenResolver implements BearerTokenResolver {
if (authorizationHeaderToken != null) {
if (parameterToken != null) {
final BearerTokenError error = BearerTokenErrors
.invalidRequest("Found multiple bearer tokens in the request");
.invalidRequest("Found multiple bearer tokens in the request");
throw new OAuth2AuthenticationException(error);
}
return authorizationHeaderToken;

View File

@@ -69,7 +69,7 @@ public class BearerTokenAuthenticationFilter extends OncePerRequestFilter {
private final AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver;
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
.getContextHolderStrategy();
private AuthenticationEntryPoint authenticationEntryPoint = new BearerTokenAuthenticationEntryPoint();

View File

@@ -72,7 +72,7 @@ public class ServerBearerTokenAuthenticationConverter implements ServerAuthentic
if (authorizationHeaderToken != null) {
if (parameterToken != null) {
BearerTokenError error = BearerTokenErrors
.invalidRequest("Found multiple bearer tokens in the request");
.invalidRequest("Found multiple bearer tokens in the request");
throw new OAuth2AuthenticationException(error);
}
return authorizationHeaderToken;

View File

@@ -67,8 +67,8 @@ public class DelegatingJwtGrantedAuthoritiesConverterTests {
@Test
public void constructorWhenAuthoritiesConverterIsNullThenIllegalArgumentException() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new DelegatingJwtGrantedAuthoritiesConverter(
(Collection<Converter<Jwt, Collection<GrantedAuthority>>>) null));
.isThrownBy(() -> new DelegatingJwtGrantedAuthoritiesConverter(
(Collection<Converter<Jwt, Collection<GrantedAuthority>>>) null));
}
private Collection<String> authorityListToOrderedSet(Collection<GrantedAuthority> grantedAuthorities) {

View File

@@ -54,15 +54,15 @@ public class JwtAuthenticationConverterTests {
@Test
public void whenSettingNullGrantedAuthoritiesConverter() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(null))
.withMessage("jwtGrantedAuthoritiesConverter cannot be null");
.isThrownBy(() -> this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(null))
.withMessage("jwtGrantedAuthoritiesConverter cannot be null");
}
@Test
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Arrays
.asList(new SimpleGrantedAuthority("blah"));
.asList(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt);
Collection<GrantedAuthority> authorities = authentication.getAuthorities();

View File

@@ -55,7 +55,7 @@ public class JwtAuthenticationTokenTests {
@Test
public void constructorWhenJwtIsNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new JwtAuthenticationToken(null))
.withMessageContaining("token cannot be null");
.withMessageContaining("token cannot be null");
}
@Test

View File

@@ -123,7 +123,7 @@ public class JwtIssuerAuthenticationManagerResolverTests {
AuthenticationManager authenticationManager = authenticationManagerResolver.resolve(null);
assertThat(authenticationManager).isNotNull();
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> authenticationManager.authenticate(token));
.isThrownBy(() -> authenticationManager.authenticate(token));
Authentication authentication = authenticationManager.authenticate(token);
assertThat(authentication.isAuthenticated()).isTrue();
}
@@ -133,10 +133,12 @@ public class JwtIssuerAuthenticationManagerResolverTests {
public void resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager() throws Exception {
try (MockWebServer server = new MockWebServer()) {
String issuer = server.url("").toString();
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
TrustedIssuerJwtAuthenticationManagerResolver resolver = new TrustedIssuerJwtAuthenticationManagerResolver(
(iss) -> iss.equals(issuer));
AuthenticationManager authenticationManager = resolver.resolve(issuer);
@@ -231,15 +233,15 @@ public class JwtIssuerAuthenticationManagerResolverTests {
@Test
public void constructorWhenNullOrEmptyIssuersThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver((Collection) null));
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver((Collection) null));
assertThatIllegalArgumentException()
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver(Collections.emptyList()));
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver(Collections.emptyList()));
}
@Test
public void constructorWhenNullAuthenticationManagerResolverThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver((AuthenticationManagerResolver) null));
.isThrownBy(() -> new JwtIssuerAuthenticationManagerResolver((AuthenticationManagerResolver) null));
}
private Authentication withBearerToken(String token) {

View File

@@ -74,12 +74,15 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
public void resolveWhenUsingTrustedIssuerThenReturnsAuthenticationManager() throws Exception {
try (MockWebServer server = new MockWebServer()) {
String issuer = server.url("").toString();
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
JWSObject jws = new JWSObject(new JWSHeader(JWSAlgorithm.RS256),
new Payload(new JSONObject(Collections.singletonMap(JwtClaimNames.ISS, issuer))));
jws.sign(new RSASSASigner(TestKeys.DEFAULT_PRIVATE_KEY));
@@ -116,7 +119,7 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
assertThat(authenticationManager).isNotNull();
Authentication token = withBearerToken(jws.serialize());
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> authenticationManager.authenticate(token).block());
.isThrownBy(() -> authenticationManager.authenticate(token).block());
Authentication authentication = authenticationManager.authenticate(token).block();
assertThat(authentication.isAuthenticated()).isTrue();
}
@@ -126,10 +129,12 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
public void resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager() throws Exception {
try (MockWebServer server = new MockWebServer()) {
String issuer = server.url("").toString();
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
server.enqueue(new MockResponse().setResponseCode(200)
.setHeader("Content-Type", "application/json")
.setBody(JWK_SET));
TrustedIssuerJwtAuthenticationManagerResolver resolver = new TrustedIssuerJwtAuthenticationManagerResolver(
(iss) -> iss.equals(issuer));
ReactiveAuthenticationManager authenticationManager = resolver.resolve(issuer).block();
@@ -170,9 +175,10 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver(
(issuer) -> Mono.justOrEmpty(authenticationManagers.get(issuer)));
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> authenticationManagerResolver.resolve(null)
.flatMap((manager) -> manager.authenticate(token)).block())
.withMessageContaining("Invalid issuer");
.isThrownBy(() -> authenticationManagerResolver.resolve(null)
.flatMap((manager) -> manager.authenticate(token))
.block())
.withMessageContaining("Invalid issuer");
ReactiveAuthenticationManager authenticationManager = mock(ReactiveAuthenticationManager.class);
given(authenticationManager.authenticate(token)).willReturn(Mono.empty());
authenticationManagers.put("trusted", authenticationManager);
@@ -208,9 +214,10 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
"trusted");
Authentication token = withBearerToken(this.noIssuer);
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> authenticationManagerResolver.resolve(null)
.flatMap((manager) -> manager.authenticate(token)).block())
.withMessageContaining("Missing issuer");
.isThrownBy(() -> authenticationManagerResolver.resolve(null)
.flatMap((manager) -> manager.authenticate(token))
.block())
.withMessageContaining("Missing issuer");
}
@Test
@@ -230,9 +237,9 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
@Test
public void constructorWhenNullOrEmptyIssuersThenException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JwtIssuerReactiveAuthenticationManagerResolver((Collection) null));
.isThrownBy(() -> new JwtIssuerReactiveAuthenticationManagerResolver((Collection) null));
assertThatIllegalArgumentException()
.isThrownBy(() -> new JwtIssuerReactiveAuthenticationManagerResolver(Collections.emptyList()));
.isThrownBy(() -> new JwtIssuerReactiveAuthenticationManagerResolver(Collections.emptyList()));
}
@Test

View File

@@ -91,7 +91,7 @@ public class JwtReactiveAuthenticationManagerTests {
BearerTokenAuthenticationToken token = new BearerTokenAuthenticationToken("token-1");
given(this.jwtDecoder.decode(any())).willReturn(Mono.error(new BadJwtException("Oops")));
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.manager.authenticate(token).block());
.isThrownBy(() -> this.manager.authenticate(token).block());
}
// gh-7549

View File

@@ -54,7 +54,7 @@ public class OpaqueTokenAuthenticationProviderTests {
@Test
public void authenticateWhenActiveTokenThenOk() throws Exception {
OAuth2AuthenticatedPrincipal principal = TestOAuth2AuthenticatedPrincipals
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
OpaqueTokenIntrospector introspector = mock(OpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(principal);
OpaqueTokenAuthenticationProvider provider = new OpaqueTokenAuthenticationProvider(introspector);
@@ -106,7 +106,7 @@ public class OpaqueTokenAuthenticationProviderTests {
given(introspector.introspect(any())).willThrow(new OAuth2IntrospectionException("with \"invalid\" chars"));
OpaqueTokenAuthenticationProvider provider = new OpaqueTokenAuthenticationProvider(introspector);
assertThatExceptionOfType(AuthenticationServiceException.class)
.isThrownBy(() -> provider.authenticate(new BearerTokenAuthenticationToken("token")));
.isThrownBy(() -> provider.authenticate(new BearerTokenAuthenticationToken("token")));
}
@Test
@@ -136,7 +136,7 @@ public class OpaqueTokenAuthenticationProviderTests {
OpaqueTokenAuthenticationProvider provider = new OpaqueTokenAuthenticationProvider(introspector);
OpaqueTokenAuthenticationConverter authenticationConverter = mock(OpaqueTokenAuthenticationConverter.class);
given(authenticationConverter.convert(any(), any(OAuth2AuthenticatedPrincipal.class)))
.willReturn(new TestingAuthenticationToken(principal, null, Collections.emptyList()));
.willReturn(new TestingAuthenticationToken(principal, null, Collections.emptyList()));
provider.setAuthenticationConverter(authenticationConverter);
Authentication result = provider.authenticate(new BearerTokenAuthenticationToken("token"));

View File

@@ -55,7 +55,7 @@ public class OpaqueTokenReactiveAuthenticationManagerTests {
@Test
public void authenticateWhenActiveTokenThenOk() throws Exception {
OAuth2AuthenticatedPrincipal authority = TestOAuth2AuthenticatedPrincipals
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
ReactiveOpaqueTokenIntrospector introspector = mock(ReactiveOpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(Mono.just(authority));
OpaqueTokenReactiveAuthenticationManager provider = new OpaqueTokenReactiveAuthenticationManager(introspector);
@@ -101,10 +101,10 @@ public class OpaqueTokenReactiveAuthenticationManagerTests {
public void authenticateWhenIntrospectionEndpointThrowsExceptionThenInvalidToken() {
ReactiveOpaqueTokenIntrospector introspector = mock(ReactiveOpaqueTokenIntrospector.class);
given(introspector.introspect(any()))
.willReturn(Mono.error(new OAuth2IntrospectionException("with \"invalid\" chars")));
.willReturn(Mono.error(new OAuth2IntrospectionException("with \"invalid\" chars")));
OpaqueTokenReactiveAuthenticationManager provider = new OpaqueTokenReactiveAuthenticationManager(introspector);
assertThatExceptionOfType(AuthenticationServiceException.class)
.isThrownBy(() -> provider.authenticate(new BearerTokenAuthenticationToken("token")).block());
.isThrownBy(() -> provider.authenticate(new BearerTokenAuthenticationToken("token")).block());
}
@Test
@@ -135,7 +135,7 @@ public class OpaqueTokenReactiveAuthenticationManagerTests {
ReactiveOpaqueTokenAuthenticationConverter authenticationConverter = mock(
ReactiveOpaqueTokenAuthenticationConverter.class);
given(authenticationConverter.convert(any(), any(OAuth2AuthenticatedPrincipal.class)))
.willReturn(Mono.just(new TestingAuthenticationToken(principal, null, Collections.emptyList())));
.willReturn(Mono.just(new TestingAuthenticationToken(principal, null, Collections.emptyList())));
provider.setAuthenticationConverter(authenticationConverter);
Authentication result = provider.authenticate(new BearerTokenAuthenticationToken("token")).block();

View File

@@ -84,8 +84,10 @@ public class ReactiveJwtAuthenticationConverterAdapterTests {
@Test
public void convertWhenTokenHasBothScopeAndScpThenScopeAttributeIsTranslatedToAuthorities() {
Jwt jwt = TestJwts.jwt().claim("scp", Arrays.asList("message:read", "message:write"))
.claim("scope", "missive:read missive:write").build();
Jwt jwt = TestJwts.jwt()
.claim("scp", Arrays.asList("message:read", "message:write"))
.claim("scope", "missive:read missive:write")
.build();
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();
// @formatter:off

View File

@@ -53,15 +53,15 @@ public class ReactiveJwtAuthenticationConverterTests {
@Test
public void whenSettingNullGrantedAuthoritiesConverter() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(null))
.withMessage("jwtGrantedAuthoritiesConverter cannot be null");
.isThrownBy(() -> this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(null))
.withMessage("jwtGrantedAuthoritiesConverter cannot be null");
}
@Test
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Flux<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Flux
.just(new SimpleGrantedAuthority("blah"));
.just(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
AbstractAuthenticationToken authentication = this.jwtAuthenticationConverter.convert(jwt).block();
Collection<GrantedAuthority> authorities = authentication.getAuthorities();

View File

@@ -43,9 +43,12 @@ public class ReactiveJwtGrantedAuthoritiesConverterAdapterTests {
public void convertWithGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Arrays
.asList(new SimpleGrantedAuthority("blah"));
.asList(new SimpleGrantedAuthority("blah"));
Collection<GrantedAuthority> authorities = new ReactiveJwtGrantedAuthoritiesConverterAdapter(
grantedAuthoritiesConverter).convert(jwt).toStream().collect(Collectors.toList());
grantedAuthoritiesConverter)
.convert(jwt)
.toStream()
.collect(Collectors.toList());
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("blah"));
}

View File

@@ -165,7 +165,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(introspectUri, CLIENT_ID,
"wrong");
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
}
@@ -192,7 +192,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
.willReturn(response(new JSONObject(introspectedValues).toJSONString()));
.willReturn(response(new JSONObject(introspectedValues).toJSONString()));
OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token");
// @formatter:off
assertThat(authority.getAttributes())
@@ -211,7 +211,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
.willThrow(new IllegalStateException("server was unresponsive"));
.willThrow(new IllegalStateException("server was unresponsive"));
// @formatter:off
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"))
@@ -226,7 +226,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willReturn(response("malformed"));
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
@Test
@@ -236,7 +236,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willReturn(INVALID);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
@Test
@@ -246,7 +246,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willReturn(MALFORMED_ISSUER);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
// gh-7563
@@ -265,25 +265,25 @@ public class NimbusOpaqueTokenIntrospectorTests {
@Test
public void constructorWhenIntrospectionUriIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(null, CLIENT_ID, CLIENT_SECRET));
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(null, CLIENT_ID, CLIENT_SECRET));
}
@Test
public void constructorWhenClientIdIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null, CLIENT_SECRET));
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null, CLIENT_SECRET));
}
@Test
public void constructorWhenClientSecretIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
}
@Test
public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null));
.isThrownBy(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null));
}
@Test
@@ -292,7 +292,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
NimbusOpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> introspectionClient.setRequestEntityConverter(null));
.isThrownBy(() -> introspectionClient.setRequestEntityConverter(null));
}
@SuppressWarnings("unchecked")
@@ -324,7 +324,7 @@ public class NimbusOpaqueTokenIntrospectorTests {
assumeThat(stubResponse.getHeaders().getContentType()).isNull();
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("sometokenhere"));
.isThrownBy(() -> introspectionClient.introspect("sometokenhere"));
}
@ParameterizedTest(name = "{displayName} when Content-Type={0}")
@@ -332,14 +332,15 @@ public class NimbusOpaqueTokenIntrospectorTests {
MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE })
public void handleNonJsonContentType(String type) {
RestOperations restOperations = mock(RestOperations.class);
ResponseEntity<String> stubResponse = ResponseEntity.ok().contentType(MediaType.parseMediaType(type))
.body(ACTIVE_RESPONSE);
ResponseEntity<String> stubResponse = ResponseEntity.ok()
.contentType(MediaType.parseMediaType(type))
.body(ACTIVE_RESPONSE);
given(restOperations.exchange(any(RequestEntity.class), eq(String.class))).willReturn(stubResponse);
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("sometokenhere"));
.isThrownBy(() -> introspectionClient.introspect("sometokenhere"));
}
private static ResponseEntity<String> response(String content) {

View File

@@ -135,7 +135,7 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
NimbusReactiveOpaqueTokenIntrospector introspectionClient = new NimbusReactiveOpaqueTokenIntrospector(
introspectUri, CLIENT_ID, "wrong");
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block());
.isThrownBy(() -> introspectionClient.introspect("token").block());
}
}
@@ -146,8 +146,8 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
NimbusReactiveOpaqueTokenIntrospector introspectionClient = new NimbusReactiveOpaqueTokenIntrospector(
INTROSPECTION_URL, webClient);
assertThatExceptionOfType(BadOpaqueTokenException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block())
.withMessage("Provided token isn't active");
.isThrownBy(() -> introspectionClient.introspect("token").block())
.withMessage("Provided token isn't active");
}
@Test
@@ -189,7 +189,7 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
NimbusReactiveOpaqueTokenIntrospector introspectionClient = new NimbusReactiveOpaqueTokenIntrospector(
INTROSPECTION_URL, webClient);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block());
.isThrownBy(() -> introspectionClient.introspect("token").block());
}
@Test
@@ -209,31 +209,31 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
NimbusReactiveOpaqueTokenIntrospector introspectionClient = new NimbusReactiveOpaqueTokenIntrospector(
INTROSPECTION_URL, webClient);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block());
.isThrownBy(() -> introspectionClient.introspect("token").block());
}
@Test
public void constructorWhenIntrospectionUriIsEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET));
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET));
}
@Test
public void constructorWhenClientIdIsEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET));
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET));
}
@Test
public void constructorWhenClientSecretIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
}
@Test
public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null));
.isThrownBy(() -> new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null));
}
@Test
@@ -244,7 +244,7 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
INTROSPECTION_URL, client);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("sometokenhere").block());
.isThrownBy(() -> introspectionClient.introspect("sometokenhere").block());
}
@ParameterizedTest(name = "{displayName} when Content-Type={0}")
@@ -257,7 +257,7 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
INTROSPECTION_URL, client);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("sometokenhere").block());
.isThrownBy(() -> introspectionClient.introspect("sometokenhere").block());
}
private WebClient mockResponse(String response) {

View File

@@ -109,15 +109,15 @@ public class OAuth2IntrospectionAuthenticatedPrincipalTests {
@Test
public void constructorWhenAttributesIsNullOrEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new OAuth2IntrospectionAuthenticatedPrincipal(null, AUTHORITIES));
.isThrownBy(() -> new OAuth2IntrospectionAuthenticatedPrincipal(null, AUTHORITIES));
assertThatIllegalArgumentException()
.isThrownBy(() -> new OAuth2IntrospectionAuthenticatedPrincipal(Collections.emptyMap(), AUTHORITIES));
.isThrownBy(() -> new OAuth2IntrospectionAuthenticatedPrincipal(Collections.emptyMap(), AUTHORITIES));
}
@Test
public void constructorWhenAuthoritiesIsNullOrEmptyThenNoAuthorities() {
Collection<? extends GrantedAuthority> authorities = new OAuth2IntrospectionAuthenticatedPrincipal(CLAIMS, null)
.getAuthorities();
.getAuthorities();
assertThat(authorities).isEmpty();
authorities = new OAuth2IntrospectionAuthenticatedPrincipal(CLAIMS, Collections.emptyList()).getAuthorities();
assertThat(authorities).isEmpty();

View File

@@ -157,7 +157,7 @@ public class SpringOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new SpringOpaqueTokenIntrospector(introspectUri, CLIENT_ID,
"wrong");
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
}
@@ -184,7 +184,7 @@ public class SpringOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new SpringOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(STRING_OBJECT_MAP)))
.willReturn(response(introspectedValues));
.willReturn(response(introspectedValues));
OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token");
// @formatter:off
assertThat(authority.getAttributes())
@@ -203,7 +203,7 @@ public class SpringOpaqueTokenIntrospectorTests {
OpaqueTokenIntrospector introspectionClient = new SpringOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(STRING_OBJECT_MAP)))
.willThrow(new IllegalStateException("server was unresponsive"));
.willThrow(new IllegalStateException("server was unresponsive"));
// @formatter:off
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"))
@@ -218,7 +218,7 @@ public class SpringOpaqueTokenIntrospectorTests {
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(STRING_OBJECT_MAP))).willReturn(response("{}"));
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
@Test
@@ -228,7 +228,7 @@ public class SpringOpaqueTokenIntrospectorTests {
restOperations);
given(restOperations.exchange(any(RequestEntity.class), eq(STRING_OBJECT_MAP))).willReturn(INVALID);
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token"));
.isThrownBy(() -> introspectionClient.introspect("token"));
}
// gh-7563
@@ -247,25 +247,25 @@ public class SpringOpaqueTokenIntrospectorTests {
@Test
public void constructorWhenIntrospectionUriIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(null, CLIENT_ID, CLIENT_SECRET));
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(null, CLIENT_ID, CLIENT_SECRET));
}
@Test
public void constructorWhenClientIdIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, null, CLIENT_SECRET));
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, null, CLIENT_SECRET));
}
@Test
public void constructorWhenClientSecretIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
}
@Test
public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, null));
.isThrownBy(() -> new SpringOpaqueTokenIntrospector(INTROSPECTION_URL, null));
}
@Test
@@ -274,7 +274,7 @@ public class SpringOpaqueTokenIntrospectorTests {
SpringOpaqueTokenIntrospector introspectionClient = new SpringOpaqueTokenIntrospector(INTROSPECTION_URL,
restOperations);
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> introspectionClient.setRequestEntityConverter(null));
.isThrownBy(() -> introspectionClient.setRequestEntityConverter(null));
}
@SuppressWarnings("unchecked")

View File

@@ -133,7 +133,7 @@ public class SpringReactiveOpaqueTokenIntrospectorTests {
SpringReactiveOpaqueTokenIntrospector introspectionClient = new SpringReactiveOpaqueTokenIntrospector(
introspectUri, CLIENT_ID, "wrong");
assertThatExceptionOfType(OAuth2IntrospectionException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block());
.isThrownBy(() -> introspectionClient.introspect("token").block());
}
}
@@ -144,8 +144,8 @@ public class SpringReactiveOpaqueTokenIntrospectorTests {
SpringReactiveOpaqueTokenIntrospector introspectionClient = new SpringReactiveOpaqueTokenIntrospector(
INTROSPECTION_URL, webClient);
assertThatExceptionOfType(BadOpaqueTokenException.class)
.isThrownBy(() -> introspectionClient.introspect("token").block())
.withMessage("Provided token isn't active");
.isThrownBy(() -> introspectionClient.introspect("token").block())
.withMessage("Provided token isn't active");
}
@Test
@@ -196,25 +196,25 @@ public class SpringReactiveOpaqueTokenIntrospectorTests {
@Test
public void constructorWhenIntrospectionUriIsEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET));
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET));
}
@Test
public void constructorWhenClientIdIsEmptyThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET));
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET));
}
@Test
public void constructorWhenClientSecretIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null));
}
@Test
public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null));
.isThrownBy(() -> new SpringReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null));
}
private WebClient mockResponse(String response) {

View File

@@ -83,7 +83,7 @@ public class BearerTokenAuthenticationEntryPointTests {
this.authenticationEntryPoint.commence(request, response, new OAuth2AuthenticationException(error));
assertThat(response.getStatus()).isEqualTo(400);
assertThat(response.getHeader("WWW-Authenticate"))
.isEqualTo("Bearer error=\"invalid_request\", error_description=\"The access token expired\"");
.isEqualTo("Bearer error=\"invalid_request\", error_description=\"The access token expired\"");
}
@Test
@@ -95,7 +95,7 @@ public class BearerTokenAuthenticationEntryPointTests {
this.authenticationEntryPoint.commence(request, response, new OAuth2AuthenticationException(error));
assertThat(response.getStatus()).isEqualTo(400);
assertThat(response.getHeader("WWW-Authenticate"))
.isEqualTo("Bearer error=\"invalid_request\", error_uri=\"https://example.com\"");
.isEqualTo("Bearer error=\"invalid_request\", error_uri=\"https://example.com\"");
}
@Test
@@ -129,7 +129,7 @@ public class BearerTokenAuthenticationEntryPointTests {
this.authenticationEntryPoint.commence(request, response, new OAuth2AuthenticationException(error));
assertThat(response.getStatus()).isEqualTo(403);
assertThat(response.getHeader("WWW-Authenticate"))
.isEqualTo("Bearer error=\"insufficient_scope\", scope=\"test.read test.write\"");
.isEqualTo("Bearer error=\"insufficient_scope\", scope=\"test.read test.write\"");
}
@Test
@@ -142,9 +142,9 @@ public class BearerTokenAuthenticationEntryPointTests {
this.authenticationEntryPoint.setRealmName("test");
this.authenticationEntryPoint.commence(request, response, new OAuth2AuthenticationException(error));
assertThat(response.getStatus()).isEqualTo(403);
assertThat(response.getHeader("WWW-Authenticate")).isEqualTo(
"Bearer realm=\"test\", error=\"insufficient_scope\", error_description=\"Insufficient scope\", "
+ "error_uri=\"https://example.com\", scope=\"test.read test.write\"");
assertThat(response.getHeader("WWW-Authenticate"))
.isEqualTo("Bearer realm=\"test\", error=\"insufficient_scope\", error_description=\"Insufficient scope\", "
+ "error_uri=\"https://example.com\", scope=\"test.read test.write\"");
}
@Test

View File

@@ -94,7 +94,7 @@ public class DefaultBearerTokenResolverTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer ");
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining(("Bearer token is malformed"));
.withMessageContaining(("Bearer token is malformed"));
}
@Test
@@ -102,7 +102,7 @@ public class DefaultBearerTokenResolverTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer an\"invalid\"token");
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining(("Bearer token is malformed"));
.withMessageContaining(("Bearer token is malformed"));
}
@Test
@@ -113,7 +113,7 @@ public class DefaultBearerTokenResolverTests {
request.setContentType("application/x-www-form-urlencoded");
request.addParameter("access_token", TEST_TOKEN);
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining("Found multiple bearer tokens in the request");
.withMessageContaining("Found multiple bearer tokens in the request");
}
@Test
@@ -123,7 +123,7 @@ public class DefaultBearerTokenResolverTests {
request.setMethod("GET");
request.addParameter("access_token", TEST_TOKEN);
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining("Found multiple bearer tokens in the request");
.withMessageContaining("Found multiple bearer tokens in the request");
}
// gh-10326
@@ -133,7 +133,7 @@ public class DefaultBearerTokenResolverTests {
request.setMethod("GET");
request.addParameter("access_token", "token1", "token2");
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining("Found multiple bearer tokens in the request");
.withMessageContaining("Found multiple bearer tokens in the request");
}
// gh-10326
@@ -144,7 +144,7 @@ public class DefaultBearerTokenResolverTests {
request.setContentType("application/x-www-form-urlencoded");
request.addParameter("access_token", "token1", "token2");
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request))
.withMessageContaining("Found multiple bearer tokens in the request");
.withMessageContaining("Found multiple bearer tokens in the request");
}
// gh-10326

View File

@@ -66,7 +66,7 @@ public class BearerTokenServerAccessDeniedHandlerTests {
this.accessDeniedHandler.handle(exchange, null).block();
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertThat(exchange.getResponse().getHeaders().get("WWW-Authenticate"))
.isEqualTo(Arrays.asList("Bearer realm=\"test\""));
.isEqualTo(Arrays.asList("Bearer realm=\"test\""));
}
@Test

View File

@@ -107,7 +107,7 @@ public class BearerTokenAuthenticationFilterTests {
new BearerTokenAuthenticationFilter(this.authenticationManager));
filter.doFilter(this.request, this.response, this.filterChain);
ArgumentCaptor<BearerTokenAuthenticationToken> captor = ArgumentCaptor
.forClass(BearerTokenAuthenticationToken.class);
.forClass(BearerTokenAuthenticationToken.class);
verify(this.authenticationManager).authenticate(captor.capture());
assertThat(captor.getValue().getPrincipal()).isEqualTo("token");
}
@@ -124,7 +124,7 @@ public class BearerTokenAuthenticationFilterTests {
filter.setSecurityContextRepository(securityContextRepository);
filter.doFilter(this.request, this.response, this.filterChain);
ArgumentCaptor<BearerTokenAuthenticationToken> captor = ArgumentCaptor
.forClass(BearerTokenAuthenticationToken.class);
.forClass(BearerTokenAuthenticationToken.class);
verify(this.authenticationManager).authenticate(captor.capture());
assertThat(captor.getValue().getPrincipal()).isEqualTo(token);
ArgumentCaptor<SecurityContext> contextArg = ArgumentCaptor.forClass(SecurityContext.class);
@@ -140,7 +140,7 @@ public class BearerTokenAuthenticationFilterTests {
given(this.authenticationManagerResolver.resolve(any())).willReturn(this.authenticationManager);
filter.doFilter(this.request, this.response, this.filterChain);
ArgumentCaptor<BearerTokenAuthenticationToken> captor = ArgumentCaptor
.forClass(BearerTokenAuthenticationToken.class);
.forClass(BearerTokenAuthenticationToken.class);
verify(this.authenticationManager).authenticate(captor.capture());
assertThat(captor.getValue().getPrincipal()).isEqualTo("token");
}
@@ -198,7 +198,7 @@ public class BearerTokenAuthenticationFilterTests {
BearerTokenAuthenticationFilter filter = addMocks(
new BearerTokenAuthenticationFilter(this.authenticationManager));
assertThatExceptionOfType(AuthenticationServiceException.class)
.isThrownBy(() -> filter.doFilter(this.request, this.response, this.filterChain));
.isThrownBy(() -> filter.doFilter(this.request, this.response, this.filterChain));
}
@Test

View File

@@ -69,9 +69,10 @@ public class ServerBearerExchangeFilterFunctionTests {
public void filterWhenAuthenticatedThenAuthorizationHeaderNull() throws Exception {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
this.function.filter(request, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication)).block();
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication))
.block();
assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION))
.isEqualTo("Bearer " + this.accessToken.getTokenValue());
.isEqualTo("Bearer " + this.accessToken.getTokenValue());
}
// gh-7353
@@ -80,16 +81,19 @@ public class ServerBearerExchangeFilterFunctionTests {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
TestingAuthenticationToken token = new TestingAuthenticationToken("user", "pass");
this.function.filter(request, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(token)).block();
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(token))
.block();
assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION)).isNull();
}
@Test
public void filterWhenExistingAuthorizationThenSingleAuthorizationHeader() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com"))
.header(HttpHeaders.AUTHORIZATION, "Existing").build();
.header(HttpHeaders.AUTHORIZATION, "Existing")
.build();
this.function.filter(request, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication)).block();
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication))
.block();
HttpHeaders headers = this.exchange.getRequest().headers();
assertThat(headers.get(HttpHeaders.AUTHORIZATION)).containsOnly("Bearer " + this.accessToken.getTokenValue());
}

View File

@@ -83,13 +83,14 @@ public class ServletBearerExchangeFilterFunctionTests {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
this.function.filter(request, this.exchange).subscriberContext(context(this.authentication)).block();
assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION))
.isEqualTo("Bearer " + this.accessToken.getTokenValue());
.isEqualTo("Bearer " + this.accessToken.getTokenValue());
}
@Test
public void filterWhenExistingAuthorizationThenSingleAuthorizationHeader() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com"))
.header(HttpHeaders.AUTHORIZATION, "Existing").build();
.header(HttpHeaders.AUTHORIZATION, "Existing")
.build();
this.function.filter(request, this.exchange).subscriberContext(context(this.authentication)).block();
HttpHeaders headers = this.exchange.getRequest().headers();
assertThat(headers.get(HttpHeaders.AUTHORIZATION)).containsOnly("Bearer " + this.accessToken.getTokenValue());

View File

@@ -53,7 +53,7 @@ public class BearerTokenServerAuthenticationEntryPointTests {
this.entryPoint.setRealmName("Realm");
this.entryPoint.commence(this.exchange, new BadCredentialsException("")).block();
assertThat(getResponse().getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE))
.isEqualTo("Bearer realm=\"Realm\"");
.isEqualTo("Bearer realm=\"Realm\"");
assertThat(getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@@ -63,7 +63,7 @@ public class BearerTokenServerAuthenticationEntryPointTests {
OAuth2AuthenticationException exception = new OAuth2AuthenticationException(oauthError);
this.entryPoint.commence(this.exchange, exception).block();
assertThat(getResponse().getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE))
.isEqualTo("Bearer error=\"invalid_request\"");
.isEqualTo("Bearer error=\"invalid_request\"");
assertThat(getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

View File

@@ -83,8 +83,8 @@ public class ServerBearerTokenAuthenticationConverterTests {
// gh-7011
@Test
public void resolveWhenValidHeaderIsEmptyStringThenTokenIsResolved() {
MockServerHttpRequest.BaseBuilder<?> request = MockServerHttpRequest.get("/").header(HttpHeaders.AUTHORIZATION,
"Bearer ");
MockServerHttpRequest.BaseBuilder<?> request = MockServerHttpRequest.get("/")
.header(HttpHeaders.AUTHORIZATION, "Bearer ");
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> convertToToken(request))
@@ -205,15 +205,15 @@ public class ServerBearerTokenAuthenticationConverterTests {
@Test
void resolveWhenQueryParameterHasMultipleAccessTokensThenOAuth2AuthenticationException() {
MockServerHttpRequest.BaseBuilder<?> request = MockServerHttpRequest.get("/").queryParam("access_token",
TEST_TOKEN, TEST_TOKEN);
MockServerHttpRequest.BaseBuilder<?> request = MockServerHttpRequest.get("/")
.queryParam("access_token", TEST_TOKEN, TEST_TOKEN);
assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> convertToToken(request))
.satisfies((ex) -> {
BearerTokenError error = (BearerTokenError) ex.getError();
assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST);
assertThat(error.getUri()).isEqualTo("https://tools.ietf.org/html/rfc6750#section-3.1");
assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
});
.satisfies((ex) -> {
BearerTokenError error = (BearerTokenError) ex.getError();
assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST);
assertThat(error.getUri()).isEqualTo("https://tools.ietf.org/html/rfc6750#section-3.1");
assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
});
}