@@ -214,6 +214,71 @@ public void deserializeWhenRequiredAttributesOnlyThenDeserializes() throws Excep
214214 assertThat (authorizedClient .getRefreshToken ()).isNull ();
215215 }
216216
217+ @ Test
218+ void deserializeWhenClientSettingsPropertyDoesNotExistThenDefaulted () throws JsonProcessingException {
219+ // ClientRegistration.clientSettings was added later, so old values will be
220+ // serialized without that property
221+ // this test checks for passivity
222+ ClientRegistration clientRegistration = this .clientRegistrationBuilder .build ();
223+ ClientRegistration .ProviderDetails providerDetails = clientRegistration .getProviderDetails ();
224+ ClientRegistration .ProviderDetails .UserInfoEndpoint userInfoEndpoint = providerDetails .getUserInfoEndpoint ();
225+ String scopes = "" ;
226+ if (!CollectionUtils .isEmpty (clientRegistration .getScopes ())) {
227+ scopes = StringUtils .collectionToDelimitedString (clientRegistration .getScopes (), "," , "\" " , "\" " );
228+ }
229+ String configurationMetadata = "\" @class\" : \" java.util.Collections$UnmodifiableMap\" " ;
230+ if (!CollectionUtils .isEmpty (providerDetails .getConfigurationMetadata ())) {
231+ configurationMetadata += "," + providerDetails .getConfigurationMetadata ()
232+ .keySet ()
233+ .stream ()
234+ .map ((key ) -> "\" " + key + "\" : \" " + providerDetails .getConfigurationMetadata ().get (key ) + "\" " )
235+ .collect (Collectors .joining ("," ));
236+ }
237+ // @formatter:off
238+ String json = "{\n " +
239+ " \" @class\" : \" org.springframework.security.oauth2.client.registration.ClientRegistration\" ,\n " +
240+ " \" registrationId\" : \" " + clientRegistration .getRegistrationId () + "\" ,\n " +
241+ " \" clientId\" : \" " + clientRegistration .getClientId () + "\" ,\n " +
242+ " \" clientSecret\" : \" " + clientRegistration .getClientSecret () + "\" ,\n " +
243+ " \" clientAuthenticationMethod\" : {\n " +
244+ " \" value\" : \" " + clientRegistration .getClientAuthenticationMethod ().getValue () + "\" \n " +
245+ " },\n " +
246+ " \" authorizationGrantType\" : {\n " +
247+ " \" value\" : \" " + clientRegistration .getAuthorizationGrantType ().getValue () + "\" \n " +
248+ " },\n " +
249+ " \" redirectUri\" : \" " + clientRegistration .getRedirectUri () + "\" ,\n " +
250+ " \" scopes\" : [\n " +
251+ " \" java.util.Collections$UnmodifiableSet\" ,\n " +
252+ " [" + scopes + "]\n " +
253+ " ],\n " +
254+ " \" providerDetails\" : {\n " +
255+ " \" @class\" : \" org.springframework.security.oauth2.client.registration.ClientRegistration$ProviderDetails\" ,\n " +
256+ " \" authorizationUri\" : \" " + providerDetails .getAuthorizationUri () + "\" ,\n " +
257+ " \" tokenUri\" : \" " + providerDetails .getTokenUri () + "\" ,\n " +
258+ " \" userInfoEndpoint\" : {\n " +
259+ " \" @class\" : \" org.springframework.security.oauth2.client.registration.ClientRegistration$ProviderDetails$UserInfoEndpoint\" ,\n " +
260+ " \" uri\" : " + ((userInfoEndpoint .getUri () != null ) ? "\" " + userInfoEndpoint .getUri () + "\" " : null ) + ",\n " +
261+ " \" authenticationMethod\" : {\n " +
262+ " \" value\" : \" " + userInfoEndpoint .getAuthenticationMethod ().getValue () + "\" \n " +
263+ " },\n " +
264+ " \" userNameAttributeName\" : " + ((userInfoEndpoint .getUserNameAttributeName () != null ) ? "\" " + userInfoEndpoint .getUserNameAttributeName () + "\" " : null ) + "\n " +
265+ " },\n " +
266+ " \" jwkSetUri\" : " + ((providerDetails .getJwkSetUri () != null ) ? "\" " + providerDetails .getJwkSetUri () + "\" " : null ) + ",\n " +
267+ " \" issuerUri\" : " + ((providerDetails .getIssuerUri () != null ) ? "\" " + providerDetails .getIssuerUri () + "\" " : null ) + ",\n " +
268+ " \" configurationMetadata\" : {\n " +
269+ " " + configurationMetadata + "\n " +
270+ " }\n " +
271+ " },\n " +
272+ " \" clientName\" : \" " + clientRegistration .getClientName () + "\" \n " +
273+ "}" ;
274+ // @formatter:on
275+ // validate the test input
276+ assertThat (json ).doesNotContain ("clientSettings" );
277+ ClientRegistration registration = this .mapper .readValue (json , ClientRegistration .class );
278+ // the default value of requireProofKey is false
279+ assertThat (registration .getClientSettings ().isRequireProofKey ()).isFalse ();
280+ }
281+
217282 private static String asJson (OAuth2AuthorizedClient authorizedClient ) {
218283 // @formatter:off
219284 return "{\n " +
0 commit comments