Skip to content

Commit 914b958

Browse files
committed
Merge branch '1.3.x'
2 parents 36d76a4 + 6120c31 commit 914b958

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/support/BearerTokenAuthenticationExtractor.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222

2323
import reactor.core.publisher.Mono;
2424

25+
import org.springframework.lang.Nullable;
2526
import org.springframework.security.core.Authentication;
2627
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
2728
import org.springframework.security.oauth2.server.resource.BearerTokenError;
@@ -68,7 +69,7 @@ public BearerTokenAuthenticationExtractor(String authorizationKey) {
6869

6970
@Override
7071
public Mono<Authentication> getAuthentication(Map<String, Object> payload) {
71-
String authorizationValue = (String) payload.get(this.authorizationKey);
72+
String authorizationValue = getAuthorizationValue(payload);
7273
if (authorizationValue == null) {
7374
return Mono.empty();
7475
}
@@ -88,4 +89,18 @@ public Mono<Authentication> getAuthentication(Map<String, Object> payload) {
8889
return Mono.just(new BearerTokenAuthenticationToken(token));
8990
}
9091

92+
@Nullable
93+
private String getAuthorizationValue(Map<String, Object> payload) {
94+
String value = (String) payload.get(this.authorizationKey);
95+
if (value != null) {
96+
return value;
97+
}
98+
for (String key : payload.keySet()) {
99+
if (key.equalsIgnoreCase(this.authorizationKey)) {
100+
return (String) payload.get(key);
101+
}
102+
}
103+
return null;
104+
}
105+
91106
}

spring-graphql/src/test/java/org/springframework/graphql/server/support/BearerTokenAuthenticationExtractorTests.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,14 @@ void extract() {
4646
assertThat(auth.getName()).isEqualTo("123456789");
4747
}
4848

49+
@Test // gh-1116
50+
void extractCaseInsensitive() {
51+
Authentication auth = getAuthentication(Map.of("authorization", "Bearer 123456789"));
52+
53+
assertThat(auth).isNotNull();
54+
assertThat(auth.getName()).isEqualTo("123456789");
55+
}
56+
4957
@Test
5058
void noToken() {
5159
Authentication auth = getAuthentication(Collections.emptyMap());

0 commit comments

Comments
 (0)