From 4462f9157e3fc7958a723a321c3a0b042fd332dc Mon Sep 17 00:00:00 2001 From: Guirong Hu Date: Fri, 10 Dec 2021 14:13:49 +0800 Subject: [PATCH 1/2] Check for the presence of Spring Security See gh-28967 --- .../autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index cbe75645ad..9e3ad8f610 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -58,6 +58,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; +import org.springframework.security.core.context.ReactiveSecurityContextHolder; +import org.springframework.security.web.reactive.result.view.CsrfRequestDataValueProcessor; +import org.springframework.security.web.server.csrf.CsrfToken; import org.springframework.util.MimeType; import org.springframework.util.unit.DataSize; import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; @@ -279,7 +282,8 @@ public class ThymeleafAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @ConditionalOnClass({ SpringSecurityDialect.class }) + @ConditionalOnClass({ SpringSecurityDialect.class, ReactiveSecurityContextHolder.class, + CsrfRequestDataValueProcessor.class, CsrfToken.class }) static class ThymeleafSecurityDialectConfiguration { @Bean From f6f5aec1838682fd51365ea4c068b4d7cebfe71b Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 10 Dec 2021 10:59:00 +0100 Subject: [PATCH 2/2] Polish "Check for the presence of Spring Security" See gh-28967 --- .../thymeleaf/ThymeleafAutoConfiguration.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 9e3ad8f610..0c0a26c4ae 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -58,8 +58,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; -import org.springframework.security.core.context.ReactiveSecurityContextHolder; -import org.springframework.security.web.reactive.result.view.CsrfRequestDataValueProcessor; import org.springframework.security.web.server.csrf.CsrfToken; import org.springframework.util.MimeType; import org.springframework.util.unit.DataSize; @@ -282,8 +280,7 @@ public class ThymeleafAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @ConditionalOnClass({ SpringSecurityDialect.class, ReactiveSecurityContextHolder.class, - CsrfRequestDataValueProcessor.class, CsrfToken.class }) + @ConditionalOnClass({ SpringSecurityDialect.class, CsrfToken.class }) static class ThymeleafSecurityDialectConfiguration { @Bean