|
104 | 104 | import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository; |
105 | 105 | import org.springframework.security.oauth2.server.authorization.client.TestRegisteredClients; |
106 | 106 | import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; |
| 107 | +import org.springframework.security.oauth2.server.authorization.context.AuthorizationServerContextHolder; |
107 | 108 | import org.springframework.security.oauth2.server.authorization.jackson2.TestingAuthenticationTokenMixin; |
108 | 109 | import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings; |
109 | 110 | import org.springframework.security.oauth2.server.authorization.settings.ClientSettings; |
|
125 | 126 | import org.springframework.security.web.context.HttpSessionSecurityContextRepository; |
126 | 127 | import org.springframework.security.web.context.SecurityContextRepository; |
127 | 128 | import org.springframework.security.web.util.matcher.RequestMatcher; |
| 129 | +import org.springframework.stereotype.Controller; |
128 | 130 | import org.springframework.test.web.servlet.MockMvc; |
129 | 131 | import org.springframework.test.web.servlet.MvcResult; |
130 | 132 | import org.springframework.util.LinkedMultiValueMap; |
131 | 133 | import org.springframework.util.MultiValueMap; |
132 | 134 | import org.springframework.util.StringUtils; |
| 135 | +import org.springframework.web.bind.annotation.GetMapping; |
| 136 | +import org.springframework.web.bind.annotation.ResponseBody; |
133 | 137 | import org.springframework.web.util.UriComponents; |
134 | 138 | import org.springframework.web.util.UriComponentsBuilder; |
135 | 139 | import org.springframework.web.util.UriUtils; |
@@ -746,6 +750,15 @@ public void requestWhenCustomConsentPageConfiguredThenRedirect() throws Exceptio |
746 | 750 | assertThat(authorization).isNotNull(); |
747 | 751 | } |
748 | 752 |
|
| 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 | + |
749 | 762 | @Test |
750 | 763 | public void requestWhenCustomConsentCustomizerConfiguredThenUsed() throws Exception { |
751 | 764 | this.spring.register(AuthorizationServerConfigurationCustomConsentRequest.class).autowire(); |
@@ -1166,6 +1179,26 @@ SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) th |
1166 | 1179 |
|
1167 | 1180 | } |
1168 | 1181 |
|
| 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 | + |
1169 | 1202 | @EnableWebSecurity |
1170 | 1203 | @Configuration(proxyBeanMethods = false) |
1171 | 1204 | static class AuthorizationServerConfigurationCustomConsentRequest extends AuthorizationServerConfiguration { |
|
0 commit comments