|
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.
|
@@ -609,17 +609,49 @@ public void doFilterWhenAuthorizationRequestAuthenticatedThenAuthorizationRespon
|
609 | 609 | .isEqualTo("https://example.com?param=encoded%20parameter%20value&code=code&state=client%20state");
|
610 | 610 | }
|
611 | 611 |
|
| 612 | + @Test |
| 613 | + public void doFilterWhenPostAuthorizationRequestAuthenticatedThenAuthorizationResponse() throws Exception { |
| 614 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient().redirectUris((redirectUris) -> { |
| 615 | + redirectUris.clear(); |
| 616 | + redirectUris.add("https://example.com?param=encoded%20parameter%20value"); |
| 617 | + }).build(); |
| 618 | + OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthenticationResult = new OAuth2AuthorizationCodeRequestAuthenticationToken( |
| 619 | + AUTHORIZATION_URI, registeredClient.getClientId(), this.principal, this.authorizationCode, |
| 620 | + registeredClient.getRedirectUris().iterator().next(), "client state", registeredClient.getScopes()); |
| 621 | + authorizationCodeRequestAuthenticationResult.setAuthenticated(true); |
| 622 | + given(this.authenticationManager.authenticate(any())).willReturn(authorizationCodeRequestAuthenticationResult); |
| 623 | + |
| 624 | + MockHttpServletRequest request = createAuthorizationRequest(registeredClient); |
| 625 | + request.setMethod("POST"); |
| 626 | + request.setQueryString(null); |
| 627 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 628 | + FilterChain filterChain = mock(FilterChain.class); |
| 629 | + |
| 630 | + this.filter.doFilter(request, response, filterChain); |
| 631 | + |
| 632 | + verify(this.authenticationManager).authenticate(any()); |
| 633 | + verifyNoInteractions(filterChain); |
| 634 | + |
| 635 | + assertThat(response.getStatus()).isEqualTo(HttpStatus.FOUND.value()); |
| 636 | + assertThat(response.getRedirectedUrl()) |
| 637 | + .isEqualTo("https://example.com?param=encoded%20parameter%20value&code=code&state=client%20state"); |
| 638 | + } |
| 639 | + |
612 | 640 | @Test
|
613 | 641 | public void doFilterWhenAuthenticationRequestAuthenticatedThenAuthorizationResponse() throws Exception {
|
614 |
| - RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes(Set::clear).build(); |
| 642 | + // Setup OpenID Connect request |
| 643 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient().scopes((scopes) -> { |
| 644 | + scopes.clear(); |
| 645 | + scopes.add(OidcScopes.OPENID); |
| 646 | + }).build(); |
615 | 647 | OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthenticationResult = new OAuth2AuthorizationCodeRequestAuthenticationToken(
|
616 | 648 | AUTHORIZATION_URI, registeredClient.getClientId(), this.principal, this.authorizationCode,
|
617 | 649 | registeredClient.getRedirectUris().iterator().next(), STATE, registeredClient.getScopes());
|
618 | 650 | authorizationCodeRequestAuthenticationResult.setAuthenticated(true);
|
619 | 651 | given(this.authenticationManager.authenticate(any())).willReturn(authorizationCodeRequestAuthenticationResult);
|
620 | 652 |
|
621 | 653 | MockHttpServletRequest request = createAuthorizationRequest(registeredClient);
|
622 |
| - request.setMethod("POST"); |
| 654 | + request.setMethod("POST"); // OpenID Connect supports POST method |
623 | 655 | request.setQueryString(null);
|
624 | 656 | MockHttpServletResponse response = new MockHttpServletResponse();
|
625 | 657 | FilterChain filterChain = mock(FilterChain.class);
|
|
0 commit comments