diff --git a/build.gradle b/build.gradle index d8b52e0..ffce2b7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '2.6.3' + id 'org.springframework.boot' version '3.0.2' id 'io.spring.dependency-management' version '1.1.0' } @@ -28,7 +28,7 @@ dependencies { implementation 'com.h2database:h2:2.1.210' implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' implementation 'org.hibernate.validator:hibernate-validator' implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' diff --git a/src/main/java/com/LabWork/app/MangaStore/configuration/PasswordEncoderConfiguration.java b/src/main/java/com/LabWork/app/MangaStore/configuration/PasswordEncoderConfiguration.java index efc266f..962134d 100644 --- a/src/main/java/com/LabWork/app/MangaStore/configuration/PasswordEncoderConfiguration.java +++ b/src/main/java/com/LabWork/app/MangaStore/configuration/PasswordEncoderConfiguration.java @@ -12,3 +12,4 @@ public class PasswordEncoderConfiguration { return new BCryptPasswordEncoder(); } } + diff --git a/src/main/java/com/LabWork/app/MangaStore/configuration/SecurityConfiguration.java b/src/main/java/com/LabWork/app/MangaStore/configuration/SecurityConfiguration.java index 1a8f887..917e663 100644 --- a/src/main/java/com/LabWork/app/MangaStore/configuration/SecurityConfiguration.java +++ b/src/main/java/com/LabWork/app/MangaStore/configuration/SecurityConfiguration.java @@ -5,19 +5,21 @@ import com.LabWork.app.MangaStore.model.Default.UserRole; import com.LabWork.app.MangaStore.service.UserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 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.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; +import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(securedEnabled = true) -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { +public class SecurityConfiguration { private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); private static final String LOGIN_URL = "/login"; private final UserService userService; @@ -35,33 +37,38 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { } } - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.headers().frameOptions().sameOrigin().and() .cors().and() .csrf().disable() - .authorizeRequests() - .antMatchers(UserSignupMvcController.SIGNUP_URL).permitAll() - .antMatchers(HttpMethod.GET, LOGIN_URL).permitAll() + .authorizeHttpRequests() + .requestMatchers(UserSignupMvcController.SIGNUP_URL).permitAll() + .requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage(LOGIN_URL).permitAll() .and() .logout().permitAll(); + return http.build(); } - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userService); + @Bean + public AuthenticationManager authenticationManagerBean(HttpSecurity http) throws Exception { + AuthenticationManagerBuilder authenticationManagerBuilder = http + .getSharedObject(AuthenticationManagerBuilder.class); + authenticationManagerBuilder.userDetailsService(userService); + return authenticationManagerBuilder.build(); } - @Override - public void configure(WebSecurity web) { - web.ignoring() - .antMatchers("/css/**") - .antMatchers("/js/**") - .antMatchers("/templates/**") - .antMatchers("/webjars/**"); + @Bean + public WebSecurityCustomizer webSecurityCustomizer() { + return web -> web.ignoring() + .requestMatchers("/css/**") + .requestMatchers("/js/**") + .requestMatchers("/templates/**") + .requestMatchers("/webjars/**") + .requestMatchers("/vk.jpg"); } } \ No newline at end of file diff --git a/src/main/java/com/LabWork/app/MangaStore/configuration/WebConfiguration.java b/src/main/java/com/LabWork/app/MangaStore/configuration/WebConfiguration.java index 51c8f97..81cd971 100644 --- a/src/main/java/com/LabWork/app/MangaStore/configuration/WebConfiguration.java +++ b/src/main/java/com/LabWork/app/MangaStore/configuration/WebConfiguration.java @@ -11,7 +11,6 @@ public class WebConfiguration implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { WebMvcConfigurer.super.addViewControllers(registry); - registry.addViewController("rest-test"); registry.addViewController("login"); } diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java b/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java index e97f346..e1a1687 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/Creator/CreatorActionMvcController.java @@ -4,7 +4,7 @@ import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; import com.LabWork.app.MangaStore.service.CreatorService; import com.LabWork.app.MangaStore.service.MangaService; -import javax.validation.Valid; +import jakarta.validation.Valid; import com.LabWork.app.MangaStore.model.Default.UserRole; import org.slf4j.Logger; diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java b/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java index fdd878e..04336fb 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/Reader/ReaderActionMvcController.java @@ -5,7 +5,7 @@ import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; import com.LabWork.app.MangaStore.service.ReaderService; import com.LabWork.app.MangaStore.service.MangaService; -import javax.validation.Valid; +import jakarta.validation.Valid; import com.LabWork.app.MangaStore.model.Default.UserRole; import org.slf4j.Logger; diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/User/UserSignupMvcController.java b/src/main/java/com/LabWork/app/MangaStore/controller/User/UserSignupMvcController.java index 0ab73f1..a7ca852 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/User/UserSignupMvcController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/User/UserSignupMvcController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; +import jakarta.validation.Valid; @Controller @RequestMapping(UserSignupMvcController.SIGNUP_URL) diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Default/Creator.java b/src/main/java/com/LabWork/app/MangaStore/model/Default/Creator.java index fc67bc8..ded996b 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Default/Creator.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Default/Creator.java @@ -1,6 +1,6 @@ package com.LabWork.app.MangaStore.model.Default; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java b/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java index 2b867b7..46e20fc 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java @@ -3,7 +3,7 @@ package com.LabWork.app.MangaStore.model.Default; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; import com.LabWork.app.MangaStore.service.CreatorService; import com.LabWork.app.MangaStore.service.MangaService; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Default/Reader.java b/src/main/java/com/LabWork/app/MangaStore/model/Default/Reader.java index 33cb70d..0aecd76 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Default/Reader.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Default/Reader.java @@ -1,6 +1,6 @@ package com.LabWork.app.MangaStore.model.Default; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Default/User.java b/src/main/java/com/LabWork/app/MangaStore/model/Default/User.java index 39ecef9..975e5e8 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Default/User.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Default/User.java @@ -1,8 +1,8 @@ package com.LabWork.app.MangaStore.model.Default; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; import java.util.Objects; @Entity diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/UserSignupDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/UserSignupDto.java index 6eed90d..f73439e 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Dto/UserSignupDto.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/UserSignupDto.java @@ -2,8 +2,8 @@ package com.LabWork.app.MangaStore.model.Dto; import com.LabWork.app.MangaStore.model.Default.UserRole; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; public class UserSignupDto { @NotBlank diff --git a/src/main/java/com/LabWork/app/MangaStore/util/validation/ValidatorUtil.java b/src/main/java/com/LabWork/app/MangaStore/util/validation/ValidatorUtil.java index edb2105..91242a5 100644 --- a/src/main/java/com/LabWork/app/MangaStore/util/validation/ValidatorUtil.java +++ b/src/main/java/com/LabWork/app/MangaStore/util/validation/ValidatorUtil.java @@ -2,10 +2,10 @@ package com.LabWork.app.MangaStore.util.validation; import org.springframework.stereotype.Component; -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; import java.util.Set; import java.util.stream.Collectors; diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 1a15471..94a1b32 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -26,20 +26,18 @@