Skip to content

Commit 8c0d2cc

Browse files
committed
Initialize RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler when jose is on classpath
Issue gh-17246
1 parent 612f788 commit 8c0d2cc

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/ReactiveOAuth2AuthorizedClientProviderBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public RefreshTokenGrantBuilder accessTokenResponseClient(
278278

279279
/**
280280
* Sets a {@link ReactiveOAuth2AuthorizationSuccessHandler} to use for handling
281-
* successful refresh token response, defaults to
281+
* successful refresh token response, see
282282
* {@link RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler}.
283283
* @param authorizationSuccessHandler the
284284
* {@link ReactiveOAuth2AuthorizationSuccessHandler} to use

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/RefreshTokenReactiveOAuth2AuthorizedClientProvider.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
3737
import org.springframework.security.oauth2.core.OAuth2Token;
3838
import org.springframework.util.Assert;
39+
import org.springframework.util.ClassUtils;
3940

4041
/**
4142
* An implementation of a {@link ReactiveOAuth2AuthorizedClientProvider} for the
@@ -50,14 +51,25 @@
5051
public final class RefreshTokenReactiveOAuth2AuthorizedClientProvider
5152
implements ReactiveOAuth2AuthorizedClientProvider {
5253

54+
private static final boolean josePresent = ClassUtils.isPresent(
55+
"org.springframework.security.oauth2.jwt.ReactiveJwtDecoder",
56+
RefreshTokenReactiveOAuth2AuthorizedClientProvider.class.getClassLoader());
57+
5358
private ReactiveOAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient = new WebClientReactiveRefreshTokenTokenResponseClient();
5459

55-
private ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler = new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler();
60+
private ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler = (authorizedClient, principal,
61+
attributes) -> Mono.empty();
5662

5763
private Duration clockSkew = Duration.ofSeconds(60);
5864

5965
private Clock clock = Clock.systemUTC();
6066

67+
public RefreshTokenReactiveOAuth2AuthorizedClientProvider() {
68+
if (josePresent) {
69+
this.authorizationSuccessHandler = new RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler();
70+
}
71+
}
72+
6173
/**
6274
* Attempt to re-authorize the
6375
* {@link OAuth2AuthorizationContext#getClientRegistration() client} in the provided
@@ -128,8 +140,9 @@ public void setAccessTokenResponseClient(
128140

129141
/**
130142
* Sets a {@link ReactiveOAuth2AuthorizationSuccessHandler} to use for handling
131-
* successful refresh token response, defaults to
132-
* {@link RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler}.
143+
* successful refresh token response. Defaults to
144+
* {@link RefreshOidcUserReactiveOAuth2AuthorizationSuccessHandler}, when
145+
* {@code spring-security-oauth2-jose} is available on the classpath.
133146
* @param authorizationSuccessHandler the
134147
* {@link ReactiveOAuth2AuthorizationSuccessHandler} to use
135148
* @since 7.1

0 commit comments

Comments
 (0)