Finish authentication

This commit is contained in:
2023-10-06 14:52:03 +08:00
parent 79e65f0785
commit 03534e4fa9
14 changed files with 121 additions and 33 deletions

View File

@@ -1,14 +0,0 @@
package top.fatweb.api.entity.converter
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings
import top.fatweb.api.entity.param.LoginParam
import top.fatweb.api.entity.permission.User
@Mapper(componentModel = "spring")
interface UserConverter {
@Mappings(Mapping(source = "username", target = "username"), Mapping(source = "password", target = "password"))
fun loginParamToUser(loginParam: LoginParam): User
}

View File

@@ -1,16 +0,0 @@
package top.fatweb.api.entity.param
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotBlank
import java.io.Serializable
class LoginParam : Serializable {
@Schema(description = "用户名", example = "test", required = true)
@NotBlank(message = "Username can not be blank")
val username: String? = null
@Schema(description = "密码", example = "test123456", required = true)
@NotBlank(message = "Password can not be blank")
val password: String? = null
}

View File

@@ -1,9 +1,11 @@
package top.fatweb.api.entity.permission
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonTypeInfo
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
class LoginUser() : UserDetails {
lateinit var user: User
@@ -22,15 +24,21 @@ class LoginUser() : UserDetails {
return authorities as List<GrantedAuthority>
}
@JsonIgnore
override fun getPassword(): String? = user.password
@JsonIgnore
override fun getUsername(): String? = user.username
@JsonIgnore
override fun isAccountNonExpired(): Boolean = true
@JsonIgnore
override fun isAccountNonLocked(): Boolean = true
@JsonIgnore
override fun isCredentialsNonExpired(): Boolean = true
@JsonIgnore
override fun isEnabled(): Boolean = user.enable == 1
}