refactor: 网关过滤器apikey放行
This commit is contained in:
parent
99b4713134
commit
c391cc57e4
|
@ -1,8 +1,11 @@
|
|||
package io.metersphere.gateway.filter;
|
||||
|
||||
import io.metersphere.commons.utils.FilterChainUtils;
|
||||
import io.metersphere.security.ApiKeyHandler;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springdoc.core.properties.SwaggerUiConfigProperties;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
@ -46,9 +49,22 @@ public class LoginFilter implements WebFilter, Ordered {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public static Boolean isApiKeyCall(ServerHttpRequest request) {
|
||||
if (request == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return StringUtils.isNotBlank(request.getHeaders().getFirst(ApiKeyHandler.API_ACCESS_KEY))
|
||||
&& StringUtils.isNotBlank(request.getHeaders().getFirst(ApiKeyHandler.API_SIGNATURE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(final ServerWebExchange serverWebExchange, final WebFilterChain webFilterChain) {
|
||||
ServerHttpRequest request = serverWebExchange.getRequest();
|
||||
if (isApiKeyCall(request)) {
|
||||
return webFilterChain.filter(serverWebExchange);
|
||||
}
|
||||
|
||||
if (basePattern.matches(request.getPath().pathWithinApplication())
|
||||
&& !excludePatterns.stream()
|
||||
|
|
Loading…
Reference in New Issue