/** * BladeX Commercial License Agreement * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. *
* Use of this software is governed by the Commercial License Agreement * obtained after purchasing a license from BladeX. *
* 1. This software is for development use only under a valid license * from BladeX. *
* 2. Redistribution of this software's source code to any third party * without a commercial license is strictly prohibited. *
* 3. Licensees may copyright their own code but cannot use segments * from this software for such purposes. Copyright of this software * remains with BladeX. *
* Using this software signifies agreement to this License, and the software * must not be used for illegal purposes. *
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is * not liable for any claims arising from secondary or illegal development. *
* Author: DreamLu (596392912@qq.com) */ package org.springblade.gateway.filter; import com.alibaba.nacos.common.utils.StringUtils; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.jwt.JwtUtil; import org.springblade.gateway.provider.AuthProvider; import org.springblade.gateway.provider.RequestProvider; import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; /** * webflux 日志请求记录,方便开发调试。请求日志过滤器排序尽量低。 * *
* 注意:暂时不支持结构体打印,想实现,请看下面的链接。 * https://stackoverflow.com/questions/45240005/how-to-log-request-and-response-bodies-in-spring-webflux * https://github.com/Silvmike/webflux-demo/blob/master/tests/src/test/java/ru/hardcoders/demo/webflux/web_handler/filters/logging *
* * @author dream.lu */ @Slf4j @Configuration(proxyBeanMethods = false) @RequiredArgsConstructor @ConditionalOnProperty(value = "blade.log.request.enabled", havingValue = "true", matchIfMissing = true) public class RequestLogFilter implements GlobalFilter, Ordered { private final WebEndpointProperties endpointProperties; @Override public Mono