поменял на ласт версию спринга

This commit is contained in:
Николай 2023-05-11 16:52:19 +04:00
parent 1317a2824d
commit b468a84b1a
16 changed files with 57 additions and 50 deletions

View File

@ -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'

View File

@ -12,3 +12,4 @@ public class PasswordEncoderConfiguration {
return new BCryptPasswordEncoder();
}
}

View File

@ -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");
}
}

View File

@ -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");
}

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -26,20 +26,18 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav" th:with="activeLink=${#request.requestURI}" sec:authorize="isAuthenticated()">
<a class="nav-link" href="/"
th:classappend="${#strings.equals(activeLink, '/')} ? 'active' : ''">Index</a>
<ul class="navbar-nav" sec:authorize="!isAuthenticated()">
<a class="nav-link" href="/login">Вход</a>
</ul>
<ul class="navbar-nav" sec:authorize="isAuthenticated()">
<a class="nav-link" href="/">Index</a>
<!--(login=${#authentication.name})-->
<a sec:authorize="hasRole('ROLE_ADMIN')" class="nav-link" th:href="@{/creatorAction(login=${#authentication.name})}"
th:classappend="${#strings.equals(activeLink, '/creatorAction')} ? 'active' : ''">CreatorAction</a>
<a sec:authorize="hasRole('ROLE_USER')" class="nav-link" th:href="@{/readerAction(readerLogin=${#authentication.name})}"
th:classappend="${#strings.equals(activeLink, '/readerAction')} ? 'active' : ''">ReaderAction</a>
<a class="nav-link" href="/manga"
th:classappend="${#strings.equals(activeLink, '/manga')} ? 'active' : ''">Catalog</a>
<a sec:authorize="hasRole('ROLE_ADMIN')" class="nav-link" href="/users"
th:classappend="${#strings.equals(activeLink, '/users')} ? 'active' : ''">Пользователи</a>
<a class="nav-link" href="/swagger-ui/index.html" target="_blank">Документация REST API</a>
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
<a class="nav-link" sec:authorize="hasRole('ROLE_ADMIN')" th:href="@{/creatorAction(login=${#authentication.name})}">CreatorAction</a>
<a class="nav-link" sec:authorize="hasRole('ROLE_USER')" th:href="@{/readerAction(readerLogin=${#authentication.name})}">ReaderAction</a>
<a sec:authorize="hasRole('ROLE_ADMIN')" class="nav-link" href="/users">Users</a>
<a class="nav-link" href="/manga">Catalog</a>
<a class="nav-link" href="/swagger-ui/index.html">Документация REST API</a>
<a class="nav-link" href="/h2-console/">Консоль H2</a>
<a class="nav-link" href="/logout">
Выход (<span th:text="${#authentication.name}"></span>)
</a>

View File

@ -5,6 +5,7 @@
<head>
</head>
<body>
<div layout:fragment="content_header" th:text="'Главная'"></div>
<div layout:fragment="content">
<div>It's works!</div>
<a href="123">ERROR</a>

View File

@ -27,4 +27,5 @@
</form>
</div>
</body>
</html>
</html>
<!DOCTYPE html>