Skip to content

Commit 998acb4

Browse files
committed
1 parent 304b0e1 commit 998acb4

File tree

11 files changed

+100
-78
lines changed

11 files changed

+100
-78
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
5555
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
5656
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
57-
import org.springframework.security.oauth2.server.authorization.jackson2.OAuth2ServerJackson2Module;
57+
import org.springframework.security.oauth2.server.authorization.jackson2.OAuth2AuthorizationServerJackson2Module;
5858
import org.springframework.util.Assert;
5959
import org.springframework.util.CollectionUtils;
6060
import org.springframework.util.StringUtils;
@@ -317,7 +317,7 @@ public OAuth2AuthorizationRowMapper(RegisteredClientRepository registeredClientR
317317
ClassLoader classLoader = JdbcOAuth2AuthorizationService.class.getClassLoader();
318318
List<Module> securityModules = SecurityJackson2Modules.getModules(classLoader);
319319
this.objectMapper.registerModules(securityModules);
320-
this.objectMapper.registerModule(new OAuth2ServerJackson2Module());
320+
this.objectMapper.registerModule(new OAuth2AuthorizationServerJackson2Module());
321321
}
322322

323323
@Override
@@ -455,7 +455,7 @@ public OAuth2AuthorizationParametersMapper() {
455455
ClassLoader classLoader = JdbcOAuth2AuthorizationService.class.getClassLoader();
456456
List<Module> securityModules = SecurityJackson2Modules.getModules(classLoader);
457457
this.objectMapper.registerModules(securityModules);
458-
this.objectMapper.registerModule(new OAuth2ServerJackson2Module());
458+
this.objectMapper.registerModule(new OAuth2AuthorizationServerJackson2Module());
459459
}
460460

461461
@Override

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2020-2021 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.
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.security.oauth2.server.authorization.jackson2;
1817

