mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-23 19:41:12 +08:00
fix: DataCopy
This commit is contained in:
@@ -7,6 +7,7 @@ import kotlin.reflect.full.createInstance
|
|||||||
import kotlin.reflect.full.declaredMemberProperties
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
import kotlin.reflect.full.memberProperties
|
import kotlin.reflect.full.memberProperties
|
||||||
import kotlin.reflect.jvm.isAccessible
|
import kotlin.reflect.jvm.isAccessible
|
||||||
|
import kotlin.reflect.jvm.javaField
|
||||||
|
|
||||||
interface DataCopy {
|
interface DataCopy {
|
||||||
fun <T : Any> toAnotherObject(
|
fun <T : Any> toAnotherObject(
|
||||||
@@ -19,15 +20,21 @@ interface DataCopy {
|
|||||||
return try {
|
return try {
|
||||||
val vo = toClass.createInstance()
|
val vo = toClass.createInstance()
|
||||||
for (prop in toClass.declaredMemberProperties) {
|
for (prop in toClass.declaredMemberProperties) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val mutableProp = prop as? KMutableProperty1<Any, Any?> ?: continue
|
|
||||||
val value = when {
|
val value = when {
|
||||||
sourceProps.containsKey(prop.name) -> sourceProps[prop.name]
|
sourceProps.containsKey(prop.name) -> sourceProps[prop.name]
|
||||||
otherProperties.containsKey(prop.name) -> otherProperties[prop.name]
|
otherProperties.containsKey(prop.name) -> otherProperties[prop.name]
|
||||||
else -> continue
|
else -> continue
|
||||||
}
|
}
|
||||||
mutableProp.isAccessible = true
|
@Suppress("UNCHECKED_CAST")
|
||||||
mutableProp.set(vo, value)
|
val mutableProp = prop as? KMutableProperty1<Any, Any?>
|
||||||
|
if (mutableProp != null) {
|
||||||
|
mutableProp.isAccessible = true
|
||||||
|
mutableProp.set(vo, value)
|
||||||
|
} else {
|
||||||
|
val field = prop.javaField ?: continue
|
||||||
|
field.isAccessible = true
|
||||||
|
field.set(vo, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vo
|
vo
|
||||||
} catch (e: ReflectiveOperationException) {
|
} catch (e: ReflectiveOperationException) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class JwtUtils(
|
|||||||
private val algorithm: Algorithm = Algorithm.HMAC256(key)
|
private val algorithm: Algorithm = Algorithm.HMAC256(key)
|
||||||
private val jwtVerifier: JWTVerifier = JWT.require(algorithm).build()
|
private val jwtVerifier: JWTVerifier = JWT.require(algorithm).build()
|
||||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||||
|
|
||||||
fun invalidateJwt(headerToken: String?): Boolean {
|
fun invalidateJwt(headerToken: String?): Boolean {
|
||||||
val token = this.convertToToken(headerToken) ?: return false
|
val token = this.convertToToken(headerToken) ?: return false
|
||||||
try {
|
try {
|
||||||
@@ -59,10 +59,10 @@ class JwtUtils(
|
|||||||
val decodedJWT = jwtVerifier.verify(token)
|
val decodedJWT = jwtVerifier.verify(token)
|
||||||
if (this.isInvalidToken(decodedJWT.id)) return null
|
if (this.isInvalidToken(decodedJWT.id)) return null
|
||||||
val expiresAt = decodedJWT.expiresAt
|
val expiresAt = decodedJWT.expiresAt
|
||||||
|
|
||||||
return if (Date().after(expiresAt)) null
|
return if (Date().after(expiresAt)) null
|
||||||
else decodedJWT
|
else decodedJWT
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.error("Error occurred while resolving JWT", e)
|
logger.error("Error occurred while resolving JWT", e)
|
||||||
return null
|
return null
|
||||||
@@ -104,6 +104,8 @@ class JwtUtils(
|
|||||||
return cal.time
|
return cal.time
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertToToken(headerToken: String?): String? =
|
fun convertToToken(headerToken: String?): String? {
|
||||||
headerToken?.replace("Bearer ", "")
|
val token = headerToken?.replace("Bearer ", "")?.trim()
|
||||||
|
return token?.takeIf { it.isNotEmpty() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user