I actually think there is defect in ThymeleafAutoConfiguration. I see the code where it is supposed to pick up and add SpringSecurityDialect to the Config if it's on the classpath, but in my debug, this is simply not happening (only LayoutDialect gets directed and added to the config). I have the SpringSecurityDialect class/jar on my classpath, but the bean below is never added to the config by SpringBoot AutoConfig (ThymeleafAutoConfig.java,line 97)
@Configuration
@ConditionalOnClass({SpringSecurityDialect.class})
protected static class ThymeleafSecurityDialectConfiguration {
protected ThymeleafSecurityDialectConfiguration() {
}
@Bean
@ConditionalOnMissingBean
public SpringSecurityDialect securityDialect() {
return new SpringSecurityDialect();
}
}
In the end, I had to actually add a bean to my custom Java config to get the SpringSecurityDialog recognized:
@Bean
public SpringSecurityDialect securityDialect() {
return new SpringSecurityDialect();
}
This worked first time. May you have some tests to verify this is a known issue or not? I include my pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>