Support Serialization in Exceptions

Issue gh-16276
This commit is contained in:
Josh Cummings
2025-01-14 18:25:17 -07:00
parent 8e59fa1719
commit 244fd2eb51
66 changed files with 249 additions and 2 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.client;
import java.io.Serial;
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.util.Assert;
@@ -30,6 +32,9 @@ import org.springframework.util.Assert;
*/
public class ClientAuthorizationException extends OAuth2AuthorizationException {
@Serial
private static final long serialVersionUID = 4710713969265443271L;
private final String clientRegistrationId;
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.client;
import java.io.Serial;
import org.springframework.security.oauth2.core.OAuth2Error;
/**
@@ -28,6 +30,9 @@ import org.springframework.security.oauth2.core.OAuth2Error;
*/
public class ClientAuthorizationRequiredException extends ClientAuthorizationException {
@Serial
private static final long serialVersionUID = -5738646355203953667L;
private static final String CLIENT_AUTHORIZATION_REQUIRED_ERROR_CODE = "client_authorization_required";
/**

View File

@@ -20,6 +20,7 @@ package org.springframework.security.oauth2.client.web;
* @author Steve Riesenberg
* @since 5.8
*/
@SuppressWarnings("serial")
class InvalidClientRegistrationIdException extends IllegalArgumentException {
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.core;
import java.io.Serial;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.util.Assert;
@@ -41,6 +43,9 @@ import org.springframework.util.Assert;
*/
public class OAuth2AuthenticationException extends AuthenticationException {
@Serial
private static final long serialVersionUID = -7832130893085581438L;
private final OAuth2Error error;
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.core;
import java.io.Serial;
import org.springframework.util.Assert;
/**
@@ -26,6 +28,9 @@ import org.springframework.util.Assert;
*/
public class OAuth2AuthorizationException extends RuntimeException {
@Serial
private static final long serialVersionUID = -5470222190376181102L;
private final OAuth2Error error;
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.jwt;
import java.io.Serial;
/**
* An exception similar to
* {@link org.springframework.security.authentication.BadCredentialsException} that
@@ -26,6 +28,9 @@ package org.springframework.security.oauth2.jwt;
*/
public class BadJwtException extends JwtException {
@Serial
private static final long serialVersionUID = 7748429527132280501L;
public BadJwtException(String message) {
super(message);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.jwt;
import java.io.Serial;
/**
* An exception thrown when a {@link JwtDecoder} or {@link ReactiveJwtDecoder}'s lazy
* initialization fails.
@@ -25,6 +27,9 @@ package org.springframework.security.oauth2.jwt;
*/
public class JwtDecoderInitializationException extends RuntimeException {
@Serial
private static final long serialVersionUID = 2786360018315628982L;
public JwtDecoderInitializationException(String message, Throwable cause) {
super(message, cause);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.jwt;
import java.io.Serial;
/**
* This exception is thrown when an error occurs while attempting to encode a JSON Web
* Token (JWT).
@@ -25,6 +27,9 @@ package org.springframework.security.oauth2.jwt;
*/
public class JwtEncodingException extends JwtException {
@Serial
private static final long serialVersionUID = 6581840872589902213L;
/**
* Constructs a {@code JwtEncodingException} using the provided parameters.
* @param message the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.jwt;
import java.io.Serial;
/**
* Base exception for all JSON Web Token (JWT) related errors.
*
@@ -24,6 +26,9 @@ package org.springframework.security.oauth2.jwt;
*/
public class JwtException extends RuntimeException {
@Serial
private static final long serialVersionUID = -3070197880233583797L;
/**
* Constructs a {@code JwtException} using the provided parameters.
* @param message the detail message

View File

@@ -16,6 +16,7 @@
package org.springframework.security.oauth2.jwt;
import java.io.Serial;
import java.util.ArrayList;
import java.util.Collection;
@@ -31,6 +32,9 @@ import org.springframework.util.Assert;
*/
public class JwtValidationException extends BadJwtException {
@Serial
private static final long serialVersionUID = 134652048447295615L;
private final Collection<OAuth2Error> errors;
/**

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.server.resource;
import java.io.Serial;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
/**
@@ -26,6 +28,9 @@ import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
*/
public class InvalidBearerTokenException extends OAuth2AuthenticationException {
@Serial
private static final long serialVersionUID = 6904689954809100280L;
/**
* Construct an instance of {@link InvalidBearerTokenException} given the provided
* description.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.server.resource.introspection;
import java.io.Serial;
/**
* An exception similar to
* {@link org.springframework.security.authentication.BadCredentialsException} that
@@ -26,6 +28,9 @@ package org.springframework.security.oauth2.server.resource.introspection;
*/
public class BadOpaqueTokenException extends OAuth2IntrospectionException {
@Serial
private static final long serialVersionUID = -6937847463454551076L;
public BadOpaqueTokenException(String message) {
super(message);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.oauth2.server.resource.introspection;
import java.io.Serial;
/**
* Base exception for all OAuth 2.0 Introspection related errors
*
@@ -24,6 +26,9 @@ package org.springframework.security.oauth2.server.resource.introspection;
*/
public class OAuth2IntrospectionException extends RuntimeException {
@Serial
private static final long serialVersionUID = -7327790383594166793L;
public OAuth2IntrospectionException(String message) {
super(message);
}