From 7e9794256ddeae1e45733ea388b503989e3d18ff Mon Sep 17 00:00:00 2001 From: "korneliusz.wandzel" Date: Mon, 29 Jan 2018 01:03:39 +0100 Subject: [PATCH 01/20] =?UTF-8?q?Commit=20for=20Different=20Types=20of=20B?= =?UTF-8?q?ean=20Injection=20in=20Spring=20=E2=80=94=20Draft=20article?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/baeldung/beaninjectiontypes/Boat.java | 19 +++++++++++++++ .../com/baeldung/beaninjectiontypes/Car.java | 18 +++++++++++++++ .../baeldung/beaninjectiontypes/Config.java | 10 ++++++++ .../baeldung/beaninjectiontypes/Engine.java | 8 +++++++ .../beaninjectiontypes/LawnMower.java | 19 +++++++++++++++ .../baeldung/beaninjectiontypes/Rocket.java | 20 ++++++++++++++++ .../baeldung/beaninjectiontypes/BoatTest.java | 23 +++++++++++++++++++ .../baeldung/beaninjectiontypes/CarTest.java | 23 +++++++++++++++++++ .../beaninjectiontypes/LawnMowerTest.java | 23 +++++++++++++++++++ .../beaninjectiontypes/RocketTest.java | 23 +++++++++++++++++++ 10 files changed, 186 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java create mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java create mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java create mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java create mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java create mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java new file mode 100644 index 0000000000..a7138aff40 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java @@ -0,0 +1,19 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Boat { + + private Engine engine; + + @Autowired + public void setEngine(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } +} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java new file mode 100644 index 0000000000..d943a0a839 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java @@ -0,0 +1,18 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Car { + @Autowired + private Engine engine; + + public void setEngine(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } +} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java new file mode 100644 index 0000000000..928ea1d794 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java @@ -0,0 +1,10 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.beaninjectiontypes") +public class Config { + +} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java new file mode 100644 index 0000000000..71c9a5855b --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java @@ -0,0 +1,8 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.stereotype.Component; + +@Component +public class Engine { + +} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java new file mode 100644 index 0000000000..19b71bf8d3 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java @@ -0,0 +1,19 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class LawnMower { + + @Autowired + private Engine engine; + + public LawnMower(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } +} diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java new file mode 100644 index 0000000000..7bfbc6fc01 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java @@ -0,0 +1,20 @@ +package com.baeldung.beaninjectiontypes; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Rocket { + + private Engine engine; + + @Autowired + public Rocket(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } + +} diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java new file mode 100644 index 0000000000..f89a14e942 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java @@ -0,0 +1,23 @@ +package com.baeldung.beaninjectiontypes; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Config.class) +public class BoatTest { + + @Autowired + Boat boat; + + @Test + public void engineInjectionTest() { + assertNotNull(boat); + assertNotNull(boat.getEngine()); + } +} diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java new file mode 100644 index 0000000000..7c022f891b --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java @@ -0,0 +1,23 @@ +package com.baeldung.beaninjectiontypes; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Config.class) +public class CarTest { + + @Autowired + Car car; + + @Test + public void engineInjectionTest() { + assertNotNull(car); + assertNotNull(car.getEngine()); + } +} diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java new file mode 100644 index 0000000000..84595c717d --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java @@ -0,0 +1,23 @@ +package com.baeldung.beaninjectiontypes; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Config.class) +public class LawnMowerTest { + + @Autowired + LawnMower lawnMower; + + @Test + public void engineInjectionTest() { + assertNotNull(lawnMower); + assertNotNull(lawnMower.getEngine()); + } +} diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java new file mode 100644 index 0000000000..3fe44d266e --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java @@ -0,0 +1,23 @@ +package com.baeldung.beaninjectiontypes; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Config.class) +public class RocketTest { + + @Autowired + Rocket rocket; + + @Test + public void engineInjectionTest() { + assertNotNull(rocket); + assertNotNull(rocket.getEngine()); + } +} From 8b8a6a6e5471c1575fc8467355644113cf290efd Mon Sep 17 00:00:00 2001 From: Korneliusz Wandzel Date: Tue, 30 Jan 2018 18:58:25 +0100 Subject: [PATCH 02/20] test names refactoring to given when then --- .../src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java | 2 +- .../src/test/java/com/baeldung/beaninjectiontypes/CarTest.java | 2 +- .../java/com/baeldung/beaninjectiontypes/LawnMowerTest.java | 2 +- .../test/java/com/baeldung/beaninjectiontypes/RocketTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java index f89a14e942..1ffe6a752f 100644 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java @@ -16,7 +16,7 @@ public class BoatTest { Boat boat; @Test - public void engineInjectionTest() { + public void givenAutowired_whenOnSetter_thenInjected() { assertNotNull(boat); assertNotNull(boat.getEngine()); } diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java index 7c022f891b..7bb9b31dde 100644 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java @@ -16,7 +16,7 @@ public class CarTest { Car car; @Test - public void engineInjectionTest() { + public void givenAutowired_whenOnField_thenSetterInjected() { assertNotNull(car); assertNotNull(car.getEngine()); } diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java index 84595c717d..f59ef05247 100644 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java @@ -16,7 +16,7 @@ public class LawnMowerTest { LawnMower lawnMower; @Test - public void engineInjectionTest() { + public void givenAutowired_whenOnField_thenConstructorInjected() { assertNotNull(lawnMower); assertNotNull(lawnMower.getEngine()); } diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java index 3fe44d266e..4723cc450e 100644 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java +++ b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java @@ -16,7 +16,7 @@ public class RocketTest { Rocket rocket; @Test - public void engineInjectionTest() { + public void givenAutowired_whenOnConstructor_thenInjected() { assertNotNull(rocket); assertNotNull(rocket.getEngine()); } From f6a5b7063f2e40045bbd8a7be0cb20893c774ecf Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 10 Feb 2018 17:52:26 +0100 Subject: [PATCH 03/20] Create README.MD --- spring-security-thymeleaf/README.MD | 1 + 1 file changed, 1 insertion(+) create mode 100644 spring-security-thymeleaf/README.MD diff --git a/spring-security-thymeleaf/README.MD b/spring-security-thymeleaf/README.MD new file mode 100644 index 0000000000..be5c138cd6 --- /dev/null +++ b/spring-security-thymeleaf/README.MD @@ -0,0 +1 @@ +This module is for Spring Security Thymeleaf tutorial. From 49d880bf5898865019c092b5837b97768fc5b797 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 10 Feb 2018 18:26:52 +0100 Subject: [PATCH 04/20] Create pom.xml --- spring-security-thymeleaf/pom.xml | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 spring-security-thymeleaf/pom.xml diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml new file mode 100644 index 0000000000..14e4e5210b --- /dev/null +++ b/spring-security-thymeleaf/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.baeldung + spring-security-thymeleaf + 0.0.1-SNAPSHOT + jar + + spring-security-thymeleaf + Spring Security with Thymeleaf tutorial + + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.BUILD-SNAPSHOT + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + From 9dd6ca91795d3658b1fe451949909310b81dff28 Mon Sep 17 00:00:00 2001 From: lol Date: Fri, 16 Feb 2018 22:31:53 +0100 Subject: [PATCH 05/20] BAEL-1556 --- spring-security-thymeleaf/pom.xml | 17 +++++++-- .../SecurityConfiguration.java | 38 +++++++++++++++++++ .../SpringSecurityThymeleafApplication.java | 12 ++++++ .../ViewController.java | 24 ++++++++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/templates/index.html | 12 ++++++ .../src/main/resources/templates/login.html | 15 ++++++++ .../main/resources/templates/loginError.html | 9 +++++ ...ringSecurityThymeleafApplicationTests.java | 27 +++++++++++++ .../ViewControllerIntegrationTest.java | 27 +++++++++++++ 10 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java create mode 100644 spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java create mode 100644 spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java create mode 100644 spring-security-thymeleaf/src/main/resources/application.properties create mode 100644 spring-security-thymeleaf/src/main/resources/templates/index.html create mode 100644 spring-security-thymeleaf/src/main/resources/templates/login.html create mode 100644 spring-security-thymeleaf/src/main/resources/templates/loginError.html create mode 100644 spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java create mode 100644 spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/ViewControllerIntegrationTest.java diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index 14e4e5210b..0f44cf7032 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -12,10 +12,10 @@ Spring Security with Thymeleaf tutorial - org.springframework.boot - spring-boot-starter-parent - 2.0.0.BUILD-SNAPSHOT - + parent-boot-5 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-5 @@ -48,6 +48,15 @@ spring-security-test test + + org.thymeleaf.extras + thymeleaf-extras-springsecurity4 + + + + org.springframework.security + spring-security-taglibs + diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java new file mode 100644 index 0000000000..185093adfa --- /dev/null +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java @@ -0,0 +1,38 @@ +package com.baeldung.springsecuritythymeleaf; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +@Configuration +@EnableWebSecurity +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/login") + .permitAll().failureUrl("/loginError").successForwardUrl("/index") + .and() + .logout() + .permitAll() + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/login"); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("user").password("password").roles("USER").and() + .withUser("admin").password("admin").roles("ADMIN"); + } +} diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java new file mode 100644 index 0000000000..c6e4dc1469 --- /dev/null +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.springsecuritythymeleaf; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringSecurityThymeleafApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSecurityThymeleafApplication.class, args); + } +} diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java new file mode 100644 index 0000000000..2f2fa69608 --- /dev/null +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java @@ -0,0 +1,24 @@ +package com.baeldung.springsecuritythymeleaf; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class ViewController { + + @RequestMapping("/login") + public String login() { + return "login"; + } + + @RequestMapping({"/index", "/"}) + public String index() { + return "index"; + } + + @RequestMapping("/loginError") + public String loginError() { + return "loginError"; + } + +} diff --git a/spring-security-thymeleaf/src/main/resources/application.properties b/spring-security-thymeleaf/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-security-thymeleaf/src/main/resources/templates/index.html b/spring-security-thymeleaf/src/main/resources/templates/index.html new file mode 100644 index 0000000000..6cbc8f867e --- /dev/null +++ b/spring-security-thymeleaf/src/main/resources/templates/index.html @@ -0,0 +1,12 @@ + + + +Welcome to Spring Security Thymeleaf tutorial + + +

