From 48f6124e2cc27476dba8ebfb398c1b4ad8875164 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 10 Mar 2026 08:15:49 +0100 Subject: fix: ignore token users with existing username (#257) This will ignore token usernames with the same username as an existing user.--- .../kotlin/dev/dnpm/etl/processor/security/TokenService.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/security/TokenService.kt b/src/main/kotlin/dev/dnpm/etl/processor/security/TokenService.kt index fdaa7d2..fd75446 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/security/TokenService.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/security/TokenService.kt @@ -20,6 +20,7 @@ package dev.dnpm.etl.processor.security import jakarta.annotation.PostConstruct +import org.slf4j.LoggerFactory import java.time.Instant import java.util.* import org.springframework.data.annotation.Id @@ -36,12 +37,18 @@ class TokenService( private val tokenRepository: TokenRepository, ) { + private val logger = LoggerFactory.getLogger(TokenService::class.java) + @PostConstruct fun setup() { tokenRepository.findAll().forEach { - userDetailsManager.createUser( - User.withUsername(it.username).password(it.password).roles("MTBFILE").build() - ) + if (!userDetailsManager.userExists(it.username)) { + userDetailsManager.createUser( + User.withUsername(it.username).password(it.password).roles("MTBFILE").build() + ) + } else { + logger.error("User ${it.username} already exists - cannot use token - skipping!") + } } } -- cgit v1.2.3