summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/security/TokenService.kt13
1 files 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!")
+ }
}
}