Skip to content

Commit 41d3c30

Browse files
committed
Merge branch '1.2.x' into 1.3.x
2 parents ce76f5c + 9addcf6 commit 41d3c30

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OAuth2AuthorizationEndpointConfigurer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,13 @@ void init(HttpSecurity httpSecurity) {
241241
? OAuth2ConfigurerUtils
242242
.withMultipleIssuersPattern(authorizationServerSettings.getAuthorizationEndpoint())
243243
: authorizationServerSettings.getAuthorizationEndpoint();
244-
this.requestMatcher = new OrRequestMatcher(
245-
new AntPathRequestMatcher(authorizationEndpointUri, HttpMethod.GET.name()),
246-
new AntPathRequestMatcher(authorizationEndpointUri, HttpMethod.POST.name()));
247-
244+
List<RequestMatcher> requestMatchers = new ArrayList<>();
245+
requestMatchers.add(new AntPathRequestMatcher(authorizationEndpointUri, HttpMethod.GET.name()));
246+
requestMatchers.add(new AntPathRequestMatcher(authorizationEndpointUri, HttpMethod.POST.name()));
247+
if (StringUtils.hasText(this.consentPage)) {
248+
requestMatchers.add(new AntPathRequestMatcher(this.consentPage));
249+
}
250+
this.requestMatcher = new OrRequestMatcher(requestMatchers);
248251
List<AuthenticationProvider> authenticationProviders = createDefaultAuthenticationProviders(httpSecurity);
249252
if (!this.authenticationProviders.isEmpty()) {
250253
authenticationProviders.addAll(0, this.authenticationProviders);

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OAuth2AuthorizationCodeGrantTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
105105
import org.springframework.security.oauth2.server.authorization.client.TestRegisteredClients;
106106
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
107+
import org.springframework.security.oauth2.server.authorization.context.AuthorizationServerContextHolder;
107108
import org.springframework.security.oauth2.server.authorization.jackson2.TestingAuthenticationTokenMixin;
108109
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
109110
import org.springframework.security.oauth2.server.authorization.settings.ClientSettings;
@@ -125,11 +126,14 @@
125126
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
126127
import org.springframework.security.web.context.SecurityContextRepository;
127128
import org.springframework.security.web.util.matcher.RequestMatcher;
129+
import org.springframework.stereotype.Controller;
128130
import org.springframework.test.web.servlet.MockMvc;
129131
import org.springframework.test.web.servlet.MvcResult;
130132
import org.springframework.util.LinkedMultiValueMap;
131133
import org.springframework.util.MultiValueMap;
132134
import org.springframework.util.StringUtils;
135+
import org.springframework.web.bind.annotation.GetMapping;
136+
import org.springframework.web.bind.annotation.ResponseBody;
133137
import org.springframework.web.util.UriComponents;
134138
import org.springframework.web.util.UriComponentsBuilder;
135139
import org.springframework.web.util.UriUtils;
@@ -746,6 +750,15 @@ public void requestWhenCustomConsentPageConfiguredThenRedirect() throws Exceptio
746750
assertThat(authorization).isNotNull();
747751
}
748752

753+
// gh-1668
754+
@Test
755+
public void requestWhenCustomConsentPageConfiguredThenAuthorizationServerContextIsAccessible() throws Exception {
756+
this.spring.register(AuthorizationServerConfigurationCustomConsentPageAccessAuthorizationServerContext.class)
757+
.autowire();
758+
759+
this.mvc.perform(get(consentPage).with(user("user"))).andExpect(status().isOk());
760+
}
761+
749762
@Test
750763
public void requestWhenCustomConsentCustomizerConfiguredThenUsed() throws Exception {
751764
this.spring.register(AuthorizationServerConfigurationCustomConsentRequest.class).autowire();
@@ -1209,6 +1222,26 @@ SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) th
12091222

12101223
}
12111224

1225+
@EnableWebSecurity
1226+
@Configuration(proxyBeanMethods = false)
1227+
static class AuthorizationServerConfigurationCustomConsentPageAccessAuthorizationServerContext
1228+
extends AuthorizationServerConfigurationCustomConsentPage {
1229+
1230+
@Controller
1231+
class ConsentController {
1232+
1233+
@GetMapping("/oauth2/consent")
1234+
@ResponseBody
1235+
String consent() {
1236+
// Ensure the AuthorizationServerContext is accessible
1237+
AuthorizationServerContextHolder.getContext().getIssuer();
1238+
return "";
1239+
}
1240+
1241+
}
1242+
1243+
}
1244+
12121245
@EnableWebSecurity
12131246
@Configuration(proxyBeanMethods = false)
12141247
static class AuthorizationServerConfigurationCustomConsentRequest extends AuthorizationServerConfiguration {

0 commit comments

Comments
 (0)