diff --git a/build.gradle b/build.gradle index 647ba77..8a64a29 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.0.2' + id 'org.springframework.boot' version '2.6.3' id 'io.spring.dependency-management' version '1.1.0' } @@ -13,28 +13,50 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'com.h2database:h2:2.1.210' - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-devtools' implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' + implementation 'org.webjars:bootstrap:5.1.3' implementation 'org.webjars:jquery:3.6.0' implementation 'org.webjars:font-awesome:6.1.0' - implementation 'org.jetbrains:annotations:24.0.0' - implementation 'org.jetbrains:annotations:24.0.0' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.hibernate.validator:hibernate-validator' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'com.auth0:java-jwt:4.4.0' - implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' - annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' + + implementation 'org.hibernate.validator:hibernate-validator' + + implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' + +// implementation 'org.springframework.boot:spring-boot-starter-web' +// implementation 'org.springframework.boot:spring-boot-starter-data-jpa' +// implementation 'com.h2database:h2:2.1.210' +// implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' +// +// implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' +// implementation 'org.springframework.boot:spring-boot-devtools' +// implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' +// implementation 'org.webjars:bootstrap:5.1.3' +// implementation 'org.webjars:jquery:3.6.0' +// implementation 'org.webjars:font-awesome:6.1.0' +// +// implementation 'org.jetbrains:annotations:24.0.0' +// implementation 'org.jetbrains:annotations:24.0.0' +// implementation 'org.springframework.boot:spring-boot-starter-validation' +// implementation 'org.hibernate.validator:hibernate-validator' +// testImplementation 'org.springframework.boot:spring-boot-starter-test' +// +// implementation 'org.springframework.boot:spring-boot-starter-security' +// implementation 'com.auth0:java-jwt:4.4.0' +// implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' +// annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" } tasks.named('test') { diff --git a/src/main/java/ru/ulstu/is/sbapp/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/is/sbapp/configuration/SecurityConfiguration.java index fa19030..1249b84 100644 --- a/src/main/java/ru/ulstu/is/sbapp/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/is/sbapp/configuration/SecurityConfiguration.java @@ -2,33 +2,29 @@ package ru.ulstu.is.sbapp.configuration; 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.config.annotation.method.configuration.EnableMethodSecurity; +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.WebSecurityCustomizer; -import org.springframework.security.web.SecurityFilterChain; import ru.ulstu.is.sbapp.controllers.UserSignUpMvcController; import ru.ulstu.is.sbapp.database.model.UserRole; import ru.ulstu.is.sbapp.database.service.UserService; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @Configuration @EnableWebSecurity -@EnableMethodSecurity( - securedEnabled = true -) -public class SecurityConfiguration { +@EnableGlobalMethodSecurity(securedEnabled = true) +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); private static final String LOGIN_URL = "/login"; private final UserService userService; - public SecurityConfiguration(UserService userService) { this.userService = userService; createAdminOnStartup(); } - private void createAdminOnStartup() { final String admin = "admin"; if (userService.findByLogin(admin) == null) { @@ -36,32 +32,42 @@ public class SecurityConfiguration { userService.createUser(admin, admin, admin, UserRole.ADMIN); } } - - @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + @Override + protected void configure(HttpSecurity http) throws Exception { http.headers().frameOptions().sameOrigin().and() .cors().and() .csrf().disable() - .authorizeHttpRequests() - .requestMatchers(UserSignUpMvcController.SIGNUP_URL).permitAll() - .requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll() + .authorizeRequests() + .antMatchers(UserSignUpMvcController.SIGNUP_URL).permitAll() + .antMatchers(HttpMethod.GET, LOGIN_URL).permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage(LOGIN_URL).permitAll() - .defaultSuccessUrl("/artist", true) .and() .logout().permitAll(); - return http.userDetailsService(userService).build(); + } + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userService); + } + @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/**"); - } +// @Override +// public void configure(WebSecurity web) { +// web.ignoring() +// .antMatchers(HttpMethod.OPTIONS, "/**") +// .antMatchers("/**/*.{js,html,css,png}") +// .antMatchers("/swagger-ui/index.html") +// .antMatchers("/webjars/**") +// .antMatchers("/swagger-resources/**") +// .antMatchers("/v3/api-docs/**"); +// } } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumController.java index 1b92994..ffc99b1 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ru.ulstu.is.sbapp.configuration.WebConfiguration; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumMvcController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumMvcController.java index e3d1ed8..27c5ef9 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumMvcController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/AlbumMvcController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistController.java index 4e6d853..b2f2012 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.web.bind.annotation.*; import ru.ulstu.is.sbapp.configuration.WebConfiguration; import ru.ulstu.is.sbapp.database.service.ArtistService; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistMvcController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistMvcController.java index 364340b..b4c70ca 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistMvcController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/ArtistMvcController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/SongController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/SongController.java index 89f0074..a6c3024 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/SongController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/SongController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.web.bind.annotation.*; import ru.ulstu.is.sbapp.configuration.WebConfiguration; import ru.ulstu.is.sbapp.database.service.AlbumService; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/SongMvcController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/SongMvcController.java index 024f9af..a633001 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/SongMvcController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/SongMvcController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpDTO.java b/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpDTO.java index 78aa46f..9111922 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpDTO.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpDTO.java @@ -1,7 +1,7 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; public class UserSignUpDTO { @NotBlank diff --git a/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpMvcController.java b/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpMvcController.java index fb6d722..a09969f 100644 --- a/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpMvcController.java +++ b/src/main/java/ru/ulstu/is/sbapp/controllers/UserSignUpMvcController.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.controllers; -import jakarta.validation.Valid; +import javax.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; diff --git a/src/main/java/ru/ulstu/is/sbapp/database/model/Album.java b/src/main/java/ru/ulstu/is/sbapp/database/model/Album.java index 5c71a29..e40a77f 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/model/Album.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/model/Album.java @@ -1,7 +1,7 @@ package ru.ulstu.is.sbapp.database.model; import com.fasterxml.jackson.annotation.JsonManagedReference; -import jakarta.persistence.*; +import javax.persistence.*; import java.util.ArrayList; import java.util.Collections; @@ -12,12 +12,12 @@ import java.util.Objects; @Table(name = "albums") public class Album { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private Long id; private String albumName; @JsonManagedReference - @OneToMany(fetch = FetchType.EAGER, mappedBy = "album") + @OneToMany(cascade = CascadeType.MERGE, mappedBy = "album") private List songs; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) diff --git a/src/main/java/ru/ulstu/is/sbapp/database/model/Artist.java b/src/main/java/ru/ulstu/is/sbapp/database/model/Artist.java index 1d6668d..876d764 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/model/Artist.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/model/Artist.java @@ -1,7 +1,7 @@ package ru.ulstu.is.sbapp.database.model; import com.fasterxml.jackson.annotation.JsonBackReference; -import jakarta.persistence.*; +import javax.persistence.*; import java.util.ArrayList; import java.util.Collections; @@ -12,7 +12,7 @@ import java.util.Objects; @Table(name = "artists") public class Artist { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private Long id; private String artistName; private String genre; diff --git a/src/main/java/ru/ulstu/is/sbapp/database/model/Song.java b/src/main/java/ru/ulstu/is/sbapp/database/model/Song.java index ec94ee3..5e8984e 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/model/Song.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/model/Song.java @@ -1,9 +1,7 @@ package ru.ulstu.is.sbapp.database.model; import com.fasterxml.jackson.annotation.JsonBackReference; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; +import javax.persistence.*; import java.util.Objects; @@ -11,7 +9,7 @@ import java.util.Objects; @Table(name = "songs") public class Song { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue private Long id; private String songName; private Double duration; diff --git a/src/main/java/ru/ulstu/is/sbapp/database/model/User.java b/src/main/java/ru/ulstu/is/sbapp/database/model/User.java index e4cef53..b8b3aaa 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/model/User.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/model/User.java @@ -1,8 +1,8 @@ package ru.ulstu.is.sbapp.database.model; -import jakarta.persistence.*; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; +import javax.persistence.*; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; import java.util.Objects; @@ -10,7 +10,7 @@ import java.util.Objects; @Table(name = "users") public class User { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue private Long id; @Column(nullable = false, unique = true, length = 64) @NotBlank diff --git a/src/main/java/ru/ulstu/is/sbapp/database/service/UserService.java b/src/main/java/ru/ulstu/is/sbapp/database/service/UserService.java index 009c22a..e0e364c 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/service/UserService.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/service/UserService.java @@ -1,6 +1,6 @@ package ru.ulstu.is.sbapp.database.service; -import jakarta.validation.ValidationException; +import javax.validation.ValidationException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; diff --git a/src/main/java/ru/ulstu/is/sbapp/database/util/validation/ValidatorUtil.java b/src/main/java/ru/ulstu/is/sbapp/database/util/validation/ValidatorUtil.java index 8baf8d0..45bb039 100644 --- a/src/main/java/ru/ulstu/is/sbapp/database/util/validation/ValidatorUtil.java +++ b/src/main/java/ru/ulstu/is/sbapp/database/util/validation/ValidatorUtil.java @@ -1,9 +1,9 @@ package ru.ulstu.is.sbapp.database.util.validation; -import jakarta.validation.ConstraintViolation; -import jakarta.validation.Validation; -import jakarta.validation.Validator; -import jakarta.validation.ValidatorFactory; +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import org.springframework.stereotype.Component; import java.util.Set;