Skip to content

Commit ab6f4e4

Browse files
committed
Revert "AuthorizationServerContext is accessible in custom consent controller"
This reverts commit 9addcf6. Closes spring-projectsgh-1668 in 1.2.x
1 parent 9addcf6 commit ab6f4e4

File tree

2 files changed

+7
-43
lines changed

2 files changed

+7
-43
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2023 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.
@@ -237,15 +237,12 @@ void setSessionAuthenticationStrategy(SessionAuthenticationStrategy sessionAuthe
237237
void init(HttpSecurity httpSecurity) {
238238
AuthorizationServerSettings authorizationServerSettings = OAuth2ConfigurerUtils
239239
.getAuthorizationServerSettings(httpSecurity);
240-
List<RequestMatcher> requestMatchers = new ArrayList<>();
241-
requestMatchers.add(new AntPathRequestMatcher(authorizationServerSettings.getAuthorizationEndpoint(),
242-
HttpMethod.GET.name()));
243-
requestMatchers.add(new AntPathRequestMatcher(authorizationServerSettings.getAuthorizationEndpoint(),
244-
HttpMethod.POST.name()));
245-
if (StringUtils.hasText(this.consentPage)) {
246-
requestMatchers.add(new AntPathRequestMatcher(this.consentPage));
247-
}
248-
this.requestMatcher = new OrRequestMatcher(requestMatchers);
240+
this.requestMatcher = new OrRequestMatcher(
241+
new AntPathRequestMatcher(authorizationServerSettings.getAuthorizationEndpoint(),
242+
HttpMethod.GET.name()),
243+
new AntPathRequestMatcher(authorizationServerSettings.getAuthorizationEndpoint(),
244+
HttpMethod.POST.name()));
245+
249246
List<AuthenticationProvider> authenticationProviders = createDefaultAuthenticationProviders(httpSecurity);
250247
if (!this.authenticationProviders.isEmpty()) {
251248
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: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
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;
108107
import org.springframework.security.oauth2.server.authorization.jackson2.TestingAuthenticationTokenMixin;
109108
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
110109
import org.springframework.security.oauth2.server.authorization.settings.ClientSettings;
@@ -126,14 +125,11 @@
126125
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
127126
import org.springframework.security.web.context.SecurityContextRepository;
128127
import org.springframework.security.web.util.matcher.RequestMatcher;
129-
import org.springframework.stereotype.Controller;
130128
import org.springframework.test.web.servlet.MockMvc;
131129
import org.springframework.test.web.servlet.MvcResult;
132130
import org.springframework.util.LinkedMultiValueMap;
133131
import org.springframework.util.MultiValueMap;
134132
import org.springframework.util.StringUtils;
135-
import org.springframework.web.bind.annotation.GetMapping;
136-
import org.springframework.web.bind.annotation.ResponseBody;
137133
import org.springframework.web.util.UriComponents;
138134
import org.springframework.web.util.UriComponentsBuilder;
139135
import org.springframework.web.util.UriUtils;
@@ -750,15 +746,6 @@ public void requestWhenCustomConsentPageConfiguredThenRedirect() throws Exceptio
750746
assertThat(authorization).isNotNull();
751747
}
752748

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-
762749
@Test
763750
public void requestWhenCustomConsentCustomizerConfiguredThenUsed() throws Exception {
764751
this.spring.register(AuthorizationServerConfigurationCustomConsentRequest.class).autowire();
@@ -1179,26 +1166,6 @@ SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) th
11791166

11801167
}
11811168

1182-
@EnableWebSecurity
1183-
@Configuration(proxyBeanMethods = false)
1184-
static class AuthorizationServerConfigurationCustomConsentPageAccessAuthorizationServerContext
1185-
extends AuthorizationServerConfigurationCustomConsentPage {
1186-
1187-
@Controller
1188-
class ConsentController {
1189-
1190-
@GetMapping("/oauth2/consent")
1191-
@ResponseBody
1192-
String consent() {
1193-
// Ensure the AuthorizationServerContext is accessible
1194-
AuthorizationServerContextHolder.getContext().getIssuer();
1195-
return "";
1196-
}
1197-
1198-
}
1199-
1200-
}
1201-
12021169
@EnableWebSecurity
12031170
@Configuration(proxyBeanMethods = false)
12041171
static class AuthorizationServerConfigurationCustomConsentRequest extends AuthorizationServerConfiguration {

0 commit comments

Comments
 (0)