diff --git a/pom.xml b/pom.xml index 96bf85a..9358797 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,26 @@ spring-boot-starter-test test + + org.testcontainers + mysql + test + + + org.testcontainers + junit-jupiter + test + + + org.springframework.boot + spring-boot-testcontainers + + + org.springframework.security + spring-security-test + RELEASE + test + org.springframework.boot spring-boot-starter-data-jpa @@ -81,12 +101,7 @@ org.springframework.boot spring-boot-starter-validation - - org.springframework.session - spring-session-jdbc - - diff --git a/src/main/java/net/sytes/kashey/sweater/config/WebSecurityConfig.java b/src/main/java/net/sytes/kashey/sweater/config/WebSecurityConfig.java index c13c214..8335f76 100644 --- a/src/main/java/net/sytes/kashey/sweater/config/WebSecurityConfig.java +++ b/src/main/java/net/sytes/kashey/sweater/config/WebSecurityConfig.java @@ -2,7 +2,6 @@ package net.sytes.kashey.sweater.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -20,18 +19,19 @@ public class WebSecurityConfig { public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(8); } + @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests((requests) -> requests - .requestMatchers("/", "/registration","/static/**", "/activate/*").permitAll() + .requestMatchers("/", "/registration", "/static/**", "/activate/*").permitAll() .anyRequest().authenticated() ) .formLogin((form) -> form .loginPage("/login") .defaultSuccessUrl("/main", true) .permitAll() - ).rememberMe(Customizer.withDefaults()) + ) .logout(LogoutConfigurer::permitAll); return http.build(); diff --git a/src/main/java/net/sytes/kashey/sweater/domain/Message.java b/src/main/java/net/sytes/kashey/sweater/domain/Message.java index fd95fae..81b8510 100644 --- a/src/main/java/net/sytes/kashey/sweater/domain/Message.java +++ b/src/main/java/net/sytes/kashey/sweater/domain/Message.java @@ -7,7 +7,7 @@ import org.hibernate.validator.constraints.Length; @Entity public class Message { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotBlank(message = "Please fill in the field.") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f0eed7e..c873ed4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -19,6 +19,3 @@ spring.mail.protocol=smtps mail.debug=true recaptcha.secret= -spring.session.jdbc.serialize=java -spring.session.jdbc.initialize-schema=always -spring.session.jdbc.table-name=SPRING_SESSION diff --git a/src/main/resources/db/migration/V1__Init_DB.sql b/src/main/resources/db/migration/V1__Init_DB.sql index ce9f7ca..905bd21 100644 --- a/src/main/resources/db/migration/V1__Init_DB.sql +++ b/src/main/resources/db/migration/V1__Init_DB.sql @@ -1,48 +1,47 @@ -create table message +CREATE TABLE IF NOT EXISTS message ( - id bigint not null, - user_id bigint, - filename varchar(255), - tag varchar(255), - text varchar(2048) not null, - primary key (id) -) engine = InnoDB; + id BIGINT AUTO_INCREMENT PRIMARY KEY, + user_id BIGINT, + filename VARCHAR(255), + tag VARCHAR(255), + text VARCHAR(2048) NOT NULL +) ENGINE = InnoDB; -create table message_seq +CREATE TABLE message_seq ( - next_val bigint -) engine = InnoDB; + next_val BIGINT +) ENGINE = InnoDB; -insert into message_seq -values (1); +INSERT INTO message_seq +VALUES (1); -create table user_role +CREATE TABLE user_role ( - user_id bigint not null, - roles enum ('ADMIN','USER') -) engine = InnoDB; + user_id BIGINT NOT NULL, + roles ENUM ('ADMIN','USER') +) ENGINE = InnoDB; -create table usr +CREATE TABLE usr ( - enabled bit not null, - id bigint not null, - activation_code varchar(255), - email varchar(255), - password varchar(255) not null, - username varchar(255) not null, - primary key (id) -) engine = InnoDB; + enabled BIT NOT NULL, + id BIGINT NOT NULL, + activation_code VARCHAR(255), + email VARCHAR(255), + password VARCHAR(255) NOT NULL, + username VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +) ENGINE = InnoDB; -create table usr_seq +CREATE TABLE usr_seq ( - next_val bigint -) engine = InnoDB; + next_val BIGINT +) ENGINE = InnoDB; -insert into usr_seq -values (1); +INSERT INTO usr_seq +VALUES (1); -alter table message - add constraint message_user_fk foreign key (user_id) references usr (id); +ALTER TABLE message + ADD CONSTRAINT message_user_fk FOREIGN KEY (user_id) REFERENCES usr (id); -alter table user_role - add constraint user_role_user_fk foreign key (user_id) references usr (id); +ALTER TABLE user_role + ADD CONSTRAINT user_role_user_fk FOREIGN KEY (user_id) REFERENCES usr (id); diff --git a/src/main/resources/templates/main.ftl b/src/main/resources/templates/main.ftl index 500159a..809a3d1 100644 --- a/src/main/resources/templates/main.ftl +++ b/src/main/resources/templates/main.ftl @@ -1,9 +1,9 @@ <#import "parts/common.ftl" as com> <@com.page> - + - + Search diff --git a/src/main/resources/templates/parts/common.ftl b/src/main/resources/templates/parts/common.ftl index 4fb35ab..6abe296 100644 --- a/src/main/resources/templates/parts/common.ftl +++ b/src/main/resources/templates/parts/common.ftl @@ -4,9 +4,9 @@ Sweater - - - + + + diff --git a/src/main/resources/templates/parts/messageEditor.ftl b/src/main/resources/templates/parts/messageEditor.ftl index c3e0798..1bd7a1a 100644 --- a/src/main/resources/templates/parts/messageEditor.ftl +++ b/src/main/resources/templates/parts/messageEditor.ftl @@ -18,7 +18,7 @@ + value="<#if message??>${message.tag}#if>" name="tag" placeholder="Tag"/> <#if tagError??> ${tagError} @@ -27,7 +27,7 @@ - + Choose file diff --git a/src/main/resources/templates/parts/messageList.ftl b/src/main/resources/templates/parts/messageList.ftl index 5eeff32..e2359e3 100644 --- a/src/main/resources/templates/parts/messageList.ftl +++ b/src/main/resources/templates/parts/messageList.ftl @@ -1,14 +1,14 @@ <#include "security.ftl"> - + <#list messages as message> - + <#if message.filename??> #if> - ${message.text} + ${message.text} #${message.tag}