From 869a3714d5ce4f1c83ca13a1c1879e1b5ac2722c Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 21 Nov 2024 19:42:34 -0800 Subject: [PATCH] Move configureCsrf into method that can also be invoked later for late filterChain registration additions. Also ignore situations where FilterChainProxy exists in classpath, but is not being used. --- .../groovy/org/grails/plugins/web/taglib/FormTagLib.groovy | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/taglib/FormTagLib.groovy b/grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/taglib/FormTagLib.groovy index 32840db31a..aaf3089e3d 100644 --- a/grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/taglib/FormTagLib.groovy +++ b/grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/taglib/FormTagLib.groovy @@ -22,6 +22,7 @@ import grails.gsp.TagLib import groovy.transform.CompileStatic import groovy.util.logging.Commons import org.grails.plugins.web.GrailsTagDateHelper +import org.springframework.beans.BeansException import java.text.DateFormat import java.text.DateFormatSymbols @@ -76,6 +77,10 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar if (applicationContext.containsBean('mvcConversionService')) { conversionService = applicationContext.getBean('mvcConversionService', ConversionService) } + configureCsrf() + } + + void configureCsrf() { try { var filterChainProxy = applicationContext.getBean( Class.forName("org.springframework.security.web.FilterChainProxy")) @@ -85,7 +90,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar springSecurityCsrfTokenClass = Class.forName("org.springframework.security.web.csrf.CsrfToken") } - } catch (ClassNotFoundException ignore) {} + } catch (ClassNotFoundException | BeansException ignore) {} } /**