generated from pricelees/issue-pr-template
feat: 로그인 이력을 관리하는 별도 서비스 정의
This commit is contained in:
parent
797ee2c0d0
commit
66ae7d7beb
@ -0,0 +1,60 @@
|
|||||||
|
package roomescape.auth.business
|
||||||
|
|
||||||
|
import com.github.f4b6a3.tsid.TsidFactory
|
||||||
|
import io.github.oshai.kotlinlogging.KLogger
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Propagation
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import roomescape.auth.infrastructure.persistence.LoginHistoryEntity
|
||||||
|
import roomescape.auth.infrastructure.persistence.LoginHistoryRepository
|
||||||
|
import roomescape.auth.web.LoginContext
|
||||||
|
import roomescape.common.config.next
|
||||||
|
import roomescape.common.dto.PrincipalType
|
||||||
|
|
||||||
|
private val log: KLogger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class LoginHistoryService(
|
||||||
|
private val loginHistoryRepository: LoginHistoryRepository,
|
||||||
|
private val tsidFactory: TsidFactory,
|
||||||
|
) {
|
||||||
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
|
fun createSuccessHistory(
|
||||||
|
principalId: Long,
|
||||||
|
principalType: PrincipalType,
|
||||||
|
context: LoginContext
|
||||||
|
) {
|
||||||
|
createHistory(principalId, principalType, success = true, context = context)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
|
fun createFailureHistory(
|
||||||
|
principalId: Long,
|
||||||
|
principalType: PrincipalType,
|
||||||
|
context: LoginContext
|
||||||
|
) {
|
||||||
|
createHistory(principalId, principalType, success = false, context = context)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createHistory(
|
||||||
|
principalId: Long,
|
||||||
|
principalType: PrincipalType,
|
||||||
|
success: Boolean,
|
||||||
|
context: LoginContext
|
||||||
|
) {
|
||||||
|
log.info { "[LoginHistoryService.createHistory] 로그인 이력 저장 시작: id=${principalId}, type=${principalType}, success=${success}" }
|
||||||
|
|
||||||
|
LoginHistoryEntity(
|
||||||
|
id = tsidFactory.next(),
|
||||||
|
principalId = principalId,
|
||||||
|
principalType = principalType,
|
||||||
|
success = success,
|
||||||
|
ipAddress = context.ipAddress,
|
||||||
|
userAgent = context.userAgent,
|
||||||
|
).also {
|
||||||
|
loginHistoryRepository.save(it)
|
||||||
|
log.info { "[LoginHistoryService.createHistory] 로그인 이력 저장 완료: principalId=${principalId}, historyId=${it.id}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user