Skip to content

Commit

Permalink
add :: auth
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Sep 2, 2024
1 parent f6e4f01 commit 39fbfa0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/kotlin/org/meogo/global/auth/AuthDetails.kt
Original file line number Diff line number Diff line change
@@ -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<GrantedAuthority?> {
return listOf<SimpleGrantedAuthority>(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
}
}
16 changes: 16 additions & 0 deletions src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 39fbfa0

Please sign in to comment.