diff --git a/src/main/kotlin/org/meogo/global/auth/AuthDetails.kt b/src/main/kotlin/org/meogo/global/auth/AuthDetails.kt new file mode 100644 index 0000000..f9d7707 --- /dev/null +++ b/src/main/kotlin/org/meogo/global/auth/AuthDetails.kt @@ -0,0 +1,40 @@ +package org.meogo.global.auth + +import org.meogo.domain.user.domain.UserRole +import org.springframework.security.core.GrantedAuthority +import org.springframework.security.core.authority.SimpleGrantedAuthority +import org.springframework.security.core.userdetails.UserDetails + +class AuthDetails( + private val name: String, + private val role: UserRole +) : UserDetails { + + override fun getAuthorities(): Collection { + return listOf(SimpleGrantedAuthority("ROLE_" + role.name)) + } + + override fun getPassword(): String? { + return null + } + + override fun getUsername(): String { + return name + } + + override fun isAccountNonExpired(): Boolean { + return true + } + + override fun isAccountNonLocked(): Boolean { + return true + } + + override fun isCredentialsNonExpired(): Boolean { + return true + } + + override fun isEnabled(): Boolean { + return true + } +} diff --git a/src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt b/src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt new file mode 100644 index 0000000..3a357af --- /dev/null +++ b/src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt @@ -0,0 +1,16 @@ +package org.meogo.global.auth + +import org.meogo.domain.user.facade.UserFacade +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.security.core.userdetails.UserDetailsService +import org.springframework.stereotype.Component + +@Component +class AuthDetailsService( + private val userFacade: UserFacade +) : UserDetailsService { + override fun loadUserByUsername(username: String): UserDetails { + val user = userFacade.getUserByAccountId(username) + return AuthDetails(user.accountId, user.role) + } +}