提交 968ce962 编写于 作者: 郝先瑞

feat: 用户注销接口

上级 1e4749bf
......@@ -59,12 +59,15 @@ public class SecurityUtils {
return String.valueOf(getTokenAttributes().get("jti"));
}
public static Long getExp() {
return Convert.toLong(getTokenAttributes().get("jti"));
}
public static Integer getDataScope() {
return Convert.toInt(getTokenAttributes().get("dataScope"));
}
public static Long getMemberId() {
return Convert.toLong(getTokenAttributes().get("memberId"));
}
}
......@@ -7,18 +7,15 @@ import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Swagger 配置
* <p>
* Spring Doc FAQ: https://springdoc.org/#faq
*
* @author haoxr
* @since 2023/2/17
* @since 3.0.0
*/
@Configuration
public class SwaggerConfig {
......
......@@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -265,11 +266,18 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
*/
@Override
public boolean logout() {
String jti = SecurityUtils.getJti();
Long expireTime = SecurityUtils.getExp(); // token 过期时间戳(秒)
return false;
long currentTime = System.currentTimeMillis() / 1000;// 当前时间(单位:秒)
if (expireTime != null) {
if (expireTime > currentTime) { // token未过期,添加至缓存作为黑名单限制访问,缓存时间为token过期剩余时间
redisTemplate.opsForValue().set(SecurityConstants.BLACKLIST_TOKEN_PREFIX + jti, null, (expireTime - currentTime), TimeUnit.SECONDS);
}
} else { // token 永不过期则永久加入黑名单(一般不会有)
redisTemplate.opsForValue().set(SecurityConstants.BLACKLIST_TOKEN_PREFIX + jti, null);
}
return true;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册