From d8fa92845cf0d3229bb57ef41541b0e776d25335 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 27 Jun 2022 16:54:41 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96gateway=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/filter/AuthFilter.java | 5 ++- .../gateway/props/AuthProperties.java | 18 +++++++++ .../gateway/provider/AuthSecure.java | 37 +++++++++++++++++++ .../gateway/provider/BasicSecure.java | 37 +++++++++++++++++++ .../gateway/provider/SignSecure.java | 37 +++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 blade-gateway/src/main/java/org/springblade/gateway/provider/AuthSecure.java create mode 100644 blade-gateway/src/main/java/org/springblade/gateway/provider/BasicSecure.java create mode 100644 blade-gateway/src/main/java/org/springblade/gateway/provider/SignSecure.java diff --git a/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java b/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java index 90ca7c46..744ec4ad 100644 --- a/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java +++ b/blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java @@ -92,7 +92,10 @@ public class AuthFilter implements GlobalFilter, Ordered { private boolean isSkip(String path) { return AuthProvider.getDefaultSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path)) - || authProperties.getSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path)); + || authProperties.getSkipUrl().stream().anyMatch(pattern -> antPathMatcher.match(pattern, path)) + || authProperties.getAuth().stream().anyMatch(auth -> antPathMatcher.match(auth.getPattern(), path)) + || authProperties.getBasic().stream().anyMatch(basic -> antPathMatcher.match(basic.getPattern(), path)) + || authProperties.getSign().stream().anyMatch(sign -> antPathMatcher.match(sign.getPattern(), path)); } private Mono unAuth(ServerHttpResponse resp, String msg) { diff --git a/blade-gateway/src/main/java/org/springblade/gateway/props/AuthProperties.java b/blade-gateway/src/main/java/org/springblade/gateway/props/AuthProperties.java index efb8d54d..d76eb7dd 100644 --- a/blade-gateway/src/main/java/org/springblade/gateway/props/AuthProperties.java +++ b/blade-gateway/src/main/java/org/springblade/gateway/props/AuthProperties.java @@ -17,6 +17,9 @@ package org.springblade.gateway.props; import lombok.Data; +import org.springblade.gateway.provider.AuthSecure; +import org.springblade.gateway.provider.BasicSecure; +import org.springblade.gateway.provider.SignSecure; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; @@ -38,4 +41,19 @@ public class AuthProperties { */ private final List skipUrl = new ArrayList<>(); + /** + * 自定义授权配置 + */ + private final List auth = new ArrayList<>(); + + /** + * 基础认证配置 + */ + private final List basic = new ArrayList<>(); + + /** + * 签名认证配置 + */ + private final List sign = new ArrayList<>(); + } diff --git a/blade-gateway/src/main/java/org/springblade/gateway/provider/AuthSecure.java b/blade-gateway/src/main/java/org/springblade/gateway/provider/AuthSecure.java new file mode 100644 index 00000000..2e69987b --- /dev/null +++ b/blade-gateway/src/main/java/org/springblade/gateway/provider/AuthSecure.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang 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: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.gateway.provider; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 自定义授权规则 + * + * @author Chill + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AuthSecure { + /** + * 请求路径 + */ + private String pattern; + +} diff --git a/blade-gateway/src/main/java/org/springblade/gateway/provider/BasicSecure.java b/blade-gateway/src/main/java/org/springblade/gateway/provider/BasicSecure.java new file mode 100644 index 00000000..bbd62c26 --- /dev/null +++ b/blade-gateway/src/main/java/org/springblade/gateway/provider/BasicSecure.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang 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: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.gateway.provider; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 基础授权规则 + * + * @author Chill + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BasicSecure { + /** + * 请求路径 + */ + private String pattern; + +} diff --git a/blade-gateway/src/main/java/org/springblade/gateway/provider/SignSecure.java b/blade-gateway/src/main/java/org/springblade/gateway/provider/SignSecure.java new file mode 100644 index 00000000..14b2ff91 --- /dev/null +++ b/blade-gateway/src/main/java/org/springblade/gateway/provider/SignSecure.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang 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: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.gateway.provider; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 签名授权规则 + * + * @author Chill + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SignSecure { + /** + * 请求路径 + */ + private String pattern; + +}