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.access;
import java.io.Serial;
/**
* Thrown if an {@link org.springframework.security.core.Authentication Authentication}
* object does not hold a required authority.
@@ -24,6 +26,9 @@ package org.springframework.security.access;
*/
public class AccessDeniedException extends RuntimeException {
@Serial
private static final long serialVersionUID = 6395817500121599533L;
/**
* Constructs an <code>AccessDeniedException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.access;
import java.io.Serial;
/**
* Thrown if an authorization request could not be processed due to a system problem.
* <p>
@@ -26,6 +28,9 @@ package org.springframework.security.access;
*/
public class AuthorizationServiceException extends AccessDeniedException {
@Serial
private static final long serialVersionUID = 4817857292041606900L;
/**
* Constructs an <code>AuthorizationServiceException</code> with the specified
* message.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
/**
* Thrown if an authentication request is rejected because the account has expired. Makes
* no assertion as to whether or not the credentials were valid.
@@ -24,6 +26,9 @@ package org.springframework.security.authentication;
*/
public class AccountExpiredException extends AccountStatusException {
@Serial
private static final long serialVersionUID = 3732869526329993353L;
/**
* Constructs a <code>AccountExpiredException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
@@ -28,6 +30,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class AuthenticationCredentialsNotFoundException extends AuthenticationException {
@Serial
private static final long serialVersionUID = 4153580041526791384L;
/**
* Constructs an <code>AuthenticationCredentialsNotFoundException</code> with the
* specified message.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -29,6 +31,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class AuthenticationServiceException extends AuthenticationException {
@Serial
private static final long serialVersionUID = -1591626195291329340L;
/**
* Constructs an <code>AuthenticationServiceException</code> with the specified
* message.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -26,6 +28,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class BadCredentialsException extends AuthenticationException {
@Serial
private static final long serialVersionUID = 2742216069043066973L;
/**
* Constructs a <code>BadCredentialsException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
/**
* Thrown if an authentication request is rejected because the account's credentials have
* expired. Makes no assertion as to whether or not the credentials were valid.
@@ -24,6 +26,9 @@ package org.springframework.security.authentication;
*/
public class CredentialsExpiredException extends AccountStatusException {
@Serial
private static final long serialVersionUID = -3306615738048904753L;
/**
* Constructs a <code>CredentialsExpiredException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
/**
* Thrown if an authentication request is rejected because the account is disabled. Makes
* no assertion as to whether or not the credentials were valid.
@@ -24,6 +26,9 @@ package org.springframework.security.authentication;
*/
public class DisabledException extends AccountStatusException {
@Serial
private static final long serialVersionUID = 2295984593872502361L;
/**
* Constructs a <code>DisabledException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -33,6 +35,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class InsufficientAuthenticationException extends AuthenticationException {
@Serial
private static final long serialVersionUID = -5514084346181236128L;
/**
* Constructs an <code>InsufficientAuthenticationException</code> with the specified
* message.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
/**
* <p>
* Thrown if an authentication request could not be processed due to a system problem that
@@ -37,6 +39,9 @@ package org.springframework.security.authentication;
*/
public class InternalAuthenticationServiceException extends AuthenticationServiceException {
@Serial
private static final long serialVersionUID = -6029644854192497840L;
public InternalAuthenticationServiceException(String message, Throwable cause) {
super(message, cause);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
/**
* Thrown if an authentication request is rejected because the account is locked. Makes no
* assertion as to whether or not the credentials were valid.
@@ -24,6 +26,9 @@ package org.springframework.security.authentication;
*/
public class LockedException extends AccountStatusException {
@Serial
private static final long serialVersionUID = 548864198455046567L;
/**
* Constructs a <code>LockedException</code> with the specified message.
* @param msg the detail message.

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -27,6 +29,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class ProviderNotFoundException extends AuthenticationException {
@Serial
private static final long serialVersionUID = 8107665253214447614L;
/**
* Constructs a <code>ProviderNotFoundException</code> with the specified message.
* @param msg the detail message

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication.ott;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -26,6 +28,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class InvalidOneTimeTokenException extends AuthenticationException {
@Serial
private static final long serialVersionUID = -3651018515682919943L;
public InvalidOneTimeTokenException(String msg) {
super(msg);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authentication.password;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -26,6 +28,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class CompromisedPasswordException extends AuthenticationException {
@Serial
private static final long serialVersionUID = -885858958297842864L;
public CompromisedPasswordException(String message) {
super(message);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.security.authorization;
import java.io.Serial;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.util.Assert;
@@ -27,6 +29,9 @@ import org.springframework.util.Assert;
*/
public class AuthorizationDeniedException extends AccessDeniedException implements AuthorizationResult {
@Serial
private static final long serialVersionUID = 3227305845919610459L;
private final AuthorizationResult result;
public AuthorizationDeniedException(String msg, AuthorizationResult authorizationResult) {

View File

@@ -16,6 +16,8 @@
package org.springframework.security.core.userdetails;
import java.io.Serial;
import org.springframework.security.core.AuthenticationException;
/**
@@ -26,6 +28,9 @@ import org.springframework.security.core.AuthenticationException;
*/
public class UsernameNotFoundException extends AuthenticationException {
@Serial
private static final long serialVersionUID = 1410688585992297006L;
/**
* Constructs a <code>UsernameNotFoundException</code> with the specified message.
* @param msg the detail message.