This commit is contained in:
Vladimir Voronin
2025-01-07 13:15:08 +03:00
parent 2506e6081f
commit 8b440ad9e8
45 changed files with 51 additions and 1048 deletions

View File

@@ -1,20 +0,0 @@
package space.luminic.budgerapp.configs
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import java.util.concurrent.Executor
//
//@Configuration
//class AsyncConfig {
// @Bean(name = ["taskExecutor"])
// fun taskExecutor(): Executor {
// val executor = ThreadPoolTaskExecutor()
// executor.corePoolSize = 5
// executor.maxPoolSize = 10
// executor.setQueueCapacity(25)
// executor.setThreadNamePrefix("Async-")
// executor.initialize()
// return executor
// }
//}

View File

@@ -1,18 +0,0 @@
package space.luminic.budgerapp.configs
import org.springframework.context.annotation.Configuration
import org.springframework.web.reactive.config.CorsRegistry
import org.springframework.web.reactive.config.WebFluxConfigurer
@Configuration
class CorsConfig : WebFluxConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**") // Разрешить все пути
.allowedOrigins("http://localhost:5173") // Разрешить домен localhost:5173
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH") // Разрешить методы
.allowedHeaders("*") // Разрешить все заголовки
.allowCredentials(true) // Разрешить передачу cookies
}
}

View File

@@ -1,44 +0,0 @@
//package space.luminic.budgerapp.configs
//import org.springframework.http.HttpHeaders
//import org.springframework.http.HttpStatus
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
//import org.springframework.security.core.context.SecurityContextHolder
//import org.springframework.stereotype.Component
//import org.springframework.web.server.ServerWebExchange
//import org.springframework.web.server.WebFilter
//import org.springframework.web.server.WebFilterChain
//import reactor.core.publisher.Mono
//import space.luminic.budgerapp.services.AuthService
//import space.luminic.budgerapp.services.TokenService
//import space.luminic.budgerapp.utils.JWTUtil
//
//@Component
//class JWTAuthFilter(
// private val jwtUtil: JWTUtil,
// private val authService: AuthService
//) : WebFilter {
//
// override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
// val authHeader = exchange.request.headers.getFirst(HttpHeaders.AUTHORIZATION)
//
// if (authHeader != null && authHeader.startsWith("Bearer ")) {
// val token = authHeader.substring(7)
// return Mono.just(token)
// .filter { authService.isTokenValid(it) }
// .flatMap { validToken ->
// val username = jwtUtil.validateToken(validToken)
// if (username != null) {
// val auth = UsernamePasswordAuthenticationToken(username, null, emptyList())
// SecurityContextHolder.getContext().authentication = auth
// }
// chain.filter(exchange)
// }
// .onErrorResume {
// exchange.response.statusCode = HttpStatus.UNAUTHORIZED
// exchange.response.setComplete()
// }
// }
//
// return chain.filter(exchange)
// }
//}

View File

@@ -1,33 +0,0 @@
//package space.luminic.budgerapp.configs
//
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
//import org.springframework.security.authentication.ReactiveAuthenticationManager
//import org.springframework.security.core.Authentication
//import org.springframework.security.core.userdetails.ReactiveUserDetailsService
//import org.springframework.security.crypto.password.PasswordEncoder
//import org.springframework.stereotype.Component
//import reactor.core.publisher.Mono
//import space.luminic.budgerapp.services.CustomReactiveUserDetailsService
//import space.luminic.budgerapp.services.TokenService
//import space.luminic.budgerapp.utils.JWTUtil
//
//@Component
//class JWTReactiveAuthenticationManager(
// private val passwordEncoder: PasswordEncoder,
// private val userDetailsService: CustomReactiveUserDetailsService
//) : ReactiveAuthenticationManager {
//
//
// override fun authenticate(authentication: Authentication): Mono<Authentication> {
// val username = authentication.principal as String
// val password = authentication.credentials as String
//
// return userDetailsService.findByUsername(username)
// .filter { userDetails -> password == passwordEncoder.encode(userDetails.password) } // Пример проверки пароля
// .map { userDetails ->
// UsernamePasswordAuthenticationToken(userDetails, null, userDetails.authorities)
// }
// }
//
//
//}

View File

@@ -1,5 +1,6 @@
package space.luminic.budgerapp.configs
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
@@ -8,20 +9,15 @@ import org.springframework.security.config.web.server.ServerHttpSecurity
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.web.server.SecurityWebFilterChain
import space.luminic.budgerapp.controllers.CustomAuthenticationEntryPoint
import space.luminic.budgerapp.services.AuthService
@Configuration
class SecurityConfig(
private val authService: AuthService
) {
@Bean
fun securityWebFilterChain(
http: ServerHttpSecurity,
bearerTokenFilter: BearerTokenFilter,
customAuthenticationEntryPoint: CustomAuthenticationEntryPoint
bearerTokenFilter: BearerTokenFilter
): SecurityWebFilterChain {
return http
.csrf { it.disable() }