To tentando subir o projeto, mas um erro de construtor vazio ta me impedindo de prosseguir.
package com.group.solution.config
import com.group.solution.security.JWTAuthenticationFilter
import com.group.solution.security.JWTLoginFilter
import com.group.solution.security.JWTUtil
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.authentication.configuration.AuthenticationConfiguration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
@Configuration
@EnableWebSecurity
class SecurityConfiguration (
private val configuration: AuthenticationConfiguration,
private val userDetailsService: UserDetailsService,
private val jwtUtil: JWTUtil,
val constant: String = "/users"
) {
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http.csrf { it.disable() }
.authorizeHttpRequests { auth ->
auth
.requestMatchers("/h2-console/**").permitAll()
.requestMatchers(HttpMethod.POST, "/login").permitAll()
.requestMatchers(HttpMethod.POST, constant).permitAll()
.requestMatchers(HttpMethod.DELETE, constant).hasRole("ADMIN")
.requestMatchers(HttpMethod.GET, constant).hasRole("ADMIN")
.requestMatchers(HttpMethod.PUT, constant).hasAnyRole("ADMIN", "USER")
.anyRequest().authenticated()
}
.addFilterBefore(
JWTLoginFilter(
authenticationManager = configuration.authenticationManager,
jwtUtil = jwtUtil
), UsernamePasswordAuthenticationFilter().javaClass
)
.addFilterBefore(
JWTAuthenticationFilter(jwtUtil = jwtUtil),
UsernamePasswordAuthenticationFilter::class.java
)
.headers { headers ->
headers.frameOptions().disable()
}
.sessionManagement {
it.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
}
return http.build()
}
@Bean
fun encoder(): PasswordEncoder = BCryptPasswordEncoder()
fun configure(auth: AuthenticationManagerBuilder?) {
auth?.userDetailsService(userDetailsService)?.passwordEncoder(encoder())
}
}
erro: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration' defined in file [C:\Users\BRAGA\Desktop\Sales-system\solution\core\target\classes\com\group\solution\config\SecurityConfiguration.class]: Failed to instantiate [com.group.solution.config.SecurityConfiguration$$SpringCGLIB$$0]: No default constructor found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.12.jar:6.1.12]