Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.springframework.security.oauth2.client;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
Expand Down Expand Up @@ -47,8 +48,7 @@ public final class AuthorizationCodeOAuth2AuthorizedClientProvider implements OA
* the authorization request
*/
@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(
context.getClientRegistration().getAuthorizationGrantType()) && context.getAuthorizedClient() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.Map;
import java.util.function.Function;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import java.time.Duration;
import java.time.Instant;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest;
import org.springframework.security.oauth2.client.endpoint.RestClientClientCredentialsTokenResponseClient;
Expand Down Expand Up @@ -61,8 +62,7 @@ public final class ClientCredentialsOAuth2AuthorizedClientProvider implements OA
* re-authorization) is not supported
*/
@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
ClientRegistration clientRegistration = context.getClientRegistration();
if (!AuthorizationGrantType.CLIENT_CREDENTIALS.equals(clientRegistration.getAuthorizationGrantType())) {
Expand Down Expand Up @@ -98,7 +98,12 @@ private OAuth2AccessTokenResponse getTokenResponse(ClientRegistration clientRegi
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
// Capture the expiration time in a local variable to ensure:
// 1. Thread safety: The value cannot change between the null check and its use.
// 2. Static analysis: Prevents IDEs (like VS Code/Eclipse) from reporting a
// potential NullPointerException on the second call.
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizationContext context
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
// Capture the expiration time in a local variable to ensure:
// 1. Thread safety: The value cannot change between the null check and its use.
// 2. Static analysis: Prevents IDEs (like VS Code/Eclipse) from reporting a
// potential NullPointerException on the second call.
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.Collections;
import java.util.List;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -64,8 +65,7 @@ public DelegatingOAuth2AuthorizedClientProvider(List<OAuth2AuthorizedClientProvi
}

@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
for (OAuth2AuthorizedClientProvider authorizedClientProvider : this.authorizedClientProviders) {
OAuth2AuthorizedClient oauth2AuthorizedClient = authorizedClientProvider.authorize(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.time.Instant;
import java.util.function.Function;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.endpoint.JwtBearerGrantRequest;
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.RestClientJwtBearerTokenResponseClient;
Expand Down Expand Up @@ -65,8 +66,7 @@ public final class JwtBearerOAuth2AuthorizedClientProvider implements OAuth2Auth
* supported
*/
@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
ClientRegistration clientRegistration = context.getClientRegistration();
if (!AuthorizationGrantType.JWT_BEARER.equals(clientRegistration.getAuthorizationGrantType())) {
Expand Down Expand Up @@ -118,7 +118,12 @@ private OAuth2AccessTokenResponse getTokenResponse(ClientRegistration clientRegi
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
// Capture the expiration time in a local variable to ensure:
// 1. Thread safety: The value cannot change between the null check and its use.
// 2. Static analysis: Prevents IDEs (like VS Code/Eclipse) from reporting a
// potential NullPointerException on the second call.
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ private Mono<Jwt> resolveJwtAssertion(OAuth2AuthorizationContext context) {
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
// Capture the expiration time in a local variable to ensure:
// 1. Thread safety: The value cannot change between the null check and its use.
// 2. Static analysis: Prevents IDEs (like VS Code/Eclipse) from reporting a
// potential NullPointerException on the second call.
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.Map;
import java.util.function.Consumer;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -74,8 +75,7 @@ public ClientRegistration getClientRegistration() {
* @return the {@link OAuth2AuthorizedClient} or {@code null} if the client
* registration was supplied
*/
@Nullable
public OAuth2AuthorizedClient getAuthorizedClient() {
@Nullable public OAuth2AuthorizedClient getAuthorizedClient() {
return this.authorizedClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import java.util.Map;
import java.util.function.Consumer;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
Expand Down Expand Up @@ -67,8 +68,7 @@ public String getClientRegistrationId() {
* was not provided.
* @return the {@link OAuth2AuthorizedClient} or {@code null} if it was not provided
*/
@Nullable
public OAuth2AuthorizedClient getAuthorizedClient() {
@Nullable public OAuth2AuthorizedClient getAuthorizedClient() {
return this.authorizedClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import java.io.Serializable;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.springframework.security.oauth2.client;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;

Expand Down Expand Up @@ -62,7 +63,6 @@ public interface OAuth2AuthorizedClientManager {
* @return the {@link OAuth2AuthorizedClient} or {@code null} if authorization is not
* supported for the specified client
*/
@Nullable
OAuth2AuthorizedClient authorize(OAuth2AuthorizeRequest authorizeRequest);
@Nullable OAuth2AuthorizedClient authorize(OAuth2AuthorizeRequest authorizeRequest);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.springframework.security.oauth2.client;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.core.AuthorizationGrantType;

Expand Down Expand Up @@ -46,7 +47,6 @@ public interface OAuth2AuthorizedClientProvider {
* @return the {@link OAuth2AuthorizedClient} or {@code null} if authorization is not
* supported for the specified client
*/
@Nullable
OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context);
@Nullable OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import java.util.HashSet;
import java.util.Set;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.lang.Nullable;
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2RefreshTokenGrantRequest;
import org.springframework.security.oauth2.client.endpoint.RestClientRefreshTokenTokenResponseClient;
Expand Down Expand Up @@ -78,8 +79,7 @@ public final class RefreshTokenOAuth2AuthorizedClientProvider
* not supported
*/
@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
OAuth2AuthorizedClient authorizedClient = context.getAuthorizedClient();
if (authorizedClient == null || authorizedClient.getRefreshToken() == null
Expand Down Expand Up @@ -123,7 +123,8 @@ private OAuth2AccessTokenResponse getTokenResponse(OAuth2AuthorizedClient author
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizationContext context
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.time.Instant;
import java.util.function.Function;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.RestClientTokenExchangeTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.TokenExchangeGrantRequest;
Expand Down Expand Up @@ -66,8 +67,7 @@ public final class TokenExchangeOAuth2AuthorizedClientProvider implements OAuth2
* supported
*/
@Override
@Nullable
public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
@Nullable public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
Assert.notNull(context, "context cannot be null");
ClientRegistration clientRegistration = context.getClientRegistration();
if (!AuthorizationGrantType.TOKEN_EXCHANGE.equals(clientRegistration.getAuthorizationGrantType())) {
Expand Down Expand Up @@ -111,7 +111,8 @@ private OAuth2AccessTokenResponse getTokenResponse(ClientRegistration clientRegi
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private Mono<OAuth2Token> resolveSubjectToken(OAuth2AuthorizationContext context
}

private boolean hasTokenExpired(OAuth2Token token) {
return this.clock.instant().isAfter(token.getExpiresAt().minus(this.clockSkew));
Instant expiresAt = token.getExpiresAt();
return expiresAt != null && this.clock.instant().isAfter(expiresAt.minus(this.clockSkew));
}

/**
Expand Down

This file was deleted.

Loading
Loading