|
16 | 16 |
|
17 | 17 | package org.springframework.security; |
18 | 18 |
|
19 | | -import java.io.ByteArrayInputStream; |
20 | | -import java.io.ByteArrayOutputStream; |
21 | 19 | import java.io.File; |
22 | 20 | import java.io.FileInputStream; |
23 | 21 | import java.io.FileOutputStream; |
|
38 | 36 | import java.util.Collection; |
39 | 37 | import java.util.Date; |
40 | 38 | import java.util.HashMap; |
41 | | -import java.util.HashSet; |
42 | 39 | import java.util.List; |
43 | 40 | import java.util.Locale; |
44 | 41 | import java.util.Map; |
|
48 | 45 | import java.util.stream.Stream; |
49 | 46 |
|
50 | 47 | import jakarta.servlet.http.Cookie; |
51 | | -import org.apache.commons.lang3.ObjectUtils; |
52 | 48 | import org.apereo.cas.client.validation.AssertionImpl; |
53 | 49 | import org.instancio.Instancio; |
54 | 50 | import org.instancio.InstancioApi; |
|
139 | 135 | import org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken; |
140 | 136 | import org.springframework.security.oauth2.client.authentication.TestOAuth2AuthenticationTokens; |
141 | 137 | import org.springframework.security.oauth2.client.authentication.TestOAuth2AuthorizationCodeAuthenticationTokens; |
142 | | -import org.springframework.security.oauth2.client.event.OAuth2AuthorizedClientRefreshedEvent; |
143 | | -import org.springframework.security.oauth2.client.oidc.authentication.event.OidcUserRefreshedEvent; |
144 | 138 | import org.springframework.security.oauth2.client.oidc.authentication.logout.OidcLogoutToken; |
145 | 139 | import org.springframework.security.oauth2.client.oidc.authentication.logout.TestOidcLogoutTokens; |
146 | 140 | import org.springframework.security.oauth2.client.oidc.session.OidcSessionInformation; |
147 | 141 | import org.springframework.security.oauth2.client.oidc.session.TestOidcSessionInformations; |
148 | 142 | import org.springframework.security.oauth2.client.registration.ClientRegistration; |
149 | | -import org.springframework.security.oauth2.client.registration.ClientRegistration.ClientSettings; |
150 | 143 | import org.springframework.security.oauth2.client.registration.TestClientRegistrations; |
151 | 144 | import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal; |
152 | 145 | import org.springframework.security.oauth2.core.OAuth2AccessToken; |
|
162 | 155 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationExchange; |
163 | 156 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; |
164 | 157 | import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse; |
165 | | -import org.springframework.security.oauth2.core.endpoint.TestOAuth2AccessTokenResponses; |
166 | 158 | import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationExchanges; |
167 | 159 | import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationRequests; |
168 | 160 | import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationResponses; |
|
187 | 179 | import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException; |
188 | 180 | import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication; |
189 | 181 | import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken; |
190 | | -import org.springframework.security.oauth2.server.resource.authentication.DPoPAuthenticationToken; |
191 | 182 | import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; |
192 | 183 | import org.springframework.security.oauth2.server.resource.introspection.BadOpaqueTokenException; |
193 | 184 | import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal; |
|
253 | 244 | import org.springframework.security.web.webauthn.api.TestBytes; |
254 | 245 | import org.springframework.security.web.webauthn.api.TestPublicKeyCredential; |
255 | 246 | import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialRequestOptions; |
256 | | -import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntities; |
257 | 247 | import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity; |
258 | | -import org.springframework.security.web.webauthn.api.TestPublicKeyCredentials; |
259 | 248 | import org.springframework.security.web.webauthn.api.UserVerificationRequirement; |
260 | 249 | import org.springframework.security.web.webauthn.authentication.WebAuthnAuthentication; |
261 | 250 | import org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationRequestToken; |
@@ -417,6 +406,9 @@ class SpringSecurityCoreVersionSerializableTests { |
417 | 406 | generatorByClassName.put(OAuth2IntrospectionException.class, |
418 | 407 | (r) -> new OAuth2IntrospectionException("message", new RuntimeException())); |
419 | 408 |
|
| 409 | + // config |
| 410 | + generatorByClassName.put(AlreadyBuiltException.class, (r) -> new AlreadyBuiltException("message")); |
| 411 | + |
420 | 412 | // core |
421 | 413 | generatorByClassName.put(RunAsUserToken.class, (r) -> { |
422 | 414 | RunAsUserToken token = new RunAsUserToken("key", user, "creds", user.getAuthorities(), |
@@ -508,6 +500,20 @@ class SpringSecurityCoreVersionSerializableTests { |
508 | 500 | generatorByClassName.put(AuthorizationDecision.class, (r) -> new AuthorizationDecision(true)); |
509 | 501 | generatorByClassName.put(AuthorityAuthorizationDecision.class, |
510 | 502 | (r) -> new AuthorityAuthorizationDecision(true, AuthorityUtils.createAuthorityList("ROLE_USER"))); |
| 503 | + generatorByClassName.put(CycleInRoleHierarchyException.class, (r) -> new CycleInRoleHierarchyException()); |
| 504 | + generatorByClassName.put(AuthorizationEvent.class, |
| 505 | + (r) -> new AuthorizationEvent(new SerializableSupplier<>(authentication), "source", |
| 506 | + new AuthorizationDecision(true))); |
| 507 | + generatorByClassName.put(AuthorizationGrantedEvent.class, |
| 508 | + (r) -> new AuthorizationGrantedEvent<>(new SerializableSupplier<>(authentication), "source", |
| 509 | + new AuthorizationDecision(true))); |
| 510 | + instancioByClassName.put(AuthorizationGrantedEvent.class, () -> { |
| 511 | + InstancioOfClassApi<?> instancio = Instancio.of(AuthorizationGrantedEvent.class); |
| 512 | + instancio.withTypeParameters(String.class); |
| 513 | + instancio.supply(Select.all(AuthorizationGrantedEvent.class), |
| 514 | + generatorByClassName.get(AuthorizationGrantedEvent.class)); |
| 515 | + return instancio; |
| 516 | + }); |
511 | 517 |
|
512 | 518 | // cas |
513 | 519 | generatorByClassName.put(CasServiceTicketAuthenticationToken.class, (r) -> { |
@@ -561,6 +567,7 @@ class SpringSecurityCoreVersionSerializableTests { |
561 | 567 | token.setDetails(details); |
562 | 568 | return token; |
563 | 569 | }); |
| 570 | + generatorByClassName.put(Saml2LogoutRequest.class, (r) -> TestSaml2LogoutRequests.create()); |
564 | 571 |
|
565 | 572 | // web |
566 | 573 | generatorByClassName.put(AnonymousAuthenticationToken.class, (r) -> { |
@@ -616,20 +623,8 @@ class SpringSecurityCoreVersionSerializableTests { |
616 | 623 | request.addPreferredLocale(Locale.ENGLISH); |
617 | 624 | return new SimpleSavedRequest(new DefaultSavedRequest(request, new PortResolverImpl(), "continue")); |
618 | 625 | }); |
619 | | - |
620 | | - // webauthn |
621 | | - generatorByClassName.put(Bytes.class, (r) -> TestBytes.get()); |
622 | | - generatorByClassName.put(ImmutablePublicKeyCredentialUserEntity.class, |
623 | | - (r) -> TestPublicKeyCredentialUserEntity.userEntity().id(TestBytes.get()).build()); |
624 | | - generatorByClassName.put(WebAuthnAuthentication.class, (r) -> { |
625 | | - PublicKeyCredentialUserEntity userEntity = TestPublicKeyCredentialUserEntity.userEntity() |
626 | | - .id(TestBytes.get()) |
627 | | - .build(); |
628 | | - List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER"); |
629 | | - WebAuthnAuthentication webAuthnAuthentication = new WebAuthnAuthentication(userEntity, authorities); |
630 | | - webAuthnAuthentication.setDetails(details); |
631 | | - return webAuthnAuthentication; |
632 | | - }); |
| 626 | + generatorByClassName.put(HttpSessionIdChangedEvent.class, |
| 627 | + (r) -> new HttpSessionIdChangedEvent(new MockHttpSession(), "1")); |
633 | 628 |
|
634 | 629 | // webauthn |
635 | 630 | CredProtectAuthenticationExtensionsClientInput.CredProtect credProtect = new CredProtectAuthenticationExtensionsClientInput.CredProtect( |
@@ -686,6 +681,25 @@ class SpringSecurityCoreVersionSerializableTests { |
686 | 681 | generatorByClassName.put(WebAuthnAuthenticationRequestToken.class, (r) -> requestToken); |
687 | 682 | generatorByClassName.put(AuthenticatorAttachment.class, (r) -> AuthenticatorAttachment.PLATFORM); |
688 | 683 | // @formatter:on |
| 684 | + generatorByClassName.put(ImmutablePublicKeyCredentialUserEntity.class, |
| 685 | + (r) -> TestPublicKeyCredentialUserEntity.userEntity().id(TestBytes.get()).build()); |
| 686 | + generatorByClassName.put(WebAuthnAuthentication.class, (r) -> { |
| 687 | + PublicKeyCredentialUserEntity userEntity = TestPublicKeyCredentialUserEntity.userEntity() |
| 688 | + .id(TestBytes.get()) |
| 689 | + .build(); |
| 690 | + List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER"); |
| 691 | + WebAuthnAuthentication webAuthnAuthentication = new WebAuthnAuthentication(userEntity, authorities); |
| 692 | + webAuthnAuthentication.setDetails(details); |
| 693 | + return webAuthnAuthentication; |
| 694 | + }); |
| 695 | + // @formatter:on |
| 696 | + generatorByClassName.put(CredentialPropertiesOutput.ExtensionOutput.class, |
| 697 | + (r) -> new CredentialPropertiesOutput(true).getOutput()); |
| 698 | + |
| 699 | + // One-Time Token |
| 700 | + DefaultOneTimeToken oneTimeToken = new DefaultOneTimeToken(UUID.randomUUID().toString(), "user", |
| 701 | + Instant.now().plusSeconds(300)); |
| 702 | + generatorByClassName.put(DefaultOneTimeToken.class, (t) -> oneTimeToken); |
689 | 703 | } |
690 | 704 |
|
691 | 705 | @ParameterizedTest |
@@ -862,4 +876,20 @@ private static String getPreviousVersion() { |
862 | 876 | return String.join(".", parts); |
863 | 877 | } |
864 | 878 |
|
| 879 | + @SuppressWarnings("serial") |
| 880 | + private static final class SerializableSupplier<T> implements Supplier<T>, Serializable { |
| 881 | + |
| 882 | + private final T value; |
| 883 | + |
| 884 | + SerializableSupplier(T value) { |
| 885 | + this.value = value; |
| 886 | + } |
| 887 | + |
| 888 | + @Override |
| 889 | + public T get() { |
| 890 | + return this.value; |
| 891 | + } |
| 892 | + |
| 893 | + } |
| 894 | + |
865 | 895 | } |
0 commit comments