79545683

Date: 2025-03-31 07:23:36
Score: 1.5
Natty:
Report link

I have been facing a similar Problem and found this issue report that describes why this is happening: https://github.com/spring-projects/spring-security/issues/14991

Basically you have to set a anonymous authentication every time you do a web-client call:

Authentication anonymousAuthentication = new AnonymousAuthenticationToken(
        "anonymous", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
String body = webClient
        .get()
        .uri(resourceUri)
        .attributes(authentication(anonymousAuthentication))
        .retrieve()
        .bodyToMono(String.class)
        .block();

...

return "index";

This will result in the ServletOAuth2AuthorizedClientExchangeFilterFunction using the same token every time.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): facing a similar Problem
Posted by: woezelmann