From 499156f90bb730f4e0b21c3013d1b422d6457821 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 30 Sep 2020 13:33:36 -0400 Subject: [PATCH] Setup for Secure Auth via MySQL --- pom.xml | 6 ++++- src/main/java/MTGClone/WebSecurityConfig.java | 22 ++++++++++++++++ .../MTGClone/controller/CardController.java | 25 +++++++++---------- src/main/webapp/WEB-INF/jsp/card.jsp | 15 ++++------- 4 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 src/main/java/MTGClone/WebSecurityConfig.java diff --git a/pom.xml b/pom.xml index c9d17a9..4d96524 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,11 @@ org.springframework.boot spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-security + jstl diff --git a/src/main/java/MTGClone/WebSecurityConfig.java b/src/main/java/MTGClone/WebSecurityConfig.java new file mode 100644 index 0000000..120092e --- /dev/null +++ b/src/main/java/MTGClone/WebSecurityConfig.java @@ -0,0 +1,22 @@ +package MTGClone; + +import org.springframework.context.annotation.Configuration; +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 +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + System.out.println("Called configure(HttpSecurity http);"); + http.authorizeRequests().antMatchers("/").permitAll().anyRequest().authenticated().and().formLogin().and() + .csrf().disable().logout(); + } + + // TODO: Login using SQLDriver.authenticateUser(username, password) + + +} \ No newline at end of file diff --git a/src/main/java/MTGClone/controller/CardController.java b/src/main/java/MTGClone/controller/CardController.java index 39d97a5..fa01930 100644 --- a/src/main/java/MTGClone/controller/CardController.java +++ b/src/main/java/MTGClone/controller/CardController.java @@ -1,5 +1,6 @@ package MTGClone.controller; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; @@ -14,24 +15,22 @@ import java.util.ArrayList; @Controller public class CardController { @GetMapping({"/card", "/"}) - public String hello(Model model) { + public String showCards(Model model) { ArrayList allCards = (new SQLDriver()).getAllCards(); model.addAttribute("allcards", allCards); - return "card"; } - - - - @PostMapping({"/card"}) - public String greet(@RequestParam("cardname") String cardname, @RequestParam("manacost") int manacost, - @RequestParam("power") int power, @RequestParam("toughness") int toughness, @RequestParam("description") String description, @RequestParam("creaturetype") String creaturetype, - @RequestParam("username") String username, @RequestParam("password") String password, ModelMap modelMap) { + + @PostMapping({"/card", "/"}) + public String newCard(@RequestParam("cardname") String cardname, @RequestParam("manacost") int manacost, + @RequestParam("power") int power, @RequestParam("toughness") int toughness, @RequestParam("description") String description, + @RequestParam("creaturetype") String creaturetype, ModelMap modelMap) { SQLDriver d = new SQLDriver(); - if (d.authenticateUser(username, password)) { - Card newCard = new Card(cardname, manacost, power, toughness, description, "", creaturetype); - d.insertCard(newCard); - } + System.out.println(creaturetype); + System.out.println("Posting to /card detected"); + Card newCard = new Card(cardname, manacost, power, toughness, description, "", creaturetype); + d.insertCard(newCard); + //modelMap.addAttribute("allcards", d.getAllCards()); return "card"; } diff --git a/src/main/webapp/WEB-INF/jsp/card.jsp b/src/main/webapp/WEB-INF/jsp/card.jsp index 99fa0e0..a7c6679 100644 --- a/src/main/webapp/WEB-INF/jsp/card.jsp +++ b/src/main/webapp/WEB-INF/jsp/card.jsp @@ -1,6 +1,6 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - + @@ -38,7 +38,7 @@ table, td, th{
-
+



@@ -48,7 +48,7 @@ table, td, th{ - @@ -56,12 +56,7 @@ table, td, th{

- - - - -
- +