Skip to content

OAuth2: ServletOAuth2AuthorizedClientExchangeFilterFunction fails to remove client webclient receives authentication failure responses #17379

Open
@jjstreet

Description

@jjstreet

Describe the bug

In some configuration setups, adding a ServletOAuth2AuthorizedClientExchangeFilterFunction to a WebClient that can retry causes an IllegalArgumentException when trying to remove the client in the case where the WebClient receives a response actionable by the authorization failure forwarder. The ClientRequest is not always populated with a HttpServletRequest attribute when the filter is added via the WebClientBuilder.filter() method instead of using the the filter's filter.oauth2Configuration() method.

The filter.filter() method does merge the required objects into the ClientRequest when making an authorized client, but then does not use that merged request when executing the handler within the filter. Without the merged attributes, its impossible for the AuthorizationFailureForwarder to clean up the client in case there is a 401/403 response from the original ClientRequest.

To Reproduce

  • Create a blank MVC-based project
  • Create a WebClient
  • Attach ServletOAuth2AuthorizedClientExchangeFilterFunction to it via builder.filter()
  • Make sure the WebClient is set to retry on WebClientResponseExceptions for 401 or 403 responses.
  • Make sure the ServletOAuth2AuthorizedClientExchangeFilterFunction is able to retrieve a token successfully
  • Make sure the WebClient is able to call an endpoint that will fail with 401 or 403 even if the token is valid to simulate the situation.
  • WebClient should emit an IllegalArgumentException with "request must not be null" as a message.

Expected behavior

It is expected that the authorizedClient is removed via the AuthorizationFailureForwarder in the case a webclient with a ServletOAuth2AuthorizedClientExchangeFilterFunction.

Sample

No sample available yet. Working to extract a minimal setup from my own programs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions