diff --git a/pom.xml b/pom.xml index 5cd2017..d503fd7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.bjoernkw schematic - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT Schematic Database management UI for Spring Boot @@ -34,6 +34,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-thymeleaf @@ -111,8 +115,8 @@ ALWAYS https://s01.oss.sonatype.org/service/local - false - false + true + true target/staging-deploy diff --git a/src/main/java/com/bjoernkw/schematic/TablesController.java b/src/main/java/com/bjoernkw/schematic/TablesController.java index b0b785f..66b7290 100644 --- a/src/main/java/com/bjoernkw/schematic/TablesController.java +++ b/src/main/java/com/bjoernkw/schematic/TablesController.java @@ -3,6 +3,7 @@ import io.github.wimdeblauwe.hsbt.mvc.HxRequest; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.security.web.csrf.CsrfToken; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.DeleteMapping; @@ -25,11 +26,15 @@ public TablesController(JdbcTemplate jdbcTemplate) { } @GetMapping - public String listTables(Model model) { + public String listTables(Model model, CsrfToken csrfToken) { model.addAttribute( VIEW_MODEL_NAME, getTables() ); + model.addAttribute( + "csrfTokenHeader", + "{\"" + csrfToken.getHeaderName() + "\": \"" + csrfToken.getToken() + "\"}" + ); return "index"; } @@ -37,7 +42,10 @@ public String listTables(Model model) { @DeleteMapping("/{tableName}") @HxRequest public String dropTable(@PathVariable String tableName, Model model) { - jdbcTemplate.execute("DROP TABLE " + tableName); + List availableTables = getTables(); + if (availableTables.stream().anyMatch(table -> table.getTableName().equals(tableName))) { + jdbcTemplate.execute("DROP TABLE " + tableName); + } model.addAttribute( VIEW_MODEL_NAME, @@ -50,7 +58,10 @@ public String dropTable(@PathVariable String tableName, Model model) { @DeleteMapping("/{tableName}/truncate") @HxRequest public String truncateTable(@PathVariable String tableName, Model model) { - jdbcTemplate.execute("TRUNCATE TABLE " + tableName); + List
availableTables = getTables(); + if (availableTables.stream().anyMatch(table -> table.getTableName().equals(tableName))) { + jdbcTemplate.execute("TRUNCATE TABLE " + tableName); + } model.addAttribute( VIEW_MODEL_NAME, @@ -75,6 +86,7 @@ private List
getTables() { ); table.setEntries(jdbcTemplate.queryForList("SELECT * FROM " + table.getTableName())); }); + return tables; } } diff --git a/src/main/resources/templates/fragments/tables.html b/src/main/resources/templates/fragments/tables.html index 5c30908..315a329 100644 --- a/src/main/resources/templates/fragments/tables.html +++ b/src/main/resources/templates/fragments/tables.html @@ -2,49 +2,46 @@ -
- - - - + +
+
+
+
[[${table.tableName}]] - - - - - - - - - -
- [[${column.columnName}]] ([[${column.dataType}]]) -
- [[${entry.get(column.columnName)}]] -
-
-
+ + + + + + + + +
+ [[${column.columnName}]] ([[${column.dataType}]]) +
+ [[${entry.get(column.columnName)}]] +
- - - + + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 95b6f35..8ae04b3 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -8,7 +8,7 @@ Tables
-
+

Tables