Source:
<code>public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { RegisteredOAuth2AuthorizedClient authorizedClientAnnotation = AnnotatedElementUtils.findMergedAnnotation( parameter.getParameter(), RegisteredOAuth2AuthorizedClient.class); Authentication principal = SecurityContextHolder.getContext().getAuthentication(); String clientRegistrationId = null; if (!StringUtils.isEmpty(authorizedClientAnnotation.registrationId())) { clientRegistrationId = authorizedClientAnnotation.registrationId(); } else if (!StringUtils.isEmpty(authorizedClientAnnotation.value())) { clientRegistrationId = authorizedClientAnnotation.value(); } else if (principal != null && OAuth2AuthenticationToken.class.isAssignableFrom(principal.getClass())) { clientRegistrationId = ((OAuth2AuthenticationToken) principal).getAuthorizedClientRegistrationId(); } if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or @RegisteredOAuth2AuthorizedClient(registrationId = \"client1\")."); } <START> if (principal == null) { <END> throw new IllegalStateException("Unable to resolve the Authorized Client with registration identifier \"" + clientRegistrationId + "\". An \"authenticated\" or \"anonymous\" request is required. " + "To allow for anonymous access, ensure HttpSecurity.anonymous() is configured."); } OAuth2AuthorizedClient authorizedClient = this.authorizedClientRepository.loadAuthorizedClient( clientRegistrationId, principal, webRequest.getNativeRequest(HttpServletRequest.class)); if (authorizedClient == null) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } return authorizedClient; }</code><technical_language>If anonymous Authentication is disabled, this null throw Exception here</technical_language>

Target:
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { RegisteredOAuth2AuthorizedClient authorizedClientAnnotation = AnnotatedElementUtils.findMergedAnnotation( parameter.getParameter(), RegisteredOAuth2AuthorizedClient.class); Authentication principal = SecurityContextHolder.getContext().getAuthentication(); String clientRegistrationId = null; if (!StringUtils.isEmpty(authorizedClientAnnotation.registrationId())) { clientRegistrationId = authorizedClientAnnotation.registrationId(); } else if (!StringUtils.isEmpty(authorizedClientAnnotation.value())) { clientRegistrationId = authorizedClientAnnotation.value(); } else if (principal != null && OAuth2AuthenticationToken.class.isAssignableFrom(principal.getClass())) { clientRegistrationId = ((OAuth2AuthenticationToken) principal).getAuthorizedClientRegistrationId(); } if (StringUtils.isEmpty(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or @RegisteredOAuth2AuthorizedClient(registrationId = \"client1\")."); } OAuth2AuthorizedClient authorizedClient = this.authorizedClientRepository.loadAuthorizedClient( clientRegistrationId, principal, webRequest.getNativeRequest(HttpServletRequest.class)); if (authorizedClient == null) { throw new ClientAuthorizationRequiredException(clientRegistrationId); } return authorizedClient; }