Skip to content

Commit e0ef1d6

Browse files
committed
Remove compiler warnings in spring-security-oauth2-authorization-server - Remove ACCESS_DECLARED_FIELDS from AOT/runtime hints - Add @SuppressWarnings("removal") for Jackson2 deprecated adapters Closes gh-18432 Signed-off-by: gimgisu <gisu1102@gmail.com>
1 parent 42e1e9f commit e0ef1d6

6 files changed

Lines changed: 29 additions & 22 deletions

File tree

oauth2/oauth2-authorization-server/spring-security-oauth2-authorization-server.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
plugins {
2+
id 'compile-warnings-error'
3+
}
4+
15
apply plugin: 'io.spring.convention.spring-module'
26

37
dependencies {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ Map<String, Object> readValue(String data) {
505505
* 3.
506506
*/
507507
@Deprecated(forRemoval = true, since = "7.0")
508+
@SuppressWarnings("removal")
508509
public static class OAuth2AuthorizationRowMapper extends AbstractOAuth2AuthorizationRowMapper {
509510

510511
private ObjectMapper objectMapper = Jackson2.createObjectMapper();
@@ -747,6 +748,7 @@ String writeValueAsString(Map<String, Object> data) throws Exception {
747748
* Jackson 3.
748749
*/
749750
@Deprecated(forRemoval = true, since = "7.0")
751+
@SuppressWarnings("removal")
750752
public static class OAuth2AuthorizationParametersMapper extends AbstractOAuth2AuthorizationParametersMapper {
751753

752754
private ObjectMapper objectMapper = Jackson2.createObjectMapper();
@@ -895,6 +897,7 @@ private String writeMap(Map<String, Object> data) {
895897
@Deprecated(forRemoval = true, since = "7.0")
896898
private static final class Jackson2 {
897899

900+
@SuppressWarnings("removal")
898901
private static ObjectMapper createObjectMapper() {
899902
ObjectMapper objectMapper = new ObjectMapper();
900903
ClassLoader classLoader = Jackson2.class.getClassLoader();

oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/aot/hint/OAuth2AuthorizationServerBeanRegistrationAotProcessor.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.security.core.authority.SimpleGrantedAuthority;
3535
import org.springframework.security.core.userdetails.User;
3636
import org.springframework.security.jackson.CoreJacksonModule;
37-
import org.springframework.security.jackson2.CoreJackson2Module;
3837
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
3938
import org.springframework.security.oauth2.core.AuthorizationGrantType;
4039
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
@@ -50,11 +49,9 @@
5049
import org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenExchangeCompositeAuthenticationToken;
5150
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
5251
import org.springframework.security.oauth2.server.authorization.jackson.OAuth2AuthorizationServerJacksonModule;
53-
import org.springframework.security.oauth2.server.authorization.jackson2.OAuth2AuthorizationServerJackson2Module;
5452
import org.springframework.security.oauth2.server.authorization.settings.OAuth2TokenFormat;
5553
import org.springframework.security.web.authentication.WebAuthenticationDetails;
5654
import org.springframework.security.web.jackson.WebServletJacksonModule;
57-
import org.springframework.security.web.jackson2.WebServletJackson2Module;
5855
import org.springframework.security.web.savedrequest.DefaultSavedRequest;
5956
import org.springframework.util.ClassUtils;
6057

@@ -116,12 +113,14 @@ public void applyTo(GenerationContext generationContext, BeanRegistrationCode be
116113
private void registerHints(RuntimeHints hints) {
117114
// Collections -> UnmodifiableSet, UnmodifiableList, UnmodifiableMap,
118115
// UnmodifiableRandomAccessList, etc.
119-
hints.reflection().registerType(Collections.class, MemberCategory.DECLARED_CLASSES);
116+
hints.reflection()
117+
.registerType(Collections.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
118+
MemberCategory.INVOKE_DECLARED_METHODS);
120119

121120
// HashSet
122121
hints.reflection()
123-
.registerType(HashSet.class, MemberCategory.DECLARED_FIELDS,
124-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
122+
.registerType(HashSet.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
123+
MemberCategory.INVOKE_DECLARED_METHODS);
125124

126125
hints.reflection()
127126
.registerTypes(Arrays.asList(TypeReference.of(AbstractAuthenticationToken.class),
@@ -138,18 +137,17 @@ private void registerHints(RuntimeHints hints) {
138137
TypeReference.of(AuthorizationGrantType.class),
139138
TypeReference.of(OAuth2AuthorizationResponseType.class),
140139
TypeReference.of(OAuth2TokenFormat.class)),
141-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
142-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS));
140+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
141+
MemberCategory.INVOKE_DECLARED_METHODS));
143142

144143
// Jackson Modules
145144
if (jackson2Present) {
146145
hints.reflection()
147146
.registerTypes(
148-
Arrays.asList(TypeReference.of(CoreJackson2Module.class),
149-
TypeReference.of(WebServletJackson2Module.class),
150-
TypeReference.of(OAuth2AuthorizationServerJackson2Module.class)),
151-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
152-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
147+
Arrays.asList(TypeReference.of(CoreJacksonModule.class),
148+
TypeReference.of(WebServletJacksonModule.class),
149+
TypeReference.of(OAuth2AuthorizationServerJacksonModule.class)),
150+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
153151
MemberCategory.INVOKE_DECLARED_METHODS));
154152
}
155153
if (jackson3Present) {
@@ -158,8 +156,7 @@ private void registerHints(RuntimeHints hints) {
158156
Arrays.asList(TypeReference.of(CoreJacksonModule.class),
159157
TypeReference.of(WebServletJacksonModule.class),
160158
TypeReference.of(OAuth2AuthorizationServerJacksonModule.class)),
161-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
162-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
159+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
163160
MemberCategory.INVOKE_DECLARED_METHODS));
164161
}
165162

@@ -222,26 +219,23 @@ private void registerHints(RuntimeHints hints) {
222219
hints.reflection()
223220
.registerType(TypeReference
224221
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
225-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
226-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
222+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
227223
MemberCategory.INVOKE_DECLARED_METHODS));
228224

229225
// Jackson Module
230226
if (jackson2Present) {
231227
hints.reflection()
232228
.registerType(TypeReference
233229
.of("org.springframework.security.oauth2.client.jackson2.OAuth2ClientJackson2Module"),
234-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
235-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
230+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
236231
MemberCategory.INVOKE_DECLARED_METHODS));
237232
}
238233
if (jackson3Present) {
239234
hints.reflection()
240235
.registerType(
241236
TypeReference
242237
.of("org.springframework.security.oauth2.client.jackson.OAuth2ClientJacksonModule"),
243-
(builder) -> builder.withMembers(MemberCategory.DECLARED_FIELDS,
244-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
238+
(builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
245239
MemberCategory.INVOKE_DECLARED_METHODS));
246240
}
247241

oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/aot/hint/OAuth2AuthorizationServerRuntimeHints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
4646
.of("org.springframework.security.oauth2.server.authorization.web.OAuth2AuthorizationEndpointFilter$OAuth2AuthorizationCodeRequestValidatingFilter"),
4747
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
4848
hints.reflection()
49-
.registerType(OAuth2AuthorizationCodeRequestAuthenticationToken.class, MemberCategory.DECLARED_FIELDS);
49+
.registerType(OAuth2AuthorizationCodeRequestAuthenticationToken.class,
50+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
5051

5152
}
5253

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ Map<String, Object> readValue(String data) {
283283
* @deprecated Use {@link JsonMapperRegisteredClientRowMapper} to switch to Jackson 3.
284284
*/
285285
@Deprecated(forRemoval = true, since = "7.0")
286+
@SuppressWarnings("removal")
286287
public static class RegisteredClientRowMapper extends AbstractRegisteredClientRowMapper {
287288

288289
private ObjectMapper objectMapper = Jackson2.createObjectMapper();
@@ -435,6 +436,7 @@ String writeValueAsString(Map<String, Object> data) throws Exception {
435436
* Jackson 3.
436437
*/
437438
@Deprecated(forRemoval = true, since = "7.0")
439+
@SuppressWarnings("removal")
438440
public static class RegisteredClientParametersMapper extends AbstractRegisteredClientParametersMapper {
439441

440442
private ObjectMapper objectMapper = Jackson2.createObjectMapper();
@@ -527,6 +529,7 @@ private String writeMap(Map<String, Object> data) {
527529
@Deprecated(forRemoval = true, since = "7.0")
528530
private static final class Jackson2 {
529531

532+
@SuppressWarnings("removal")
530533
private static ObjectMapper createObjectMapper() {
531534
ObjectMapper objectMapper = new ObjectMapper();
532535
ClassLoader classLoader = Jackson2.class.getClassLoader();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ private OAuth2Authorization findBy(String filter, Object... args) {
657657
return !result.isEmpty() ? result.get(0) : null;
658658
}
659659

660+
@SuppressWarnings("removal")
660661
private static final class CustomOAuth2AuthorizationRowMapper
661662
extends JdbcOAuth2AuthorizationService.OAuth2AuthorizationRowMapper {
662663

@@ -794,6 +795,7 @@ private Map<String, Object> parseMap(String data) {
794795

795796
}
796797

798+
@SuppressWarnings("removal")
797799
private static final class CustomOAuth2AuthorizationParametersMapper
798800
extends JdbcOAuth2AuthorizationService.OAuth2AuthorizationParametersMapper {
799801

0 commit comments

Comments
 (0)