|
@@ -20,7 +20,9 @@ import org.springframework.security.oauth2.client.endpoint.OAuth2RefreshTokenGra
|
|
import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient;
|
|
import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
+import java.time.Clock;
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
+import java.time.Instant;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -128,6 +130,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
public class RefreshTokenGrantBuilder implements Builder {
|
|
public class RefreshTokenGrantBuilder implements Builder {
|
|
private ReactiveOAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient;
|
|
private ReactiveOAuth2AccessTokenResponseClient<OAuth2RefreshTokenGrantRequest> accessTokenResponseClient;
|
|
private Duration clockSkew;
|
|
private Duration clockSkew;
|
|
|
|
+ private Clock clock;
|
|
|
|
|
|
private RefreshTokenGrantBuilder() {
|
|
private RefreshTokenGrantBuilder() {
|
|
}
|
|
}
|
|
@@ -145,7 +148,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets the maximum acceptable clock skew, which is used when checking the access token expiry.
|
|
* Sets the maximum acceptable clock skew, which is used when checking the access token expiry.
|
|
- * An access token is considered expired if it's before {@code Instant.now() - clockSkew}.
|
|
|
|
|
|
+ * An access token is considered expired if it's before {@code Instant.now(this.clock) - clockSkew}.
|
|
*
|
|
*
|
|
* @param clockSkew the maximum acceptable clock skew
|
|
* @param clockSkew the maximum acceptable clock skew
|
|
* @return the {@link RefreshTokenGrantBuilder}
|
|
* @return the {@link RefreshTokenGrantBuilder}
|
|
@@ -155,6 +158,17 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the {@link Clock} used in {@link Instant#now(Clock)} when checking the access token expiry.
|
|
|
|
+ *
|
|
|
|
+ * @param clock the clock
|
|
|
|
+ * @return the {@link RefreshTokenGrantBuilder}
|
|
|
|
+ */
|
|
|
|
+ public RefreshTokenGrantBuilder clock(Clock clock) {
|
|
|
|
+ this.clock = clock;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Builds an instance of {@link RefreshTokenReactiveOAuth2AuthorizedClientProvider}.
|
|
* Builds an instance of {@link RefreshTokenReactiveOAuth2AuthorizedClientProvider}.
|
|
*
|
|
*
|
|
@@ -169,6 +183,9 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
if (this.clockSkew != null) {
|
|
if (this.clockSkew != null) {
|
|
authorizedClientProvider.setClockSkew(this.clockSkew);
|
|
authorizedClientProvider.setClockSkew(this.clockSkew);
|
|
}
|
|
}
|
|
|
|
+ if (this.clock != null) {
|
|
|
|
+ authorizedClientProvider.setClock(this.clock);
|
|
|
|
+ }
|
|
return authorizedClientProvider;
|
|
return authorizedClientProvider;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -202,6 +219,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
public class ClientCredentialsGrantBuilder implements Builder {
|
|
public class ClientCredentialsGrantBuilder implements Builder {
|
|
private ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient;
|
|
private ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient;
|
|
private Duration clockSkew;
|
|
private Duration clockSkew;
|
|
|
|
+ private Clock clock;
|
|
|
|
|
|
private ClientCredentialsGrantBuilder() {
|
|
private ClientCredentialsGrantBuilder() {
|
|
}
|
|
}
|
|
@@ -219,7 +237,7 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets the maximum acceptable clock skew, which is used when checking the access token expiry.
|
|
* Sets the maximum acceptable clock skew, which is used when checking the access token expiry.
|
|
- * An access token is considered expired if it's before {@code Instant.now() - clockSkew}.
|
|
|
|
|
|
+ * An access token is considered expired if it's before {@code Instant.now(this.clock) - clockSkew}.
|
|
*
|
|
*
|
|
* @param clockSkew the maximum acceptable clock skew
|
|
* @param clockSkew the maximum acceptable clock skew
|
|
* @return the {@link ClientCredentialsGrantBuilder}
|
|
* @return the {@link ClientCredentialsGrantBuilder}
|
|
@@ -229,6 +247,17 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the {@link Clock} used in {@link Instant#now(Clock)} when checking the access token expiry.
|
|
|
|
+ *
|
|
|
|
+ * @param clock the clock
|
|
|
|
+ * @return the {@link ClientCredentialsGrantBuilder}
|
|
|
|
+ */
|
|
|
|
+ public ClientCredentialsGrantBuilder clock(Clock clock) {
|
|
|
|
+ this.clock = clock;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Builds an instance of {@link ClientCredentialsReactiveOAuth2AuthorizedClientProvider}.
|
|
* Builds an instance of {@link ClientCredentialsReactiveOAuth2AuthorizedClientProvider}.
|
|
*
|
|
*
|
|
@@ -243,6 +272,9 @@ public final class ReactiveOAuth2AuthorizedClientProviderBuilder {
|
|
if (this.clockSkew != null) {
|
|
if (this.clockSkew != null) {
|
|
authorizedClientProvider.setClockSkew(this.clockSkew);
|
|
authorizedClientProvider.setClockSkew(this.clockSkew);
|
|
}
|
|
}
|
|
|
|
+ if (this.clock != null) {
|
|
|
|
+ authorizedClientProvider.setClock(this.clock);
|
|
|
|
+ }
|
|
return authorizedClientProvider;
|
|
return authorizedClientProvider;
|
|
}
|
|
}
|
|
}
|
|
}
|