Skip to content

Commit c53a092

Browse files
committed
Ensure serializable classes do not share serialVersionUID
Closes gh-2100
1 parent a1588de commit c53a092

File tree

32 files changed

+129
-121
lines changed

32 files changed

+129
-121
lines changed

docs/src/main/java/sample/jpa/entity/authorizationconsent/AuthorizationConsent.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package sample.jpa.entity.authorizationconsent;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920
import java.util.Objects;
2021

@@ -62,6 +63,10 @@ public void setAuthorities(String authorities) {
6263
// @fold:off
6364

6465
public static class AuthorizationConsentId implements Serializable {
66+
67+
@Serial
68+
private static final long serialVersionUID = -8507564681220621744L;
69+
6570
private String registeredClientId;
6671
private String principalName;
6772

etc/checkstyle/checkstyle-suppressions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
55
<suppressions>
66
<suppress files=".*" checks="JavadocStyle" />
7-
<suppress files="SpringAuthorizationServerVersion\.java" checks="HideUtilityClassConstructor"/>
87
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toLowerCaseWithoutLocale"/>
98
<suppress files="[\\/]src[\\/]test[\\/]" checks="RegexpSinglelineJava" id="toUpperCaseWithoutLocale"/>
109
<suppress files="AbstractOAuth2AuthorizationCodeRequestAuthenticationToken\.java" checks="SpringMethodVisibility"/>

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/AbstractOAuth2AuthorizationServerMetadata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920
import java.net.URI;
2021
import java.net.URL;
@@ -26,7 +27,6 @@
2627
import java.util.function.Consumer;
2728

2829
import org.springframework.security.oauth2.jose.jws.JwsAlgorithms;
29-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
3030
import org.springframework.util.Assert;
3131

3232
/**
@@ -59,7 +59,8 @@
5959
public abstract class AbstractOAuth2AuthorizationServerMetadata
6060
implements OAuth2AuthorizationServerMetadataClaimAccessor, Serializable {
6161

62-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
62+
@Serial
63+
private static final long serialVersionUID = -8817963285912690443L;
6364

6465
private final Map<String, Object> claims;
6566

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2Authorization.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920
import java.time.Instant;
2021
import java.util.Collections;
@@ -32,7 +33,6 @@
3233
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
3334
import org.springframework.security.oauth2.core.OAuth2Token;
3435
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
35-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
3636
import org.springframework.util.Assert;
3737
import org.springframework.util.CollectionUtils;
3838
import org.springframework.util.StringUtils;
@@ -54,7 +54,8 @@
5454
*/
5555
public class OAuth2Authorization implements Serializable {
5656

57-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
57+
@Serial
58+
private static final long serialVersionUID = 880363144799377926L;
5859

5960
private String id;
6061

@@ -246,7 +247,8 @@ public static Builder from(OAuth2Authorization authorization) {
246247
*/
247248
public static class Token<T extends OAuth2Token> implements Serializable {
248249

249-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
250+
@Serial
251+
private static final long serialVersionUID = -5931125502413497522L;
250252

251253
protected static final String TOKEN_METADATA_NAMESPACE = "metadata.token.";
252254

@@ -377,9 +379,7 @@ public int hashCode() {
377379
/**
378380
* A builder for {@link OAuth2Authorization}.
379381
*/
380-
public static class Builder implements Serializable {
381-
382-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
382+
public static class Builder {
383383

384384
private String id;
385385

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2AuthorizationConsent.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920
import java.util.Collections;
2021
import java.util.HashSet;
@@ -26,7 +27,6 @@
2627
import org.springframework.security.core.GrantedAuthority;
2728
import org.springframework.security.core.authority.SimpleGrantedAuthority;
2829
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
29-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
3030
import org.springframework.util.Assert;
3131
import org.springframework.util.CollectionUtils;
3232

@@ -46,7 +46,8 @@
4646
*/
4747
public final class OAuth2AuthorizationConsent implements Serializable {
4848

49-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
49+
@Serial
50+
private static final long serialVersionUID = -1950648027021276018L;
5051

5152
private static final String AUTHORITIES_SCOPE_PREFIX = "SCOPE_";
5253

@@ -153,9 +154,7 @@ public static Builder withId(@NonNull String registeredClientId, @NonNull String
153154
/**
154155
* A builder for {@link OAuth2AuthorizationConsent}.
155156
*/
156-
public static final class Builder implements Serializable {
157-
158-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
157+
public static final class Builder {
159158

160159
private final String registeredClientId;
161160

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2AuthorizationServerMetadata.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serial;
1819
import java.util.Map;
1920

2021
import org.springframework.util.Assert;
@@ -33,6 +34,9 @@
3334
*/
3435
public final class OAuth2AuthorizationServerMetadata extends AbstractOAuth2AuthorizationServerMetadata {
3536

37+
@Serial
38+
private static final long serialVersionUID = 3993358339217009284L;
39+
3640
private OAuth2AuthorizationServerMetadata(Map<String, Object> claims) {
3741
super(claims);
3842
}

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2TokenIntrospection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.oauth2.server.authorization;
1818

19+
import java.io.Serial;
1920
import java.io.Serializable;
2021
import java.net.URI;
2122
import java.net.URL;
@@ -29,7 +30,6 @@
2930

3031
import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimAccessor;
3132
import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames;
32-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
3333
import org.springframework.util.Assert;
3434

3535
/**
@@ -44,7 +44,8 @@
4444
*/
4545
public final class OAuth2TokenIntrospection implements OAuth2TokenIntrospectionClaimAccessor, Serializable {
4646

47-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
47+
@Serial
48+
private static final long serialVersionUID = -8846164058150912395L;
4849

4950
private final Map<String, Object> claims;
5051

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/OAuth2TokenType.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization;
1717

18+
import java.io.Serial;
1819
import java.io.Serializable;
1920

20-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
2121
import org.springframework.util.Assert;
2222

2323
/**
@@ -30,7 +30,8 @@
3030
*/
3131
public final class OAuth2TokenType implements Serializable {
3232

33-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
33+
@Serial
34+
private static final long serialVersionUID = -9015673781220922768L;
3435

3536
/**
3637
* {@code access_token} token type.

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/AbstractOAuth2AuthorizationCodeRequestAuthenticationToken.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization.authentication;
1717

18+
import java.io.Serial;
1819
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.HashSet;
@@ -24,7 +25,6 @@
2425
import org.springframework.lang.Nullable;
2526
import org.springframework.security.authentication.AbstractAuthenticationToken;
2627
import org.springframework.security.core.Authentication;
27-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
2828
import org.springframework.util.Assert;
2929

3030
/**
@@ -38,7 +38,8 @@
3838
*/
3939
abstract class AbstractOAuth2AuthorizationCodeRequestAuthenticationToken extends AbstractAuthenticationToken {
4040

41-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
41+
@Serial
42+
private static final long serialVersionUID = -5813797478091794517L;
4243

4344
private final String authorizationUri;
4445

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AccessTokenAuthenticationToken.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.security.oauth2.server.authorization.authentication;
1717

18+
import java.io.Serial;
1819
import java.util.Collections;
1920
import java.util.Map;
2021

@@ -24,7 +25,6 @@
2425
import org.springframework.security.oauth2.core.OAuth2AccessToken;
2526
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
2627
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
27-
import org.springframework.security.oauth2.server.authorization.util.SpringAuthorizationServerVersion;
2828
import org.springframework.util.Assert;
2929

3030
/**
@@ -42,7 +42,8 @@
4242
*/
4343
public class OAuth2AccessTokenAuthenticationToken extends AbstractAuthenticationToken {
4444

45-
private static final long serialVersionUID = SpringAuthorizationServerVersion.SERIAL_VERSION_UID;
45+
@Serial
46+
private static final long serialVersionUID = 2773767853287774441L;
4647

4748
private final RegisteredClient registeredClient;
4849

0 commit comments

Comments
 (0)