From ce5f5e6e335ff96cd0379e5c9537c0e82678d2f5 Mon Sep 17 00:00:00 2001 From: Marcus Hert Da Coregio Date: Wed, 17 Jan 2024 16:14:59 -0300 Subject: [PATCH] Add native hint for CsrfTokenRequestAttributeHandler$SupplierCsrfToken Closes gh-14397 --- .../web/aot/hint/WebMvcSecurityRuntimeHints.java | 8 +++++++- .../web/aot/hint/WebMvcSecurityRuntimeHintsTests.java | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHints.java b/web/src/main/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHints.java index 66e872e649..0f9cebfa09 100644 --- a/web/src/main/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHints.java +++ b/web/src/main/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.security.web.aot.hint; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.security.web.access.expression.WebSecurityExpressionRoot; /** @@ -34,6 +35,11 @@ class WebMvcSecurityRuntimeHints implements RuntimeHintsRegistrar { hints.reflection() .registerType(WebSecurityExpressionRoot.class, (builder) -> builder .withMembers(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); + hints.reflection() + .registerType( + TypeReference + .of("org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler$SupplierCsrfToken"), + MemberCategory.INVOKE_DECLARED_METHODS); } } diff --git a/web/src/test/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHintsTests.java b/web/src/test/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHintsTests.java index 956b192179..1c279457da 100644 --- a/web/src/test/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHintsTests.java +++ b/web/src/test/java/org/springframework/security/web/aot/hint/WebMvcSecurityRuntimeHintsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.security.web.access.expression.WebSecurityExpressionRoot; @@ -53,4 +54,12 @@ class WebMvcSecurityRuntimeHintsTests { .accepts(this.hints); } + @Test + void supplierCsrfTokenHasHints() { + assertThat(RuntimeHintsPredicates.reflection() + .onType(TypeReference + .of("org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler$SupplierCsrfToken")) + .withMemberCategories(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.hints); + } + }