package com.chantha.jdbc.security import org.springframework.beans.factory.annotation.Autowired import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.userdetails.UserDetails import org.springframework.stereotype.Component import org.springframework.stereotype.Controller import org.springframework.stereotype.Service class UserPrincipal constructor(private val user: User):UserDetails{ override fun getAuthorities(): List { val listGrantedAuthority= mutableListOf() user.getRolesList().map { val roles=SimpleGrantedAuthority("ROLE_$it") listGrantedAuthority.add(roles) } return listGrantedAuthority } override fun isEnabled(): Boolean { return user.status == 1 } override fun getUsername(): String { return user.userName } override fun isCredentialsNonExpired(): Boolean { return true } override fun getPassword(): String { return user.password } override fun isAccountNonExpired(): Boolean { return true } override fun isAccountNonLocked(): Boolean { return true } }