Skip to content

Commit 08c9791

Browse files
maibinpivovarit
authored andcommitted
Thymeleaf decorator (eugenp#747)
* Expression-Based Access Control PermitAll, hasRole, hasAnyRole etc. I modified classes regards to Security * Added test cases for Spring Security Expressions * Handler Interceptor - logging example * Test for logger interceptor * Removed conflicted part * UserInterceptor (adding user information to model) * Spring Handler Interceptor - session timers * Spring Security CSRF attack protection with Thymeleaf * Fix and(); * Logger update * Changed config for Thymeleaf * Thymeleaf Natural Processing and Inlining * Expression Utility Objects, Thymeleaf * listOfStudents edited * Thymeleaf layout decorators
1 parent 15f5a9e commit 08c9791

7 files changed

Lines changed: 296 additions & 176 deletions

File tree

‎spring-thymeleaf/pom.xml‎

Lines changed: 181 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -5,186 +5,192 @@
55
<artifactId>spring-thymeleaf</artifactId>
66
<version>0.1-SNAPSHOT</version>
77
<packaging>war</packaging>
8-
<properties>
9-
<java-version>1.8</java-version>
10-
<!-- spring -->
11-
<org.springframework-version>4.3.3.RELEASE</org.springframework-version>
12-
<javax.servlet-version>3.0.1</javax.servlet-version>
13-
<!-- logging -->
14-
<org.slf4j.version>1.7.12</org.slf4j.version>
15-
<logback.version>1.1.3</logback.version>
16-
<!-- thymeleaf -->
17-
<org.thymeleaf-version>3.0.1.RELEASE</org.thymeleaf-version>
18-
<!-- validation -->
19-
<javax.validation-version>1.1.0.Final</javax.validation-version>
20-
<org.hibernate-version>5.1.2.Final</org.hibernate-version>
8+
<properties>
9+
<java-version>1.8</java-version>
10+
<!-- spring -->
11+
<org.springframework-version>4.3.3.RELEASE</org.springframework-version>
12+
<javax.servlet-version>3.0.1</javax.servlet-version>
13+
<!-- logging -->
14+
<org.slf4j.version>1.7.12</org.slf4j.version>
15+
<logback.version>1.1.3</logback.version>
16+
<!-- thymeleaf -->
17+
<org.thymeleaf-version>3.0.1.RELEASE</org.thymeleaf-version>
18+
<!-- validation -->
19+
<javax.validation-version>1.1.0.Final</javax.validation-version>
20+
<org.hibernate-version>5.1.2.Final</org.hibernate-version>
2121

22-
<!-- Maven plugins -->
23-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
24-
<maven-war-plugin.version>2.6</maven-war-plugin.version>
25-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
26-
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
27-
</properties>
22+
<!-- Maven plugins -->
23+
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
24+
<maven-war-plugin.version>2.6</maven-war-plugin.version>
25+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
26+
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
27+
</properties>
2828

29-
<dependencies>
30-
<!-- Spring -->
31-
<dependency>
32-
<groupId>org.springframework</groupId>
33-
<artifactId>spring-context</artifactId>
34-
<version>${org.springframework-version}</version>
35-
<exclusions>
36-
<!-- Exclude Commons Logging in favor of SLF4j -->
37-
<exclusion>
38-
<groupId>commons-logging</groupId>
39-
<artifactId>commons-logging</artifactId>
40-
</exclusion>
41-
</exclusions>
42-
</dependency>
43-
<dependency>
44-
<groupId>org.springframework</groupId>
45-
<artifactId>spring-webmvc</artifactId>
46-
<version>${org.springframework-version}</version>
47-
</dependency>
48-
<!-- Spring Security -->
49-
<dependency>
50-
<groupId>org.springframework.security</groupId>
51-
<artifactId>spring-security-web</artifactId>
52-
<version>4.1.3.RELEASE</version>
53-
</dependency>
54-
<dependency>
55-
<groupId>org.springframework.security</groupId>
56-
<artifactId>spring-security-config</artifactId>
57-
<version>4.1.3.RELEASE</version>
58-
</dependency>
59-
<!-- Thymeleaf -->
60-
<dependency>
61-
<groupId>org.thymeleaf</groupId>
62-
<artifactId>thymeleaf</artifactId>
63-
<version>${org.thymeleaf-version}</version>
64-
</dependency>
65-
<dependency>
66-
<groupId>org.thymeleaf</groupId>
67-
<artifactId>thymeleaf-spring4</artifactId>
68-
<version>${org.thymeleaf-version}</version>
69-
</dependency>
70-
<!-- Logging -->
71-
<dependency>
72-
<groupId>org.slf4j</groupId>
73-
<artifactId>slf4j-api</artifactId>
74-
<version>${org.slf4j.version}</version>
75-
</dependency>
76-
<dependency>
77-
<groupId>ch.qos.logback</groupId>
78-
<artifactId>logback-classic</artifactId>
79-
<version>${logback.version}</version>
80-
<!-- <scope>runtime</scope> -->
81-
</dependency>
82-
<dependency>
83-
<groupId>org.slf4j</groupId>
84-
<artifactId>jcl-over-slf4j</artifactId>
85-
<version>${org.slf4j.version}</version>
86-
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
87-
</dependency>
88-
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
89-
<groupId>org.slf4j</groupId>
90-
<artifactId>log4j-over-slf4j</artifactId>
91-
<version>${org.slf4j.version}</version>
92-
</dependency>
93-
<!-- Servlet -->
94-
<dependency>
95-
<groupId>javax.servlet</groupId>
96-
<artifactId>javax.servlet-api</artifactId>
97-
<version>${javax.servlet-version}</version>
98-
<scope>provided</scope>
99-
</dependency>
100-
<!-- Validation -->
101-
<dependency>
102-
<groupId>javax.validation</groupId>
103-
<artifactId>validation-api</artifactId>
104-
<version>${javax.validation-version}</version>
105-
</dependency>
106-
<dependency>
107-
<groupId>org.hibernate</groupId>
108-
<artifactId>hibernate-validator</artifactId>
109-
<version>${org.hibernate-version}</version>
110-
</dependency>
111-
<!-- test scoped -->
29+
<dependencies>
30+
<!-- Spring -->
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-context</artifactId>
34+
<version>${org.springframework-version}</version>
35+
<exclusions>
36+
<!-- Exclude Commons Logging in favor of SLF4j -->
37+
<exclusion>
38+
<groupId>commons-logging</groupId>
39+
<artifactId>commons-logging</artifactId>
40+
</exclusion>
41+
</exclusions>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework</groupId>
45+
<artifactId>spring-webmvc</artifactId>
46+
<version>${org.springframework-version}</version>
47+
</dependency>
48+
<!-- Spring Security -->
49+
<dependency>
50+
<groupId>org.springframework.security</groupId>
51+
<artifactId>spring-security-web</artifactId>
52+
<version>4.1.3.RELEASE</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.security</groupId>
56+
<artifactId>spring-security-config</artifactId>
57+
<version>4.1.3.RELEASE</version>
58+
</dependency>
59+
<!-- Thymeleaf -->
60+
<dependency>
61+
<groupId>org.thymeleaf</groupId>
62+
<artifactId>thymeleaf</artifactId>
63+
<version>${org.thymeleaf-version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.thymeleaf</groupId>
67+
<artifactId>thymeleaf-spring4</artifactId>
68+
<version>${org.thymeleaf-version}</version>
69+
</dependency>
70+
<!-- https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect -->
71+
<dependency>
72+
<groupId>nz.net.ultraq.thymeleaf</groupId>
73+
<artifactId>thymeleaf-layout-dialect</artifactId>
74+
<version>2.0.4</version>
75+
</dependency>
76+
<!-- Logging -->
77+
<dependency>
78+
<groupId>org.slf4j</groupId>
79+
<artifactId>slf4j-api</artifactId>
80+
<version>${org.slf4j.version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>ch.qos.logback</groupId>
84+
<artifactId>logback-classic</artifactId>
85+
<version>${logback.version}</version>
86+
<!-- <scope>runtime</scope> -->
87+
</dependency>
88+
<dependency>
89+
<groupId>org.slf4j</groupId>
90+
<artifactId>jcl-over-slf4j</artifactId>
91+
<version>${org.slf4j.version}</version>
92+
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
93+
</dependency>
94+
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
95+
<groupId>org.slf4j</groupId>
96+
<artifactId>log4j-over-slf4j</artifactId>
97+
<version>${org.slf4j.version}</version>
98+
</dependency>
99+
<!-- Servlet -->
100+
<dependency>
101+
<groupId>javax.servlet</groupId>
102+
<artifactId>javax.servlet-api</artifactId>
103+
<version>${javax.servlet-version}</version>
104+
<scope>provided</scope>
105+
</dependency>
106+
<!-- Validation -->
107+
<dependency>
108+
<groupId>javax.validation</groupId>
109+
<artifactId>validation-api</artifactId>
110+
<version>${javax.validation-version}</version>
111+
</dependency>
112+
<dependency>
113+
<groupId>org.hibernate</groupId>
114+
<artifactId>hibernate-validator</artifactId>
115+
<version>${org.hibernate-version}</version>
116+
</dependency>
117+
<!-- test scoped -->
112118

113-
<dependency>
114-
<groupId>org.springframework</groupId>
115-
<artifactId>spring-test</artifactId>
116-
<version>4.1.3.RELEASE</version>
117-
<scope>test</scope>
118-
</dependency>
119+
<dependency>
120+
<groupId>org.springframework</groupId>
121+
<artifactId>spring-test</artifactId>
122+
<version>4.1.3.RELEASE</version>
123+
<scope>test</scope>
124+
</dependency>
119125

120-
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test -->
121-
<dependency>
122-
<groupId>org.springframework.security</groupId>
123-
<artifactId>spring-security-test</artifactId>
124-
<version>4.1.3.RELEASE</version>
125-
<scope>test</scope>
126-
</dependency>
126+
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-test -->
127+
<dependency>
128+
<groupId>org.springframework.security</groupId>
129+
<artifactId>spring-security-test</artifactId>
130+
<version>4.1.3.RELEASE</version>
131+
<scope>test</scope>
132+
</dependency>
127133

128-
<!-- https://mvnrepository.com/artifact/junit/junit -->
129-
<dependency>
130-
<groupId>junit</groupId>
131-
<artifactId>junit</artifactId>
132-
<version>4.12</version>
133-
<scope>test</scope>
134-
</dependency>
134+
<!-- https://mvnrepository.com/artifact/junit/junit -->
135+
<dependency>
136+
<groupId>junit</groupId>
137+
<artifactId>junit</artifactId>
138+
<version>4.12</version>
139+
<scope>test</scope>
140+
</dependency>
135141

136-
</dependencies>
142+
</dependencies>
143+
144+
<build>
145+
<plugins>
146+
<plugin>
147+
<groupId>org.apache.maven.plugins</groupId>
148+
<artifactId>maven-compiler-plugin</artifactId>
149+
<version>${maven-compiler-plugin.version}</version>
150+
<configuration>
151+
<source>${java-version}</source>
152+
<target>${java-version}</target>
153+
</configuration>
154+
</plugin>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-war-plugin</artifactId>
158+
<version>${maven-war-plugin.version}</version>
159+
<configuration>
160+
<failOnMissingWebXml>false</failOnMissingWebXml>
161+
</configuration>
162+
</plugin>
163+
<plugin>
164+
<groupId>org.apache.maven.plugins</groupId>
165+
<artifactId>maven-surefire-plugin</artifactId>
166+
<version>${maven-surefire-plugin.version}</version>
167+
<configuration>
168+
<excludes>
169+
</excludes>
170+
<systemPropertyVariables>
171+
</systemPropertyVariables>
172+
</configuration>
173+
</plugin>
174+
<plugin>
175+
<groupId>org.codehaus.cargo</groupId>
176+
<artifactId>cargo-maven2-plugin</artifactId>
177+
<version>${cargo-maven2-plugin.version}</version>
178+
<configuration>
179+
<wait>true</wait>
180+
<container>
181+
<containerId>jetty8x</containerId>
182+
<type>embedded</type>
183+
<systemProperties>
184+
</systemProperties>
185+
</container>
186+
<configuration>
187+
<properties>
188+
<cargo.servlet.port>8082</cargo.servlet.port>
189+
</properties>
190+
</configuration>
191+
</configuration>
192+
</plugin>
193+
</plugins>
194+
</build>
137195

138-
<build>
139-
<plugins>
140-
<plugin>
141-
<groupId>org.apache.maven.plugins</groupId>
142-
<artifactId>maven-compiler-plugin</artifactId>
143-
<version>${maven-compiler-plugin.version}</version>
144-
<configuration>
145-
<source>${java-version}</source>
146-
<target>${java-version}</target>
147-
</configuration>
148-
</plugin>
149-
<plugin>
150-
<groupId>org.apache.maven.plugins</groupId>
151-
<artifactId>maven-war-plugin</artifactId>
152-
<version>${maven-war-plugin.version}</version>
153-
<configuration>
154-
<failOnMissingWebXml>false</failOnMissingWebXml>
155-
</configuration>
156-
</plugin>
157-
<plugin>
158-
<groupId>org.apache.maven.plugins</groupId>
159-
<artifactId>maven-surefire-plugin</artifactId>
160-
<version>${maven-surefire-plugin.version}</version>
161-
<configuration>
162-
<excludes>
163-
</excludes>
164-
<systemPropertyVariables>
165-
</systemPropertyVariables>
166-
</configuration>
167-
</plugin>
168-
<plugin>
169-
<groupId>org.codehaus.cargo</groupId>
170-
<artifactId>cargo-maven2-plugin</artifactId>
171-
<version>${cargo-maven2-plugin.version}</version>
172-
<configuration>
173-
<wait>true</wait>
174-
<container>
175-
<containerId>jetty8x</containerId>
176-
<type>embedded</type>
177-
<systemProperties>
178-
</systemProperties>
179-
</container>
180-
<configuration>
181-
<properties>
182-
<cargo.servlet.port>8082</cargo.servlet.port>
183-
</properties>
184-
</configuration>
185-
</configuration>
186-
</plugin>
187-
</plugins>
188-
</build>
189-
190196
</project>

‎spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import com.baeldung.thymeleaf.formatter.NameFormatter;
2323
import com.baeldung.thymeleaf.utils.ArrayUtil;
2424

25+
import nz.net.ultraq.thymeleaf.LayoutDialect;
26+
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
27+
2528

2629
@Configuration
2730
@EnableWebMvc
@@ -70,6 +73,7 @@ public ViewResolver plainViewResolver() {
7073

7174
private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
7275
SpringTemplateEngine engine = new SpringTemplateEngine();
76+
engine.addDialect(new LayoutDialect(new GroupingStrategy()));
7377
engine.setTemplateResolver(templateResolver);
7478
return engine;
7579
}

0 commit comments

Comments
 (0)