Skip to content

Commit

Permalink
Merge pull request #1 from wiverson/dev
Browse files Browse the repository at this point in the history
Add Spring Security Demo
  • Loading branch information
wiverson committed Jun 28, 2021
2 parents eaa5f69 + 9109801 commit 8a15017
Show file tree
Hide file tree
Showing 47 changed files with 1,873 additions and 139 deletions.
67 changes: 44 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,46 @@
<dependencies>

<!-- Spring Security related -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.thymeleaf.extras</groupId>-->
<!-- <artifactId>thymeleaf-extras-springsecurity5</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<!-- Remove noise from build introduced by Spring 2.5.0 -->
<!-- https://stackoverflow.com/questions/67630048/springboot-2-5-0-for-jackson-kotlin-classes-support-please-add-com-fasterxml-ja -->
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Spring Data related -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -91,6 +107,11 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<!-- Layouts -->
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
Expand Down Expand Up @@ -137,7 +158,7 @@
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
<version>0.46</version>
<version>0.47</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo;
package com.devhow;

import nz.net.ultraq.thymeleaf.LayoutDialect;
import org.springframework.boot.SpringApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -9,7 +9,7 @@
import java.util.Date;

@Controller
@RequestMapping("/click-to-edit")
@RequestMapping("/public/click-to-edit")
public class ClickToEdit {

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import com.github.javafaker.Faker;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

Expand All @@ -15,5 +16,4 @@ public String overview(Model model) {
return "index";
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import org.intellij.lang.annotations.Language;
import org.springframework.http.MediaType;
Expand All @@ -25,7 +25,7 @@
* different approach.
*/
@Controller
@RequestMapping("/infinite-scroll")
@RequestMapping("/public/infinite-scroll")
public class InfiniteScroll {

@GetMapping
Expand All @@ -45,7 +45,7 @@ public String start(Model model) {

@Language("html")
final String loadHtml = """
<tr hx-get="/infinite-scroll/page/%d"
<tr hx-get="/public/infinite-scroll/page/%d"
hx-trigger="revealed"
hx-swap="afterend">
<td>%s</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import j2html.tags.ContainerTag;
import org.springframework.http.MediaType;
Expand All @@ -17,7 +17,7 @@
import static j2html.TagCreator.*;

@Controller
@RequestMapping("/input")
@RequestMapping("/public/input")
public class InputCatalog {

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devhow.htmxdemo.demo;
package com.devhow.htmxdemo;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
Expand All @@ -10,7 +10,7 @@
import static j2html.TagCreator.*;

@Controller
@RequestMapping("/todo")
@RequestMapping("/public/todo")
public class ToDoList {

@GetMapping
Expand Down Expand Up @@ -39,7 +39,7 @@ public String create(@RequestParam("new-todo") String todo) {
.attr("hx-confirm", "Are you sure?")
.attr("hx-target", "closest tr")
.attr("hx-swap", "outerHTML swap:1s")
.attr("hx-delete", "/todo/delete")
.attr("hx-delete", "/public/todo/delete")
.attr("hx-trigger", "click")
.withClasses("btn", "btn-danger")
)
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/devhow/htmxdemo/TopSecret.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.devhow.htmxdemo;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/private/")
public class TopSecret {

@GetMapping("/")
public String index(Model model) {
model.addAttribute("now", new Date());
return "private-index";
}

@GetMapping(path = "/data", produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String data() {
return "<p>hi! %s </p>".formatted(new Date().toString());
}

}
82 changes: 82 additions & 0 deletions src/main/java/com/devhow/htmxdemo/ValueSelect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.devhow.htmxdemo;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import org.intellij.lang.annotations.Language;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.Date;

@Controller
@RequestMapping("/public/value-select")
public class ValueSelect {

/**
* IntelliJ has a plugin that supports handlebars inline (and file template) syntax highlighting.
* <p>
* https://plugins.jetbrains.com/plugin/6884-handlebars-mustache
*/
@Language("handlebars")
String handleBarTemplate =
"""
{{#each}}
<option value="{{this}}">{{{this}}}</option>
{{/each}}
""";
Template template;
private String[] java8 = {"lambdas", "collections", "streams"};
private String[] java9 = {"collections", "streams", "optionals", "interfaces", "jshell"};
private String[] java10 = {"var"};
private String[] java11 = {"strings", "scripts", "lambda var"};
private String[] java12 = {"unicode 11"};
private String[] java13 = {"unicode 12"};
private String[] java14 = {"switch", "better null pointer error messages"};
private String[] java15 = {"text blocks", "Z garbage collector"};
private String[] java16 = {"sockets", "records"};

public ValueSelect() {
Handlebars handlebars = new Handlebars();
try {
template = handlebars.compileInline(handleBarTemplate);
} catch (IOException e) {
e.printStackTrace();
}
}

@GetMapping
public String start(Model model) {
model.addAttribute("now", new Date().toInstant());
return "value-select";
}

@GetMapping(value = "/models", produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String models(@RequestParam("make") String make) throws IOException {
if ("java8".equals(make))
return template.apply(java8);
if ("java9".equals(make))
return template.apply(java9);
if ("java10".equals(make))
return template.apply(java10);
if ("java11".equals(make))
return template.apply(java11);
if ("java12".equals(make))
return template.apply(java12);
if ("java13".equals(make))
return template.apply(java13);
if ("java14".equals(make))
return template.apply(java14);
if ("java15".equals(make))
return template.apply(java15);
if ("java16".equals(make))
return template.apply(java16);
throw new IllegalArgumentException("Unknown make");
}
}
55 changes: 0 additions & 55 deletions src/main/java/com/devhow/htmxdemo/demo/ValueSelect.java

This file was deleted.

Loading

0 comments on commit 8a15017

Please sign in to comment.