From a56bdbe5fbc109566bffffdacd891d759c0a6084 Mon Sep 17 00:00:00 2001 From: oliverfernandez Date: Sun, 12 Aug 2018 14:09:51 +0200 Subject: [PATCH] Security architecture --- FilmFestWeb/pom.xml | 24 ++++++++++++------- .../configuration/SecurityConfiguration.java | 19 +++++++++++++++ .../intranet/IntranetController.java | 23 ++++++------------ .../filmfestweb/web/WebController.java | 15 ++++++++++++ .../resources/templates/intranet/index.html | 11 +++++++++ .../main/resources/templates/web/index.html | 11 +++++++++ 6 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/configuration/SecurityConfiguration.java create mode 100644 FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/web/WebController.java create mode 100644 FilmFestWeb/src/main/resources/templates/intranet/index.html create mode 100644 FilmFestWeb/src/main/resources/templates/web/index.html diff --git a/FilmFestWeb/pom.xml b/FilmFestWeb/pom.xml index 178a012..f0b0bb4 100644 --- a/FilmFestWeb/pom.xml +++ b/FilmFestWeb/pom.xml @@ -28,6 +28,7 @@ org.springframework.boot spring-boot-devtools + true @@ -36,18 +37,23 @@ test + + + org.springframework.boot + spring-boot-starter-thymeleaf + - - - - + + org.springframework.boot + spring-boot-starter-security + - - - - - + + org.springframework.security + spring-security-test + test + diff --git a/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/configuration/SecurityConfiguration.java b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/configuration/SecurityConfiguration.java new file mode 100644 index 0000000..4362659 --- /dev/null +++ b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/configuration/SecurityConfiguration.java @@ -0,0 +1,19 @@ +package com.tantarantana.filmfestweb.configuration; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +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; + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(securedEnabled = true) +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + http.formLogin(); +// super.configure(http); + } +} + diff --git a/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/intranet/IntranetController.java b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/intranet/IntranetController.java index 5fd6f4a..8da15b8 100644 --- a/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/intranet/IntranetController.java +++ b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/intranet/IntranetController.java @@ -5,31 +5,22 @@ import com.tantarantana.domain.edition.EditionRepository; import com.tantarantana.domain.serie.SerieRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.annotation.Secured; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.ArrayList; import java.util.List; @Controller +@RequestMapping("/intranet") +@Secured("isAuthenticated()") public class IntranetController { - @Autowired - private EditionRepository editionRepository; - - @Autowired - private SerieRepository serieRepository; - - - @GetMapping("/intranet/editions") - @ResponseBody - public List editions() { - List editions = new ArrayList<>(); - - editionRepository.findAll().forEach(editions::add); - serieRepository.findAll(); - - return editions; + @GetMapping({"", "/"}) + public String index() { + return "intranet/index"; } } diff --git a/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/web/WebController.java b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/web/WebController.java new file mode 100644 index 0000000..6e129a5 --- /dev/null +++ b/FilmFestWeb/src/main/java/com/tantarantana/filmfestweb/web/WebController.java @@ -0,0 +1,15 @@ +package com.tantarantana.filmfestweb.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/") +public class WebController { + + @GetMapping + public String index() { + return "web/index"; + } +} diff --git a/FilmFestWeb/src/main/resources/templates/intranet/index.html b/FilmFestWeb/src/main/resources/templates/intranet/index.html new file mode 100644 index 0000000..8c19f7d --- /dev/null +++ b/FilmFestWeb/src/main/resources/templates/intranet/index.html @@ -0,0 +1,11 @@ + + + + + Tantarantana Intranet + + + Welcome to Tantarantana Intranet + + + \ No newline at end of file diff --git a/FilmFestWeb/src/main/resources/templates/web/index.html b/FilmFestWeb/src/main/resources/templates/web/index.html new file mode 100644 index 0000000..c1dbd34 --- /dev/null +++ b/FilmFestWeb/src/main/resources/templates/web/index.html @@ -0,0 +1,11 @@ + + + + + Tantarantana Public + + + Welcome to Tantarantana main page + + + \ No newline at end of file