Welcome

+

Spring Security Thymeleaf tutorial

+
Text visible to user.
+
Text visible to admin.
+ + \ No newline at end of file diff --git a/spring-security-thymeleaf/src/main/resources/templates/login.html b/spring-security-thymeleaf/src/main/resources/templates/login.html new file mode 100644 index 0000000000..49cbedabf2 --- /dev/null +++ b/spring-security-thymeleaf/src/main/resources/templates/login.html @@ -0,0 +1,15 @@ + + + +Insert title here + + +

Custom Login Page

+
+ :
:
+
+ + \ No newline at end of file diff --git a/spring-security-thymeleaf/src/main/resources/templates/loginError.html b/spring-security-thymeleaf/src/main/resources/templates/loginError.html new file mode 100644 index 0000000000..1e05cb4a87 --- /dev/null +++ b/spring-security-thymeleaf/src/main/resources/templates/loginError.html @@ -0,0 +1,9 @@ + + + +Login error page + + +

Login Error Page

+ + \ No newline at end of file diff --git a/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java new file mode 100644 index 0000000000..dea254dd31 --- /dev/null +++ b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplicationTests.java @@ -0,0 +1,27 @@ +package com.baeldung.springsecuritythymeleaf; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringSecurityThymeleafApplicationTests { + + @Autowired + ViewController viewController; + @Autowired + WebApplicationContext wac; + + @Test + public void whenConfigured_thenLoadsContext() { + assertNotNull(viewController); + assertNotNull(wac); + } + +} diff --git a/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/ViewControllerIntegrationTest.java b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/ViewControllerIntegrationTest.java new file mode 100644 index 0000000000..d2e7354d2d --- /dev/null +++ b/spring-security-thymeleaf/src/test/java/com/baeldung/springsecuritythymeleaf/ViewControllerIntegrationTest.java @@ -0,0 +1,27 @@ +package com.baeldung.springsecuritythymeleaf; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@WebMvcTest +public class ViewControllerIntegrationTest { + + @Autowired + MockMvc mockMvc; + + @Test + public void givenUser_whenPerformingGet_thenReturnsIndex() throws Exception { + mockMvc.perform(get("/index").with(user("user").password("password"))).andExpect(status().isOk()).andExpect(view().name("index")); + } + +} From 6642fc53a4feaff8ce9051e2f0018b11e22b937a Mon Sep 17 00:00:00 2001 From: kwandzel Date: Fri, 16 Feb 2018 22:59:09 +0100 Subject: [PATCH 06/20] cleaning dependencies --- spring-security-thymeleaf/pom.xml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index 0f44cf7032..f40aabcf8b 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -48,15 +48,10 @@ spring-security-test test - - org.thymeleaf.extras - thymeleaf-extras-springsecurity4 - - - - org.springframework.security - spring-security-taglibs - + + org.thymeleaf.extras + thymeleaf-extras-springsecurity4 + From 77735a57fd196e683dfb49c0c8deedab652d2bcf Mon Sep 17 00:00:00 2001 From: kwandzel Date: Sat, 17 Feb 2018 16:59:50 +0100 Subject: [PATCH 07/20] improvements, additional security dialect --- .../springsecuritythymeleaf/SecurityConfiguration.java | 7 +++---- .../baeldung/springsecuritythymeleaf/ViewController.java | 8 ++++---- .../src/main/resources/templates/index.html | 3 +++ .../src/main/resources/templates/login.html | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java index 185093adfa..9c734a6b2d 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java @@ -30,9 +30,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER").and() - .withUser("admin").password("admin").roles("ADMIN"); + auth.inMemoryAuthentication() + .withUser("user").password("password").roles("USER").and() + .withUser("admin").password("admin").roles("ADMIN"); } } diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java index 2f2fa69608..81b891dad8 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java @@ -5,17 +5,17 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ViewController { - + @RequestMapping("/login") public String login() { return "login"; } - - @RequestMapping({"/index", "/"}) + + @RequestMapping({ "/index", "/" }) public String index() { return "index"; } - + @RequestMapping("/loginError") public String loginError() { return "loginError"; diff --git a/spring-security-thymeleaf/src/main/resources/templates/index.html b/spring-security-thymeleaf/src/main/resources/templates/index.html index 6cbc8f867e..c127f7c663 100644 --- a/spring-security-thymeleaf/src/main/resources/templates/index.html +++ b/spring-security-thymeleaf/src/main/resources/templates/index.html @@ -8,5 +8,8 @@

