|
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. |
@@ -232,9 +232,6 @@ public class OAuth2AuthorizationCodeGrantTests { |
232 | 232 | @Autowired |
233 | 233 | private OAuth2AuthorizationService authorizationService; |
234 | 234 |
|
235 | | - @Autowired |
236 | | - private OAuth2AuthorizationConsentService authorizationConsentService; |
237 | | - |
238 | 235 | @Autowired |
239 | 236 | private JwtDecoder jwtDecoder; |
240 | 237 |
|
@@ -692,38 +689,6 @@ public void requestWhenRequiresConsentThenDisplaysConsentPage() throws Exception |
692 | 689 | assertThat(consentPage).contains(scopeCheckbox("message.write")); |
693 | 690 | } |
694 | 691 |
|
695 | | - @Test |
696 | | - public void requestWhenRequiresConsentThenDisplaysConsentPageWithOnlyNewScope() throws Exception { |
697 | | - this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
698 | | - |
699 | | - RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> { |
700 | | - scopes.clear(); |
701 | | - scopes.add("message.read"); |
702 | | - scopes.add("message.write"); |
703 | | - }).clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build()).build(); |
704 | | - this.registeredClientRepository.save(registeredClient); |
705 | | - |
706 | | - OAuth2AuthorizationConsent authorizationConsent = OAuth2AuthorizationConsent |
707 | | - .withId(registeredClient.getId(), "user") |
708 | | - .scope("message.write") |
709 | | - .build(); |
710 | | - |
711 | | - this.authorizationConsentService.save(authorizationConsent); |
712 | | - |
713 | | - String consentPage = this.mvc |
714 | | - .perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
715 | | - .queryParams(getAuthorizationRequestParameters(registeredClient)) |
716 | | - .with(user("user"))) |
717 | | - .andExpect(status().is2xxSuccessful()) |
718 | | - .andReturn() |
719 | | - .getResponse() |
720 | | - .getContentAsString(); |
721 | | - |
722 | | - assertThat(consentPage).contains("Consent required"); |
723 | | - assertThat(consentPage).contains(scopeCheckbox("message.read")); |
724 | | - assertThat(consentPage).contains(disabledScopeCheckbox("message.write")); |
725 | | - } |
726 | | - |
727 | 692 | @Test |
728 | 693 | public void requestWhenConsentRequestThenReturnAccessTokenResponse() throws Exception { |
729 | 694 | this.spring.register(AuthorizationServerConfiguration.class).autowire(); |
@@ -781,47 +746,6 @@ public void requestWhenConsentRequestThenReturnAccessTokenResponse() throws Exce |
781 | 746 | .andReturn(); |
782 | 747 | } |
783 | 748 |
|
784 | | - @Test |
785 | | - public void requestWhenCustomConsentPageConfiguredThenRedirectWithAllScopes() throws Exception { |
786 | | - this.spring.register(AuthorizationServerConfigurationCustomConsentPage.class).autowire(); |
787 | | - |
788 | | - RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> { |
789 | | - scopes.clear(); |
790 | | - scopes.add("message.read"); |
791 | | - scopes.add("message.write"); |
792 | | - }).clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build()).build(); |
793 | | - this.registeredClientRepository.save(registeredClient); |
794 | | - |
795 | | - OAuth2AuthorizationConsent authorizationConsent = OAuth2AuthorizationConsent |
796 | | - .withId(registeredClient.getId(), "user") |
797 | | - .scope("message.write") |
798 | | - .build(); |
799 | | - |
800 | | - this.authorizationConsentService.save(authorizationConsent); |
801 | | - |
802 | | - MvcResult mvcResult = this.mvc |
803 | | - .perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
804 | | - .queryParams(getAuthorizationRequestParameters(registeredClient)) |
805 | | - .with(user("user"))) |
806 | | - .andExpect(status().is3xxRedirection()) |
807 | | - .andReturn(); |
808 | | - String redirectedUrl = mvcResult.getResponse().getRedirectedUrl(); |
809 | | - assertThat(redirectedUrl).matches("http://localhost/oauth2/consent\\?scope=.+&client_id=.+&state=.+"); |
810 | | - |
811 | | - String locationHeader = URLDecoder.decode(redirectedUrl, StandardCharsets.UTF_8); |
812 | | - UriComponents uriComponents = UriComponentsBuilder.fromUriString(locationHeader).build(); |
813 | | - MultiValueMap<String, String> redirectQueryParams = uriComponents.getQueryParams(); |
814 | | - |
815 | | - assertThat(uriComponents.getPath()).isEqualTo(consentPage); |
816 | | - assertThat(redirectQueryParams.getFirst(OAuth2ParameterNames.SCOPE)).isEqualTo("message.read message.write"); |
817 | | - assertThat(redirectQueryParams.getFirst(OAuth2ParameterNames.CLIENT_ID)) |
818 | | - .isEqualTo(registeredClient.getClientId()); |
819 | | - |
820 | | - String state = extractParameterFromRedirectUri(redirectedUrl, "state"); |
821 | | - OAuth2Authorization authorization = this.authorizationService.findByToken(state, STATE_TOKEN_TYPE); |
822 | | - assertThat(authorization).isNotNull(); |
823 | | - } |
824 | | - |
825 | 749 | @Test |
826 | 750 | public void requestWhenCustomConsentPageConfiguredThenRedirect() throws Exception { |
827 | 751 | this.spring.register(AuthorizationServerConfigurationCustomConsentPage.class).autowire(); |
@@ -1152,6 +1076,7 @@ public void requestWhenPushedAuthorizationRequestThenReturnAccessTokenResponse() |
1152 | 1076 | .isEqualTo(true); |
1153 | 1077 | } |
1154 | 1078 |
|
| 1079 | + // gh-2182 |
1155 | 1080 | @Test |
1156 | 1081 | public void requestWhenPushedAuthorizationRequestAndRequiresConsentThenDisplaysConsentPage() throws Exception { |
1157 | 1082 | this.spring.register(AuthorizationServerConfigurationWithPushedAuthorizationRequests.class).autowire(); |
@@ -1192,54 +1117,7 @@ public void requestWhenPushedAuthorizationRequestAndRequiresConsentThenDisplaysC |
1192 | 1117 | assertThat(consentPage).contains(scopeCheckbox("message.write")); |
1193 | 1118 | } |
1194 | 1119 |
|
1195 | | - @Test |
1196 | | - public void requestWhenPushedAuthorizationRequestAndRequiresConsentThenDisplaysConsentPageWithOnlyNewScope() |
1197 | | - throws Exception { |
1198 | | - this.spring.register(AuthorizationServerConfigurationWithPushedAuthorizationRequests.class).autowire(); |
1199 | | - |
1200 | | - RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> { |
1201 | | - scopes.clear(); |
1202 | | - scopes.add("message.read"); |
1203 | | - scopes.add("message.write"); |
1204 | | - }).clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build()).build(); |
1205 | | - this.registeredClientRepository.save(registeredClient); |
1206 | | - |
1207 | | - OAuth2AuthorizationConsent authorizationConsent = OAuth2AuthorizationConsent |
1208 | | - .withId(registeredClient.getId(), "user") |
1209 | | - .scope("message.write") |
1210 | | - .build(); |
1211 | | - |
1212 | | - this.authorizationConsentService.save(authorizationConsent); |
1213 | | - |
1214 | | - MvcResult mvcResult = this.mvc |
1215 | | - .perform(post("/oauth2/par").params(getAuthorizationRequestParameters(registeredClient)) |
1216 | | - .param(PkceParameterNames.CODE_CHALLENGE, S256_CODE_CHALLENGE) |
1217 | | - .param(PkceParameterNames.CODE_CHALLENGE_METHOD, "S256") |
1218 | | - .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeader(registeredClient))) |
1219 | | - .andExpect(header().string(HttpHeaders.CACHE_CONTROL, containsString("no-store"))) |
1220 | | - .andExpect(header().string(HttpHeaders.PRAGMA, containsString("no-cache"))) |
1221 | | - .andExpect(status().isCreated()) |
1222 | | - .andExpect(jsonPath("$.request_uri").isNotEmpty()) |
1223 | | - .andExpect(jsonPath("$.expires_in").isNotEmpty()) |
1224 | | - .andReturn(); |
1225 | | - |
1226 | | - String requestUri = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.request_uri"); |
1227 | | - |
1228 | | - String consentPage = this.mvc |
1229 | | - .perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
1230 | | - .queryParam(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
1231 | | - .queryParam(OAuth2ParameterNames.REQUEST_URI, requestUri) |
1232 | | - .with(user("user"))) |
1233 | | - .andExpect(status().is2xxSuccessful()) |
1234 | | - .andReturn() |
1235 | | - .getResponse() |
1236 | | - .getContentAsString(); |
1237 | | - |
1238 | | - assertThat(consentPage).contains("Consent required"); |
1239 | | - assertThat(consentPage).contains(scopeCheckbox("message.read")); |
1240 | | - assertThat(consentPage).contains(disabledScopeCheckbox("message.write")); |
1241 | | - } |
1242 | | - |
| 1120 | + // gh-2182 |
1243 | 1121 | @Test |
1244 | 1122 | public void requestWhenPushedAuthorizationRequestAndCustomConsentPageConfiguredThenRedirect() throws Exception { |
1245 | 1123 | this.spring.register(AuthorizationServerConfigurationWithPushedAuthorizationRequestsAndCustomConsentPage.class) |
@@ -1290,64 +1168,6 @@ public void requestWhenPushedAuthorizationRequestAndCustomConsentPageConfiguredT |
1290 | 1168 | assertThat(authorization).isNotNull(); |
1291 | 1169 | } |
1292 | 1170 |
|
1293 | | - @Test |
1294 | | - public void requestWhenPushedAuthorizationRequestAndCustomConsentPageConfiguredThenRedirectWithAllScopes() |
1295 | | - throws Exception { |
1296 | | - this.spring.register(AuthorizationServerConfigurationWithPushedAuthorizationRequestsAndCustomConsentPage.class) |
1297 | | - .autowire(); |
1298 | | - |
1299 | | - RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> { |
1300 | | - scopes.clear(); |
1301 | | - scopes.add("message.read"); |
1302 | | - scopes.add("message.write"); |
1303 | | - }).clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build()).build(); |
1304 | | - this.registeredClientRepository.save(registeredClient); |
1305 | | - |
1306 | | - OAuth2AuthorizationConsent authorizationConsent = OAuth2AuthorizationConsent |
1307 | | - .withId(registeredClient.getId(), "user") |
1308 | | - .scope("message.write") |
1309 | | - .build(); |
1310 | | - |
1311 | | - this.authorizationConsentService.save(authorizationConsent); |
1312 | | - |
1313 | | - MvcResult mvcResult = this.mvc |
1314 | | - .perform(post("/oauth2/par").params(getAuthorizationRequestParameters(registeredClient)) |
1315 | | - .param(PkceParameterNames.CODE_CHALLENGE, S256_CODE_CHALLENGE) |
1316 | | - .param(PkceParameterNames.CODE_CHALLENGE_METHOD, "S256") |
1317 | | - .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeader(registeredClient))) |
1318 | | - .andExpect(header().string(HttpHeaders.CACHE_CONTROL, containsString("no-store"))) |
1319 | | - .andExpect(header().string(HttpHeaders.PRAGMA, containsString("no-cache"))) |
1320 | | - .andExpect(status().isCreated()) |
1321 | | - .andExpect(jsonPath("$.request_uri").isNotEmpty()) |
1322 | | - .andExpect(jsonPath("$.expires_in").isNotEmpty()) |
1323 | | - .andReturn(); |
1324 | | - |
1325 | | - String requestUri = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.request_uri"); |
1326 | | - |
1327 | | - mvcResult = this.mvc |
1328 | | - .perform(get(DEFAULT_AUTHORIZATION_ENDPOINT_URI) |
1329 | | - .queryParam(OAuth2ParameterNames.CLIENT_ID, registeredClient.getClientId()) |
1330 | | - .queryParam(OAuth2ParameterNames.REQUEST_URI, requestUri) |
1331 | | - .with(user("user"))) |
1332 | | - .andExpect(status().is3xxRedirection()) |
1333 | | - .andReturn(); |
1334 | | - String redirectedUrl = mvcResult.getResponse().getRedirectedUrl(); |
1335 | | - assertThat(redirectedUrl).matches("http://localhost/oauth2/consent\\?scope=.+&client_id=.+&state=.+"); |
1336 | | - |
1337 | | - String locationHeader = URLDecoder.decode(redirectedUrl, StandardCharsets.UTF_8); |
1338 | | - UriComponents uriComponents = UriComponentsBuilder.fromUriString(locationHeader).build(); |
1339 | | - MultiValueMap<String, String> redirectQueryParams = uriComponents.getQueryParams(); |
1340 | | - |
1341 | | - assertThat(uriComponents.getPath()).isEqualTo(consentPage); |
1342 | | - assertThat(redirectQueryParams.getFirst(OAuth2ParameterNames.SCOPE)).isEqualTo("message.read message.write"); |
1343 | | - assertThat(redirectQueryParams.getFirst(OAuth2ParameterNames.CLIENT_ID)) |
1344 | | - .isEqualTo(registeredClient.getClientId()); |
1345 | | - |
1346 | | - String state = extractParameterFromRedirectUri(redirectedUrl, "state"); |
1347 | | - OAuth2Authorization authorization = this.authorizationService.findByToken(state, STATE_TOKEN_TYPE); |
1348 | | - assertThat(authorization).isNotNull(); |
1349 | | - } |
1350 | | - |
1351 | 1171 | private static String generateDPoPProof(String tokenEndpointUri) { |
1352 | 1172 | // @formatter:off |
1353 | 1173 | Map<String, Object> publicJwk = TestJwks.DEFAULT_EC_JWK |
@@ -1404,12 +1224,6 @@ private static String scopeCheckbox(String scope) { |
1404 | 1224 | "<input class=\"form-check-input\" type=\"checkbox\" name=\"scope\" value=\"{0}\" id=\"{0}\">", scope); |
1405 | 1225 | } |
1406 | 1226 |
|
1407 | | - private static String disabledScopeCheckbox(String scope) { |
1408 | | - return MessageFormat.format( |
1409 | | - "<input class=\"form-check-input\" type=\"checkbox\" name=\"scope\" id=\"{0}\" checked disabled>", |
1410 | | - scope); |
1411 | | - } |
1412 | | - |
1413 | 1227 | private String extractParameterFromRedirectUri(String redirectUri, String param) |
1414 | 1228 | throws UnsupportedEncodingException { |
1415 | 1229 | String locationHeader = URLDecoder.decode(redirectUri, StandardCharsets.UTF_8.name()); |
|
0 commit comments