|
1 | 1 | /* |
2 | | - * Copyright 2020-2024 the original author or authors. |
| 2 | + * Copyright 2020-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
35 | 35 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
36 | 36 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
37 | 37 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; |
| 38 | +import org.springframework.security.config.Customizer; |
38 | 39 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
39 | 40 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
40 | 41 | import org.springframework.security.oauth2.jose.TestJwks; |
@@ -80,6 +81,9 @@ public class OAuth2AuthorizationServerMetadataTests { |
80 | 81 | @Autowired |
81 | 82 | private JdbcOperations jdbcOperations; |
82 | 83 |
|
| 84 | + @Autowired |
| 85 | + private AuthorizationServerSettings authorizationServerSettings; |
| 86 | + |
83 | 87 | @BeforeAll |
84 | 88 | public static void setupClass() { |
85 | 89 | JWKSet jwkSet = new JWKSet(TestJwks.DEFAULT_RSA_JWK); |
@@ -155,6 +159,17 @@ public void requestWhenAuthorizationServerMetadataRequestAndMetadataCustomizerSe |
155 | 159 | hasItems("scope1", "scope2"))); |
156 | 160 | } |
157 | 161 |
|
| 162 | + @Test |
| 163 | + public void requestWhenAuthorizationServerMetadataRequestAndPushedAuthorizationRequestEnabledThenMetadataResponseIncludesPushedAuthorizationRequestEndpoint() |
| 164 | + throws Exception { |
| 165 | + this.spring.register(AuthorizationServerConfigurationWithPushedAuthorizationRequestEnabled.class).autowire(); |
| 166 | + |
| 167 | + this.mvc.perform(get(ISSUER.concat(DEFAULT_OAUTH2_AUTHORIZATION_SERVER_METADATA_ENDPOINT_URI))) |
| 168 | + .andExpect(status().is2xxSuccessful()) |
| 169 | + .andExpect(jsonPath("$.pushed_authorization_request_endpoint") |
| 170 | + .value(ISSUER.concat(this.authorizationServerSettings.getPushedAuthorizationRequestEndpoint()))); |
| 171 | + } |
| 172 | + |
158 | 173 | @EnableWebSecurity |
159 | 174 | @Import(OAuth2AuthorizationServerConfiguration.class) |
160 | 175 | static class AuthorizationServerConfiguration { |
@@ -226,4 +241,29 @@ AuthorizationServerSettings authorizationServerSettings() { |
226 | 241 |
|
227 | 242 | } |
228 | 243 |
|
| 244 | + @EnableWebSecurity |
| 245 | + @Configuration(proxyBeanMethods = false) |
| 246 | + static class AuthorizationServerConfigurationWithPushedAuthorizationRequestEnabled |
| 247 | + extends AuthorizationServerConfiguration { |
| 248 | + |
| 249 | + // @formatter:off |
| 250 | + @Bean |
| 251 | + SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
| 252 | + OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
| 253 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
| 254 | + http |
| 255 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 256 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 257 | + authorizationServer |
| 258 | + .pushedAuthorizationRequestEndpoint(Customizer.withDefaults()) |
| 259 | + ) |
| 260 | + .authorizeHttpRequests((authorize) -> |
| 261 | + authorize.anyRequest().authenticated() |
| 262 | + ); |
| 263 | + return http.build(); |
| 264 | + } |
| 265 | + // @formatter:on |
| 266 | + |
| 267 | + } |
| 268 | + |
229 | 269 | } |
0 commit comments