Spring Security Thymeleaf tutorial

Text visible to user.
Text visible to admin.
+
Text visible only to authenticated users.
+ Authenticated username:
+ Authenticated user roles:
\ No newline at end of file diff --git a/spring-security-thymeleaf/src/main/resources/templates/login.html b/spring-security-thymeleaf/src/main/resources/templates/login.html index 49cbedabf2..92cade03ec 100644 --- a/spring-security-thymeleaf/src/main/resources/templates/login.html +++ b/spring-security-thymeleaf/src/main/resources/templates/login.html @@ -1,7 +1,7 @@ -Insert title here +Custom Login Page

Custom Login Page

From 1b18720fb3394179707a9087cf6308b808b3a66a Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:26:45 +0100 Subject: [PATCH 08/20] Delete Boat.java --- .../com/baeldung/beaninjectiontypes/Boat.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java deleted file mode 100644 index a7138aff40..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Boat.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class Boat { - - private Engine engine; - - @Autowired - public void setEngine(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } -} From c0220b2a3404340462eaf0381f529ca125e00a57 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:27:43 +0100 Subject: [PATCH 09/20] Delete Car.java --- .../com/baeldung/beaninjectiontypes/Car.java | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java deleted file mode 100644 index d943a0a839..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Car.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class Car { - @Autowired - private Engine engine; - - public void setEngine(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } -} From 3148bebd72ff18eeda2cec17f4d2708a60b1a90a Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:28:02 +0100 Subject: [PATCH 10/20] Delete Config.java --- .../java/com/baeldung/beaninjectiontypes/Config.java | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java deleted file mode 100644 index 928ea1d794..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Config.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ComponentScan("com.baeldung.beaninjectiontypes") -public class Config { - -} From 15481af880feaf4e60f40a89536e4a0a99331ba8 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:28:10 +0100 Subject: [PATCH 11/20] Delete Engine.java --- .../main/java/com/baeldung/beaninjectiontypes/Engine.java | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java deleted file mode 100644 index 71c9a5855b..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Engine.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.stereotype.Component; - -@Component -public class Engine { - -} From 34cbaab012ca092d4b659d838002218011b6c03e Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:28:19 +0100 Subject: [PATCH 12/20] Delete LawnMower.java --- .../beaninjectiontypes/LawnMower.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java deleted file mode 100644 index 19b71bf8d3..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/LawnMower.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class LawnMower { - - @Autowired - private Engine engine; - - public LawnMower(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } -} From 099678fd50c4042c46657fcec3e7c747520cca70 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:28:30 +0100 Subject: [PATCH 13/20] Delete Rocket.java --- .../baeldung/beaninjectiontypes/Rocket.java | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java diff --git a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java b/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java deleted file mode 100644 index 7bfbc6fc01..0000000000 --- a/spring-core/src/main/java/com/baeldung/beaninjectiontypes/Rocket.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class Rocket { - - private Engine engine; - - @Autowired - public Rocket(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } - -} From f9d3687435bedd6325e7b96578f4ee9511ed9fcb Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:32:46 +0100 Subject: [PATCH 14/20] adding module --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index ca6d4afe82..ea20aebde0 100644 --- a/pom.xml +++ b/pom.xml @@ -279,6 +279,7 @@ lucene vraptor persistence-modules/java-cockroachdb + spring-security-thymeleaf From 5b4d0fb58391ac180776dc12a3d717f935a4fbe5 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:38:05 +0100 Subject: [PATCH 15/20] Delete BoatTest.java --- .../baeldung/beaninjectiontypes/BoatTest.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java deleted file mode 100644 index 1ffe6a752f..0000000000 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/BoatTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Config.class) -public class BoatTest { - - @Autowired - Boat boat; - - @Test - public void givenAutowired_whenOnSetter_thenInjected() { - assertNotNull(boat); - assertNotNull(boat.getEngine()); - } -} From 250feb50a05e46475911f15de129b9a92532d085 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:38:14 +0100 Subject: [PATCH 16/20] Delete CarTest.java --- .../baeldung/beaninjectiontypes/CarTest.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java deleted file mode 100644 index 7bb9b31dde..0000000000 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/CarTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Config.class) -public class CarTest { - - @Autowired - Car car; - - @Test - public void givenAutowired_whenOnField_thenSetterInjected() { - assertNotNull(car); - assertNotNull(car.getEngine()); - } -} From 2e65942cb25a98e5a75d8bab18c9f019f261309e Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:38:23 +0100 Subject: [PATCH 17/20] Delete LawnMowerTest.java --- .../beaninjectiontypes/LawnMowerTest.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java deleted file mode 100644 index f59ef05247..0000000000 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/LawnMowerTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Config.class) -public class LawnMowerTest { - - @Autowired - LawnMower lawnMower; - - @Test - public void givenAutowired_whenOnField_thenConstructorInjected() { - assertNotNull(lawnMower); - assertNotNull(lawnMower.getEngine()); - } -} From e60ed53788f84aa0c8fbdbccce5687d3d0868f81 Mon Sep 17 00:00:00 2001 From: kornelihno Date: Sat, 17 Feb 2018 17:38:30 +0100 Subject: [PATCH 18/20] Delete RocketTest.java --- .../beaninjectiontypes/RocketTest.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java diff --git a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java b/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java deleted file mode 100644 index 4723cc450e..0000000000 --- a/spring-core/src/test/java/com/baeldung/beaninjectiontypes/RocketTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.beaninjectiontypes; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Config.class) -public class RocketTest { - - @Autowired - Rocket rocket; - - @Test - public void givenAutowired_whenOnConstructor_thenInjected() { - assertNotNull(rocket); - assertNotNull(rocket.getEngine()); - } -} From b021e6b01a36fc0ba05c89c30e56c99c94bc5f15 Mon Sep 17 00:00:00 2001 From: kwandzel Date: Mon, 19 Feb 2018 21:09:57 +0100 Subject: [PATCH 19/20] Readme change --- spring-security-thymeleaf/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-thymeleaf/README.MD b/spring-security-thymeleaf/README.MD index be5c138cd6..44d118f8a8 100644 --- a/spring-security-thymeleaf/README.MD +++ b/spring-security-thymeleaf/README.MD @@ -1 +1,2 @@ This module is for Spring Security Thymeleaf tutorial. +Jira BAEL-1556 \ No newline at end of file From 94421b7d388cea17a3d1fb7da8e87960c9dcc082 Mon Sep 17 00:00:00 2001 From: kwandzel Date: Mon, 19 Feb 2018 22:45:40 +0100 Subject: [PATCH 20/20] [BAEL-1556]:fixes according to a review --- .../SecurityConfiguration.java | 34 +++++++++++-------- .../SpringSecurityThymeleafApplication.java | 6 ++-- .../ViewController.java | 22 +++++------- .../src/main/resources/templates/index.html | 9 +++-- .../src/main/resources/templates/login.html | 4 +-- .../main/resources/templates/loginError.html | 9 ----- 6 files changed, 39 insertions(+), 45 deletions(-) delete mode 100644 spring-security-thymeleaf/src/main/resources/templates/loginError.html diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java index 9c734a6b2d..687c0c2e39 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java @@ -12,26 +12,32 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - @Override + @Override protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests() - .anyRequest().authenticated() - .and() + http.authorizeRequests() + .anyRequest() + .authenticated() + .and() .formLogin() - .loginPage("/login") - .permitAll().failureUrl("/loginError").successForwardUrl("/index") - .and() + .loginPage("/login") + .permitAll() + .successForwardUrl("/index") + .and() .logout() - .permitAll() - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .logoutSuccessUrl("/login"); + .permitAll() + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/login"); } @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser("user").password("password").roles("USER").and() - .withUser("admin").password("admin").roles("ADMIN"); + .withUser("user") + .password("password") + .roles("USER") + .and() + .withUser("admin") + .password("admin") + .roles("ADMIN"); } } diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java index c6e4dc1469..09a4e74988 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SpringSecurityThymeleafApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringSecurityThymeleafApplication { - public static void main(String[] args) { - SpringApplication.run(SpringSecurityThymeleafApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(SpringSecurityThymeleafApplication.class, args); + } } diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java index 81b891dad8..a2337f9db5 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/ViewController.java @@ -6,19 +6,13 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ViewController { - @RequestMapping("/login") - public String login() { - return "login"; - } - - @RequestMapping({ "/index", "/" }) - public String index() { - return "index"; - } - - @RequestMapping("/loginError") - public String loginError() { - return "loginError"; - } + @RequestMapping("/login") + public String login() { + return "login"; + } + @RequestMapping({ "/index", "/" }) + public String index() { + return "index"; + } } diff --git a/spring-security-thymeleaf/src/main/resources/templates/index.html b/spring-security-thymeleaf/src/main/resources/templates/index.html index c127f7c663..27426ec496 100644 --- a/spring-security-thymeleaf/src/main/resources/templates/index.html +++ b/spring-security-thymeleaf/src/main/resources/templates/index.html @@ -8,8 +8,11 @@

Spring Security Thymeleaf tutorial

Text visible to user.
Text visible to admin.
-
Text visible only to authenticated users.
- Authenticated username:
- Authenticated user roles:
+
Text visible only to + authenticated users.
+ Authenticated username: +
+ Authenticated user roles: +
\ No newline at end of file diff --git a/spring-security-thymeleaf/src/main/resources/templates/login.html b/spring-security-thymeleaf/src/main/resources/templates/login.html index 92cade03ec..0177f7d8e8 100644 --- a/spring-security-thymeleaf/src/main/resources/templates/login.html +++ b/spring-security-thymeleaf/src/main/resources/templates/login.html @@ -7,9 +7,9 @@

Custom Login Page

: