thymeleaf / thymeleaf-extras-springsecurity

Thymeleaf "extras" integration module for Spring Security 3.x and 4.x
http://www.thymeleaf.org
Apache License 2.0
482 stars 106 forks source link

Make springsecurity extras available on error page? #54

Open fapdash opened 6 years ago

fapdash commented 6 years ago

I've noticed that the extras provided by this package don't seem to be available when rendering the Spring error pages after an Exception. (e.g. error.html) ${#authentication.name} fails with a NPE. Elements with sec:authentication="name" don't get rendered.

Is this a problem with my configuration or is this a limitation of thymeleaf-extras-springsecurity?

My thymeleaf dependencies (with Spring Boot 1.5.10):

compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.7.RELEASE'
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.7.RELEASE'
compile 'org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.1.RELEASE'
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.2.2'
compile group: 'io.github.jpenren', name: 'thymeleaf-spring-data-dialect', version: '3.3.0'
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '3.0.2.RELEASE'
php-coder commented 4 years ago

This isn't Thymeleaf issue but rather the way how Spring Security is configured by default in Spring Boot (the filter doesn't bind to ERROR requests and that's why authentication info isn't available on error pages). This has been fixed in Spring Boot >= 2.0: https://github.com/spring-projects/spring-boot/issues/8289

But for 1.5, you need to add the following configuration:

security.filter-dispatcher-types: ASYNC, REQUEST, ERROR