[bs-170] Out of the box support for thymeleaf security dialect

[Fixes #52121649]
This commit is contained in:
Dave Syer
2013-07-15 09:59:14 +01:00
parent 14aa163731
commit 789e75d2e5
5 changed files with 53 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.PostConstruct;
import javax.servlet.Servlet;
import nz.net.ultraq.thymeleaf.LayoutDialect;
@@ -38,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.thymeleaf.TemplateProcessingParameters;
import org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect;
import org.thymeleaf.resourceresolver.IResourceResolver;
import org.thymeleaf.spring3.SpringTemplateEngine;
import org.thymeleaf.spring3.view.ThymeleafViewResolver;
@@ -155,9 +157,23 @@ public class ThymeleafAutoConfiguration {
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(this.templateEngine);
resolver.setCharacterEncoding("UTF-8");
return resolver;
}
}
@Configuration
@ConditionalOnClass({ SpringSecurityDialect.class })
protected static class ThymeleafSecurityDialectConfiguration {
@Autowired
private SpringTemplateEngine templateEngine;
@PostConstruct
public void configureThymeleafSecurity() {
this.templateEngine.addDialect(new SpringSecurityDialect());
}
}
}

View File

@@ -41,6 +41,7 @@ import org.springframework.core.io.Resource;
import org.springframework.format.Formatter;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;
@@ -154,4 +155,10 @@ public class WebMvcAutoConfiguration {
}
}
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter();
}
}