/* * Copyright (c) 2018-2028, DreamLu All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: DreamLu 卢春梦 (596392912@qq.com) */ package com.vci.ubcs.gateway.filter; import com.alibaba.nacos.common.utils.StringUtils; import com.vci.ubcs.gateway.provider.AuthProvider; import com.vci.ubcs.gateway.provider.RequestProvider; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.jwt.JwtUtil; 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 GlobalRequestLogFilter implements GlobalFilter, Ordered { private final WebEndpointProperties endpointProperties; @Override public Mono