Multiple bug fixes #23

Merged
william merged 7 commits from develop into master 2021-12-23 21:13:29 -05:00
4 changed files with 25 additions and 10 deletions
Showing only changes of commit b18ed35571 - Show all commits

View File

@ -41,6 +41,7 @@ class JwtAuthenticationFilter(
override fun attemptAuthentication(request: HttpServletRequest, response: HttpServletResponse): Authentication {
val loginRequest = jacksonObjectMapper().readValue(request.inputStream, UserLoginRequest::class.java)
logger.debug("Login attempt for user ${loginRequest.id}...")
return authManager.authenticate(UsernamePasswordAuthenticationToken(loginRequest.id, loginRequest.password))
}
@ -53,6 +54,10 @@ class JwtAuthenticationFilter(
val userDetails = auth.principal as UserDetails
val token = jwtService.buildJwt(userDetails)
with(userDetails.user) {
logger.info("User ${this.id} (${this.firstName} ${this.lastName}) has logged in successfully")
}
response.addHeader("Access-Control-Expose-Headers", authorizationCookieName)
response.addHeader(authorizationCookieName, "Bearer $token")
response.addCookie(authorizationCookieName, "Bearer$token") {

View File

@ -7,6 +7,8 @@ import dev.fyloz.colorrecipesexplorer.model.account.User
import dev.fyloz.colorrecipesexplorer.service.users.JwtService
import dev.fyloz.colorrecipesexplorer.service.users.UserDetailsService
import dev.fyloz.colorrecipesexplorer.service.users.UserService
import mu.KLogger
import mu.KotlinLogging
import org.slf4j.Logger
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
@ -39,9 +41,10 @@ abstract class BaseSecurityConfig(
private val userDetailsService: UserDetailsService,
private val jwtService: JwtService,
private val environment: Environment,
protected val logger: Logger,
protected val securityProperties: CreSecurityProperties
) : WebSecurityConfigurerAdapter() {
protected abstract val logger: Logger
protected val passwordEncoder = BCryptPasswordEncoder()
var debugMode = false
@ -119,9 +122,10 @@ class SecurityConfig(
@Lazy private val userService: UserService,
jwtService: JwtService,
environment: Environment,
logger: Logger,
securityProperties: CreSecurityProperties
) : BaseSecurityConfig(userDetailsService, jwtService, environment, logger, securityProperties) {
) : BaseSecurityConfig(userDetailsService, jwtService, environment, securityProperties) {
override val logger = KotlinLogging.logger {}
@PostConstruct
fun initWebSecurity() {
if (emergencyMode) {
@ -165,9 +169,10 @@ class EmergencySecurityConfig(
userDetailsService: UserDetailsService,
jwtService: JwtService,
environment: Environment,
logger: Logger,
securityProperties: CreSecurityProperties
) : BaseSecurityConfig(userDetailsService, jwtService, environment, logger, securityProperties) {
) : BaseSecurityConfig(userDetailsService, jwtService, environment, securityProperties) {
override val logger = KotlinLogging.logger {}
init {
emergencyMode = true
}

View File

@ -5,6 +5,7 @@ import dev.fyloz.colorrecipesexplorer.config.annotations.PreAuthorizeViewUsers
import dev.fyloz.colorrecipesexplorer.model.account.*
import dev.fyloz.colorrecipesexplorer.service.users.GroupService
import dev.fyloz.colorrecipesexplorer.service.users.UserService
import mu.KotlinLogging
import org.springframework.context.annotation.Profile
import org.springframework.http.MediaType
import org.springframework.security.access.prepost.PreAuthorize

View File

@ -1,7 +1,7 @@
package dev.fyloz.colorrecipesexplorer.service.jobs
import dev.fyloz.colorrecipesexplorer.service.TouchUpKitService
import org.slf4j.Logger
import mu.KotlinLogging
import org.springframework.context.annotation.Profile
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
@ -9,18 +9,22 @@ import org.springframework.stereotype.Component
@Component
@Profile("!emergency")
class TouchUpKitRemover(
private val touchUpKitService: TouchUpKitService,
private val logger: Logger
private val touchUpKitService: TouchUpKitService
) {
private val logger = KotlinLogging.logger {}
@Scheduled(cron = "0 0 0 * * *")
fun execute() {
logger.debug("Executing expired touch up kits removal job... ")
removeExpiredKits()
}
private fun removeExpiredKits() {
logger.info("Removing expired touch up kits...")
with(touchUpKitService.getAll().filter(touchUpKitService::isExpired)) {
this.forEach(touchUpKitService::delete)
this.forEach {
logger.debug("Removed expired touch up kit ${it.id} (${it.project} ${it.buggy})")
touchUpKitService.delete(it)
}
logger.info("Removed ${this.size} expired touch up kits")
}
}