-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6e4f01
commit 39fbfa0
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/main/kotlin/org/meogo/global/auth/AuthDetailsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |