Skip to content

Commit b9911fd

Browse files
committed
Add serialVersionUID to Authentication classes
Issue gh-16276
1 parent e3cd433 commit b9911fd

File tree

45 files changed

+199
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+199
-20
lines changed

Diff for: config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OidcBackChannelLogoutAuthentication.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.config.annotation.web.configurers.oauth2.client;
1818

19+
import java.io.Serial;
1920
import java.util.Collections;
2021

2122
import org.springframework.security.authentication.AbstractAuthenticationToken;
@@ -36,6 +37,9 @@
3637
*/
3738
class OidcBackChannelLogoutAuthentication extends AbstractAuthenticationToken {
3839

40+
@Serial
41+
private static final long serialVersionUID = 9095810699956350287L;
42+
3943
private final OidcLogoutToken logoutToken;
4044

4145
private final ClientRegistration clientRegistration;

Diff for: config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OidcLogoutAuthenticationToken.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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,8 @@
1616

1717
package org.springframework.security.config.annotation.web.configurers.oauth2.client;
1818

19+
import java.io.Serial;
20+
1921
import org.springframework.security.authentication.AbstractAuthenticationToken;
2022
import org.springframework.security.core.authority.AuthorityUtils;
2123
import org.springframework.security.oauth2.client.registration.ClientRegistration;
@@ -29,6 +31,9 @@
2931
*/
3032
class OidcLogoutAuthenticationToken extends AbstractAuthenticationToken {
3133

34+
@Serial
35+
private static final long serialVersionUID = -1568528983223505540L;
36+
3237
private final String logoutToken;
3338

3439
private final ClientRegistration clientRegistration;

Diff for: config/src/main/java/org/springframework/security/config/web/server/OidcBackChannelLogoutAuthentication.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.config.web.server;
1818

19+
import java.io.Serial;
1920
import java.util.Collections;
2021

2122
import org.springframework.security.authentication.AbstractAuthenticationToken;
@@ -36,6 +37,9 @@
3637
*/
3738
class OidcBackChannelLogoutAuthentication extends AbstractAuthenticationToken {
3839

40+
@Serial
41+
private static final long serialVersionUID = 9095810699956350287L;
42+
3943
private final OidcLogoutToken logoutToken;
4044

4145
private final ClientRegistration clientRegistration;

Diff for: config/src/main/java/org/springframework/security/config/web/server/OidcLogoutAuthenticationToken.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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,8 @@
1616

1717
package org.springframework.security.config.web.server;
1818

19+
import java.io.Serial;
20+
1921
import org.springframework.security.authentication.AbstractAuthenticationToken;
2022
import org.springframework.security.core.authority.AuthorityUtils;
2123
import org.springframework.security.oauth2.client.registration.ClientRegistration;
@@ -29,6 +31,9 @@
2931
*/
3032
class OidcLogoutAuthenticationToken extends AbstractAuthenticationToken {
3133

34+
@Serial
35+
private static final long serialVersionUID = -1568528983223505540L;
36+
3237
private final String logoutToken;
3338

3439
private final ClientRegistration clientRegistration;

Diff for: config/src/test/java/org/springframework/security/SpringSecurityCoreVersionSerializableTests.java

+82
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.file.Paths;
3333
import java.time.Instant;
3434
import java.util.ArrayList;
35+
import java.util.Collection;
3536
import java.util.Date;
3637
import java.util.HashMap;
3738
import java.util.List;
@@ -54,26 +55,42 @@
5455
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
5556
import org.springframework.core.type.filter.AssignableTypeFilter;
5657
import org.springframework.security.access.intercept.RunAsUserToken;
58+
import org.springframework.security.authentication.AbstractAuthenticationToken;
5759
import org.springframework.security.authentication.AnonymousAuthenticationToken;
5860
import org.springframework.security.authentication.RememberMeAuthenticationToken;
5961
import org.springframework.security.authentication.TestAuthentication;
62+
import org.springframework.security.authentication.TestingAuthenticationToken;
6063
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
6164
import org.springframework.security.authentication.jaas.JaasAuthenticationToken;
65+
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
6266
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken;
6367
import org.springframework.security.cas.authentication.CasAuthenticationToken;
6468
import org.springframework.security.cas.authentication.CasServiceTicketAuthenticationToken;
69+
import org.springframework.security.core.GrantedAuthority;
6570
import org.springframework.security.core.SpringSecurityCoreVersion;
71+
import org.springframework.security.core.authority.AuthorityUtils;
6672
import org.springframework.security.core.session.ReactiveSessionInformation;
6773
import org.springframework.security.core.session.SessionInformation;
6874
import org.springframework.security.core.userdetails.UserDetails;
75+
import org.springframework.security.ldap.userdetails.LdapAuthority;
6976
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
7077
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
7178
import org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken;
7279
import org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken;
7380
import org.springframework.security.oauth2.client.authentication.TestOAuth2AuthenticationTokens;
7481
import org.springframework.security.oauth2.client.authentication.TestOAuth2AuthorizationCodeAuthenticationTokens;
82+
import org.springframework.security.oauth2.client.oidc.authentication.logout.OidcLogoutToken;
83+
import org.springframework.security.oauth2.client.oidc.authentication.logout.TestOidcLogoutTokens;
84+
import org.springframework.security.oauth2.client.oidc.session.OidcSessionInformation;
85+
import org.springframework.security.oauth2.client.oidc.session.TestOidcSessionInformations;
7586
import org.springframework.security.oauth2.client.registration.ClientRegistration;
7687
import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
88+
import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
89+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
90+
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
91+
import org.springframework.security.oauth2.core.OAuth2DeviceCode;
92+
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
93+
import org.springframework.security.oauth2.core.OAuth2UserCode;
7794
import org.springframework.security.oauth2.core.TestOAuth2AccessTokens;
7895
import org.springframework.security.oauth2.core.TestOAuth2AuthenticatedPrincipals;
7996
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange;
@@ -82,16 +99,30 @@
8299
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationExchanges;
83100
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationRequests;
84101
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationResponses;
102+
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
85103
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
104+
import org.springframework.security.oauth2.core.oidc.TestOidcIdTokens;
105+
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
106+
import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
107+
import org.springframework.security.oauth2.core.oidc.user.TestOidcUsers;
86108
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
87109
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
88110
import org.springframework.security.oauth2.core.user.TestOAuth2Users;
111+
import org.springframework.security.oauth2.jwt.Jwt;
89112
import org.springframework.security.oauth2.jwt.TestJwts;
113+
import org.springframework.security.oauth2.server.resource.BearerTokenError;
114+
import org.springframework.security.oauth2.server.resource.BearerTokenErrors;
90115
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
91116
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken;
92117
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
118+
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal;
93119
import org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal;
120+
import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
121+
import org.springframework.security.saml2.provider.service.authentication.Saml2PostAuthenticationRequest;
122+
import org.springframework.security.saml2.provider.service.authentication.Saml2RedirectAuthenticationRequest;
94123
import org.springframework.security.saml2.provider.service.authentication.TestSaml2Authentications;
124+
import org.springframework.security.saml2.provider.service.authentication.TestSaml2PostAuthenticationRequests;
125+
import org.springframework.security.saml2.provider.service.authentication.TestSaml2RedirectAuthenticationRequests;
95126
import org.springframework.security.web.authentication.WebAuthenticationDetails;
96127
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
97128

@@ -138,6 +169,17 @@ class SpringSecurityCoreVersionSerializableTests {
138169
(r) -> new SessionInformation(user, r.alphanumeric(4), new Date(1704378933936L)));
139170
generatorByClassName.put(ReactiveSessionInformation.class,
140171
(r) -> new ReactiveSessionInformation(user, r.alphanumeric(4), Instant.ofEpochMilli(1704378933936L)));
172+
generatorByClassName.put(OAuth2AccessToken.class, (r) -> TestOAuth2AccessTokens.scopes("scope"));
173+
generatorByClassName.put(OAuth2DeviceCode.class,
174+
(r) -> new OAuth2DeviceCode("token", Instant.now(), Instant.now()));
175+
generatorByClassName.put(OAuth2RefreshToken.class,
176+
(r) -> new OAuth2RefreshToken("refreshToken", Instant.now(), Instant.now()));
177+
generatorByClassName.put(OAuth2UserCode.class,
178+
(r) -> new OAuth2UserCode("token", Instant.now(), Instant.now()));
179+
generatorByClassName.put(DefaultOidcUser.class, (r) -> TestOidcUsers.create());
180+
generatorByClassName.put(OidcUserAuthority.class,
181+
(r) -> new OidcUserAuthority(TestOidcIdTokens.idToken().build(),
182+
new OidcUserInfo(Map.of("claim", "value")), "claim"));
141183

142184
// oauth2-client
143185
ClientRegistration.Builder clientRegistrationBuilder = TestClientRegistrations.clientRegistration();
@@ -167,6 +209,18 @@ class SpringSecurityCoreVersionSerializableTests {
167209
token.setDetails(details);
168210
return token;
169211
});
212+
generatorByClassName.put(OidcIdToken.class, (r) -> TestOidcIdTokens.idToken().build());
213+
generatorByClassName.put(OidcLogoutToken.class,
214+
(r) -> TestOidcLogoutTokens.withSessionId("issuer", "sessionId").issuedAt(Instant.now()).build());
215+
generatorByClassName.put(OidcSessionInformation.class, (r) -> TestOidcSessionInformations.create());
216+
generatorByClassName.put(DefaultOAuth2AuthenticatedPrincipal.class, (r) -> {
217+
OAuth2AuthenticatedPrincipal principal = TestOAuth2AuthenticatedPrincipals.active();
218+
return new DefaultOAuth2AuthenticatedPrincipal(principal.getName(), principal.getAttributes(),
219+
(Collection<GrantedAuthority>) principal.getAuthorities());
220+
});
221+
222+
// oauth2-jwt
223+
generatorByClassName.put(Jwt.class, (r) -> TestJwts.user());
170224

171225
// oauth2-resource-server
172226
generatorByClassName
@@ -192,6 +246,9 @@ class SpringSecurityCoreVersionSerializableTests {
192246
token.setDetails(details);
193247
return token;
194248
});
249+
generatorByClassName.put(BearerTokenError.class, (r) -> BearerTokenErrors.invalidToken("invalid token"));
250+
generatorByClassName.put(OAuth2IntrospectionAuthenticatedPrincipal.class,
251+
(r) -> TestOAuth2AuthenticatedPrincipals.active());
195252

196253
// core
197254
generatorByClassName.put(RunAsUserToken.class, (r) -> {
@@ -215,6 +272,11 @@ class SpringSecurityCoreVersionSerializableTests {
215272
token.setDetails(details);
216273
return token;
217274
});
275+
generatorByClassName.put(OneTimeTokenAuthenticationToken.class,
276+
(r) -> applyDetails(new OneTimeTokenAuthenticationToken("username", "token")));
277+
278+
generatorByClassName.put(TestingAuthenticationToken.class,
279+
(r) -> applyDetails(new TestingAuthenticationToken("username", "password")));
218280

219281
// cas
220282
generatorByClassName.put(CasServiceTicketAuthenticationToken.class, (r) -> {
@@ -234,11 +296,25 @@ class SpringSecurityCoreVersionSerializableTests {
234296
return token;
235297
});
236298

299+
// ldap
300+
generatorByClassName.put(LdapAuthority.class,
301+
(r) -> new LdapAuthority("USER", "username", Map.of("attribute", List.of("value1", "value2"))));
302+
237303
// saml2-service-provider
238304
generatorByClassName.put(DefaultSaml2AuthenticatedPrincipal.class,
239305
(r) -> TestSaml2Authentications.authentication().getPrincipal());
306+
generatorByClassName.put(Saml2Authentication.class,
307+
(r) -> applyDetails(TestSaml2Authentications.authentication()));
308+
generatorByClassName.put(Saml2PostAuthenticationRequest.class,
309+
(r) -> TestSaml2PostAuthenticationRequests.create());
310+
generatorByClassName.put(Saml2RedirectAuthenticationRequest.class,
311+
(r) -> TestSaml2RedirectAuthenticationRequests.create());
240312

241313
// web
314+
generatorByClassName.put(AnonymousAuthenticationToken.class, (r) -> {
315+
Collection<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER");
316+
return applyDetails(new AnonymousAuthenticationToken("key", "username", authorities));
317+
});
242318
generatorByClassName.put(PreAuthenticatedAuthenticationToken.class, (r) -> {
243319
PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(user, "creds",
244320
user.getAuthorities());
@@ -361,6 +437,12 @@ private static InstancioApi<?> instancioWithDefaults(Class<?> clazz) {
361437
return instancio;
362438
}
363439

440+
private static <T extends AbstractAuthenticationToken> T applyDetails(T authentication) {
441+
WebAuthenticationDetails details = new WebAuthenticationDetails("remote", "sessionId");
442+
authentication.setDetails(details);
443+
return authentication;
444+
}
445+
364446
private static String getCurrentVersion() {
365447
String version = System.getProperty("springSecurityVersion");
366448
String[] parts = version.split("\\.");
Binary file not shown.

Diff for: core/src/main/java/org/springframework/security/authentication/ott/OneTimeTokenAuthenticationToken.java

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.authentication.ott;
1818

19+
import java.io.Serial;
1920
import java.util.Collection;
2021
import java.util.Collections;
2122

@@ -30,6 +31,9 @@
3031
*/
3132
public class OneTimeTokenAuthenticationToken extends AbstractAuthenticationToken {
3233

34+
@Serial
35+
private static final long serialVersionUID = -8691636031126328365L;
36+
3337
private final Object principal;
3438

3539
private String tokenValue;

Diff for: ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapAuthority.java

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.security.ldap.userdetails;
1818

19+
import java.io.Serial;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.Map;
@@ -31,6 +32,9 @@
3132
*/
3233
public class LdapAuthority implements GrantedAuthority {
3334

35+
@Serial
36+
private static final long serialVersionUID = 343193700821611354L;
37+
3438
private final String dn;
3539

3640
private final String role;

Diff for: oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/authentication/logout/OidcLogoutToken.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.client.oidc.authentication.logout;
1818

19+
import java.io.Serial;
1920
import java.time.Instant;
2021
import java.util.Collection;
2122
import java.util.Collections;
@@ -45,6 +46,9 @@
4546
*/
4647
public class OidcLogoutToken extends AbstractOAuth2Token implements LogoutTokenClaimAccessor {
4748

49+
@Serial
50+
private static final long serialVersionUID = -5705409698230609696L;
51+
4852
private static final String BACKCHANNEL_LOGOUT_TOKEN_EVENT_NAME = "http://schemas.openid.net/event/backchannel-logout";
4953

5054
private final Map<String, Object> claims;

Diff for: oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/session/OidcSessionInformation.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.client.oidc.session;
1818

19+
import java.io.Serial;
1920
import java.util.Collections;
2021
import java.util.Date;
2122
import java.util.LinkedHashMap;
@@ -33,6 +34,9 @@
3334
*/
3435
public class OidcSessionInformation extends SessionInformation {
3536

37+
@Serial
38+
private static final long serialVersionUID = -1703808683027974918L;
39+
3640
private final Map<String, String> authorities;
3741

3842
/**

Diff for: oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/DefaultOAuth2AuthenticatedPrincipal.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 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.core;
1818

19+
import java.io.Serial;
1920
import java.io.Serializable;
2021
import java.util.Collection;
2122
import java.util.Collections;
@@ -34,6 +35,9 @@
3435
*/
3536
public final class DefaultOAuth2AuthenticatedPrincipal implements OAuth2AuthenticatedPrincipal, Serializable {
3637

38+
@Serial
39+
private static final long serialVersionUID = 4631662622577433065L;
40+
3741
private final Map<String, Object> attributes;
3842

3943
private final Collection<GrantedAuthority> authorities;

0 commit comments

Comments
 (0)