/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer.service import net.piedpiper.bremer.dao.UserDao import net.piedpiper.bremer.model.BremerUser 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.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service("bremer.service.LoginService") class LoginService( @Qualifier("bremer.dao.UserDao") private val userDao: UserDao ) : UserDetailsService { @Transactional override fun loadUserByUsername(name: String?): UserDetails? = name?.let { userDao.findOneByName(name)?.let { BremerUser(it) } } ?: throw UsernameNotFoundException("Login failed!") }