Refactor:1; Fix:2; Feat:1 #15
@@ -38,7 +38,7 @@ class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRe
|
|||||||
val token = WebUtil.getToken(tokenWithPrefix)
|
val token = WebUtil.getToken(tokenWithPrefix)
|
||||||
JwtUtil.parseJwt(token)
|
JwtUtil.parseJwt(token)
|
||||||
|
|
||||||
val redisKeyPattern = "${SecurityProperties.jwtIssuer}_login_*:" + token
|
val redisKeyPattern = "${SecurityProperties.jwtIssuer}_login_*:${token}"
|
||||||
val redisKeys = redisUtil.keys(redisKeyPattern)
|
val redisKeys = redisUtil.keys(redisKeyPattern)
|
||||||
if (redisKeys.isEmpty()) {
|
if (redisKeys.isEmpty()) {
|
||||||
throw TokenHasExpiredException()
|
throw TokenHasExpiredException()
|
||||||
|
|||||||
@@ -264,19 +264,19 @@ class AuthenticationServiceImpl(
|
|||||||
override fun logout(token: String): Boolean {
|
override fun logout(token: String): Boolean {
|
||||||
val loginUser = WebUtil.getLoginUser() ?: throw TokenHasExpiredException()
|
val loginUser = WebUtil.getLoginUser() ?: throw TokenHasExpiredException()
|
||||||
|
|
||||||
return redisUtil.delObject("${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token)
|
return redisUtil.delObject("${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:${token}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renewToken(token: String): TokenVo {
|
override fun renewToken(token: String): TokenVo {
|
||||||
val loginUser = WebUtil.getLoginUser() ?: throw TokenHasExpiredException()
|
val loginUser = WebUtil.getLoginUser() ?: throw TokenHasExpiredException()
|
||||||
|
|
||||||
val oldRedisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token
|
val oldRedisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:${token}"
|
||||||
redisUtil.delObject(oldRedisKey)
|
redisUtil.delObject(oldRedisKey)
|
||||||
val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString())
|
val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString())
|
||||||
|
|
||||||
jwt ?: throw RuntimeException("Login failed")
|
jwt ?: throw RuntimeException("Login failed")
|
||||||
|
|
||||||
val redisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + jwt
|
val redisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:${jwt}"
|
||||||
redisUtil.setObject(
|
redisUtil.setObject(
|
||||||
redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit
|
redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit
|
||||||
)
|
)
|
||||||
@@ -390,7 +390,7 @@ class AuthenticationServiceImpl(
|
|||||||
|
|
||||||
jwt ?: throw RuntimeException("Login failed")
|
jwt ?: throw RuntimeException("Login failed")
|
||||||
|
|
||||||
val redisKey = "${SecurityProperties.jwtIssuer}_login_${userId}:" + jwt
|
val redisKey = "${SecurityProperties.jwtIssuer}_login_${userId}:${jwt}"
|
||||||
redisUtil.setObject(redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit)
|
redisUtil.setObject(redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit)
|
||||||
|
|
||||||
return LoginVo(jwt, loginUser.user.id, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp)
|
return LoginVo(jwt, loginUser.user.id, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp)
|
||||||
|
|||||||
Reference in New Issue
Block a user