1918
import java.util.HashSet;
@@ -26,9 +25,8 @@
2625
* This mixin class is used to serialize/deserialize {@link HashSet}.
2726
*
2827
* @author Steve Riesenberg
29-
* @see HashSet
30-
* @see OAuth2ServerJackson2Module
3128
* @since 0.1.2
29+
* @see HashSet
3230
*/
3331
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
3432
abstract class HashSetMixin {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525

2626
/**
27+
* TODO
28+
* This class is a straight copy from Spring Security.
29+
* It should be consolidated when merging this codebase into Spring Security.
30+
*
2731
* Utility class for {@code JsonNode}.
2832
*
2933
* @author Joe Grandja
30-
* @since 0.1.2
34+
* @since 5.3
3135
*/
3236
abstract class JsonNodeUtils {
3337

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@
3131
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder;
3232

3333
/**
34+
* TODO
35+
* This class is a straight copy from Spring Security.
36+
* It should be consolidated when merging this codebase into Spring Security.
37+
*
3438
* A {@code JsonDeserializer} for {@link OAuth2AuthorizationRequest}.
3539
*
3640
* @author Joe Grandja
37-
* @since 0.1.2
41+
* @since 5.3
3842
* @see OAuth2AuthorizationRequest
3943
* @see OAuth2AuthorizationRequestMixin
4044
*/

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
2525

2626
/**
27+
* TODO
28+
* This class is a straight copy from Spring Security.
29+
* It should be consolidated when merging this codebase into Spring Security.
30+
*
2731
* This mixin class is used to serialize/deserialize {@link OAuth2AuthorizationRequest}.
2832
* It also registers a custom deserializer {@link OAuth2AuthorizationRequestDeserializer}.
2933
*
3034
* @author Joe Grandja
31-
* @since 0.1.2
35+
* @since 5.3
3236
* @see OAuth2AuthorizationRequest
3337
* @see OAuth2AuthorizationRequestDeserializer
34-
* @see OAuth2ServerJackson2Module
3538
*/
3639
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
3740
@JsonDeserialize(using = OAuth2AuthorizationRequestDeserializer.class)
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2020-2021 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.
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.security.oauth2.server.authorization.jackson2;
1817

1918
import java.util.Collections;
@@ -24,7 +23,6 @@
2423

2524
import org.springframework.security.jackson2.SecurityJackson2Modules;
2625
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
27-
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2ClientAuthenticationToken;
2826

2927
/**
3028
* Jackson {@code Module} for {@code spring-authorization-server}, that registers the
@@ -34,7 +32,6 @@
3432
* <li>{@link UnmodifiableMapMixin}</li>
3533
* <li>{@link HashSetMixin}</li>
3634
* <li>{@link OAuth2AuthorizationRequestMixin}</li>
37-
* <li>{@link OAuth2ClientAuthenticationTokenMixin}</li>
3835
* </ul>
3936
*
4037
* If not already enabled, default typing will be automatically enabled as type info is
@@ -43,21 +40,23 @@
4340
*
4441
* <pre>
4542
* ObjectMapper mapper = new ObjectMapper();
46-
* mapper.registerModule(new OAuth2ServerJackson2Module());
43+
* mapper.registerModule(new OAuth2AuthorizationServerJackson2Module());
4744
* </pre>
4845
*
46+
* <b>NOTE:</b> Use {@link SecurityJackson2Modules#getModules(ClassLoader)} to get a list
47+
* of all security modules.
48+
*
4949
* @author Steve Riesenberg
5050
* @since 0.1.2
5151
* @see SecurityJackson2Modules
5252
* @see UnmodifiableMapMixin
5353
* @see HashSetMixin
5454
* @see OAuth2AuthorizationRequestMixin
55-
* @see OAuth2ClientAuthenticationTokenMixin
5655
*/
57-
public class OAuth2ServerJackson2Module extends SimpleModule {
56+
public class OAuth2AuthorizationServerJackson2Module extends SimpleModule {
5857

59-
public OAuth2ServerJackson2Module() {
60-
super(OAuth2ServerJackson2Module.class.getName(), new Version(1, 0, 0, null, null, null));
58+
public OAuth2AuthorizationServerJackson2Module() {
59+
super(OAuth2AuthorizationServerJackson2Module.class.getName(), new Version(1, 0, 0, null, null, null));
6160
}
6261

6362
@Override
@@ -67,7 +66,6 @@ public void setupModule(SetupContext context) {
6766
UnmodifiableMapMixin.class);
6867
context.setMixInAnnotations(HashSet.class, HashSetMixin.class);
6968
context.setMixInAnnotations(OAuth2AuthorizationRequest.class, OAuth2AuthorizationRequestMixin.class);
70-
context.setMixInAnnotations(OAuth2ClientAuthenticationToken.class, OAuth2ClientAuthenticationTokenMixin.class);
7169
}
7270

7371
}

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,57 @@
1919
import com.fasterxml.jackson.databind.JsonNode;
2020
import com.fasterxml.jackson.databind.util.StdConverter;
2121

22+
import org.springframework.security.oauth2.core.AuthenticationMethod;
2223
import org.springframework.security.oauth2.core.AuthorizationGrantType;
24+
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
25+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
2326

2427
/**
28+
* TODO
29+
* This class is a straight copy from Spring Security.
30+
* It should be consolidated when merging this codebase into Spring Security.
31+
*
2532
* {@code StdConverter} implementations.
2633
*
2734
* @author Joe Grandja
28-
* @since 0.1.2
35+
* @since 5.3
2936
*/
3037
abstract class StdConverters {
3138

39+
static final class AccessTokenTypeConverter extends StdConverter<JsonNode, OAuth2AccessToken.TokenType> {
40+
41+
@Override
42+
public OAuth2AccessToken.TokenType convert(JsonNode jsonNode) {
43+
String value = JsonNodeUtils.findStringValue(jsonNode, "value");
44+
if (OAuth2AccessToken.TokenType.BEARER.getValue().equalsIgnoreCase(value)) {
45+
return OAuth2AccessToken.TokenType.BEARER;
46+
}
47+
return null;
48+
}
49+
50+
}
51+
52+
static final class ClientAuthenticationMethodConverter extends StdConverter<JsonNode, ClientAuthenticationMethod> {
53+
54+
@Override
55+
public ClientAuthenticationMethod convert(JsonNode jsonNode) {
56+
String value = JsonNodeUtils.findStringValue(jsonNode, "value");
57+
if (ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue().equalsIgnoreCase(value)
58+
|| ClientAuthenticationMethod.BASIC.getValue().equalsIgnoreCase(value)) {
59+
return ClientAuthenticationMethod.CLIENT_SECRET_BASIC;
60+
}
61+
if (ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue().equalsIgnoreCase(value)
62+
|| ClientAuthenticationMethod.POST.getValue().equalsIgnoreCase(value)) {
63+
return ClientAuthenticationMethod.CLIENT_SECRET_POST;
64+
}
65+
if (ClientAuthenticationMethod.NONE.getValue().equalsIgnoreCase(value)) {
66+
return ClientAuthenticationMethod.NONE;
67+
}
68+
return null;
69+
}
70+
71+
}
72+
3273
static final class AuthorizationGrantTypeConverter extends StdConverter<JsonNode, AuthorizationGrantType> {
3374

3475
@Override
@@ -51,4 +92,23 @@ public AuthorizationGrantType convert(JsonNode jsonNode) {
5192

5293
}
5394

95+
static final class AuthenticationMethodConverter extends StdConverter<JsonNode, AuthenticationMethod> {
96+
97+
@Override
98+
public AuthenticationMethod convert(JsonNode jsonNode) {
99+
String value = JsonNodeUtils.findStringValue(jsonNode, "value");
100+
if (AuthenticationMethod.HEADER.getValue().equalsIgnoreCase(value)) {
101+
return AuthenticationMethod.HEADER;
102+
}
103+
if (AuthenticationMethod.FORM.getValue().equalsIgnoreCase(value)) {
104+
return AuthenticationMethod.FORM;
105+
}
106+
if (AuthenticationMethod.QUERY.getValue().equalsIgnoreCase(value)) {
107+
return AuthenticationMethod.QUERY;
108+
}
109+
return null;
110+
}
111+
112+
}
113+
54114
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
import com.fasterxml.jackson.databind.ObjectMapper;
2929

3030
/**
31+
* TODO
32+
* This class is a straight copy from Spring Security.
33+
* It should be consolidated when merging this codebase into Spring Security.
34+
*
3135
* A {@code JsonDeserializer} for {@link Collections#unmodifiableMap(Map)}.
3236
*
3337
* @author Joe Grandja
34-
* @since 0.1.2
38+
* @since 5.3
3539
* @see Collections#unmodifiableMap(Map)
3640
* @see UnmodifiableMapMixin
3741
*/

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2525

2626
/**
27+
* TODO
28+
* This class is a straight copy from Spring Security.
29+
* It should be consolidated when merging this codebase into Spring Security.
30+
*
2731
* This mixin class is used to serialize/deserialize
2832
* {@link Collections#unmodifiableMap(Map)}. It also registers a custom deserializer
2933
* {@link UnmodifiableMapDeserializer}.
3034
*
3135
* @author Joe Grandja
32-
* @since 0.1.2
36+
* @since 5.3
3337
* @see Collections#unmodifiableMap(Map)
3438
* @see UnmodifiableMapDeserializer
35-
* @see OAuth2ServerJackson2Module
3639
*/
3740
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
3841
@JsonDeserialize(using = UnmodifiableMapDeserializer.class)

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/TestingAuthenticationTokenMixin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2020-2021 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.
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.security.oauth2.server.authorization.jackson2;
1817

1918
import java.util.List;

0 commit comments

Comments
 (0)