mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 05:29:29 +08:00
Revert "refactor(gateway): 重写is-login方法,不用响应式,防止阻塞redisson线程"
This reverts commit a1afb45929
.
This commit is contained in:
parent
a1afb45929
commit
d742e0d84f
@ -1,14 +1,20 @@
|
||||
package io.metersphere.gateway.config;
|
||||
|
||||
import io.metersphere.commons.constants.SessionConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.session.data.redis.RedisSessionRepository;
|
||||
import org.springframework.web.server.session.HeaderWebSessionIdResolver;
|
||||
import org.springframework.web.server.session.WebSessionIdResolver;
|
||||
|
||||
@Configuration
|
||||
public class SessionConfig {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Bean
|
||||
public WebSessionIdResolver webSessionIdResolver() {
|
||||
HeaderWebSessionIdResolver sessionIdResolver = new HeaderWebSessionIdResolver();
|
||||
@ -16,5 +22,9 @@ public class SessionConfig {
|
||||
return sessionIdResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisSessionRepository redisSessionRepository() {
|
||||
return new RedisSessionRepository(redisTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,9 @@ import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.session.data.redis.RedisSessionRepository;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.WebSession;
|
||||
@ -49,14 +49,14 @@ public class LoginController {
|
||||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
private RedisSessionRepository redisSessionRepository;
|
||||
|
||||
@GetMapping(value = "/is-login")
|
||||
public Mono<ResultHolder> isLogin(@RequestHeader(name = SessionConstants.HEADER_TOKEN, required = false) String sessionId,
|
||||
@RequestHeader(name = SessionConstants.CSRF_TOKEN, required = false) String csrfToken) throws Exception {
|
||||
if (StringUtils.isNotBlank(sessionId) && StringUtils.isNotBlank(csrfToken)) {
|
||||
userLoginService.validateCsrfToken(sessionId, csrfToken);
|
||||
Object userFromSession = redisTemplate.opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user");
|
||||
Object userFromSession = redisSessionRepository.getSessionRedisOperations().opsForHash().get("spring:session:sessions:" + sessionId, "sessionAttr:user");
|
||||
if (userFromSession != null) {
|
||||
if (userFromSession instanceof User) {
|
||||
// 用户只有工作空间权限
|
||||
|
Loading…
Reference in New Issue
Block a user