springcloud gateway2.0 websession ID

时间:2018-08-05 16:22:50

标签: java

在我的spring会话应用程序中,我使用springcloud网关2.0作为我的网关服务器,但是在后端服务上不使用webflux,它是springboot应用程序。现在,我想在春季会话中的后端应用程序设置属性之后在网关服务器上获取会话。我在春季会话redis服务器中发现websession的ID不等于httpsession的ID。

@EnableFeignClients
@SpringBootApplication
@EnableRedisWebSession
@Slf4j
public class WebGatewayApplication {

     private static final Logger logger = LoggerFactory.getLogger(WebGatewayApplication.class);

     public static void main(String[] args) {
        logger.info("Starting WebGatewayApplication ---------------------------------------");
        SpringApplication.run(WebGatewayApplication.class, args);
        logger.info("WebGatewayApplication started successed ------------------------------");
     }
}

@EnableDiscoveryClient
@SpringBootApplication
@EnableCircuitBreaker
@EnableRedisHttpSession
public class AdminApplication {

    private static final Logger logger = LoggerFactory.getLogger(AdminApplication.class);

    public static void main(String[] args) {
        logger.info("Starting AdminApplication =======================================");
        SpringApplication.run(AdminApplication.class, args);
        logger.info("AdminApplication started successed ==============================");
    }
}

@PostMapping("/pb/login")
public Response<Void> login(@RequestParam("loginName") String username, String password,
    HttpServletRequest request, HttpServletResponse resp) {
    Admin admin = .....
    HttpSession session = request.getSession();
    logger.debug("session id is {}",session.getId());
    request.getSession().setAttribute(GlobalConstant.SESSION_KEY, admin);
}

@Component
public class LoginFilter implements GlobalFilter, Ordered {

    private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class);


    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        Map<String, Object> attrs =  exchange.getSession().block().getAttributes();
        // attrs size is 0
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE;
    }
}

关于如何配置或修复此问题的任何想法?

0 个答案:

没有答案