/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.service.app import net.piedpiper.bremer.model.api.BremerUser import net.piedpiper.bremer.service.domain.UserDomainService import org.springframework.beans.factory.annotation.Qualifier import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.core.userdetails.UsernameNotFoundException import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service("bremer.service.LoginAppService") class LoginAppService( private val passwordEncoder: PasswordEncoder, @Qualifier("bremer.dao.UserDomainService") private val userDomainService: UserDomainService ) : UserDetailsService { @Transactional override fun loadUserByUsername(name: String?): UserDetails? = name?.let { userDomainService.findUserByName(name)?.let { BremerUser(it) } } ?: throw UsernameNotFoundException("Login failed!") }