Browse Source

优化gateway鉴权逻辑

test
smallchill 3 years ago
parent
commit
d8fa92845c
  1. 5
      blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java
  2. 18
      blade-gateway/src/main/java/org/springblade/gateway/props/AuthProperties.java
  3. 37
      blade-gateway/src/main/java/org/springblade/gateway/provider/AuthSecure.java
  4. 37
      blade-gateway/src/main/java/org/springblade/gateway/provider/BasicSecure.java
  5. 37
      blade-gateway/src/main/java/org/springblade/gateway/provider/SignSecure.java

5
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<Void> unAuth(ServerHttpResponse resp, String msg) {

18
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<String> skipUrl = new ArrayList<>();
/**
* 自定义授权配置
*/
private final List<AuthSecure> auth = new ArrayList<>();
/**
* 基础认证配置
*/
private final List<BasicSecure> basic = new ArrayList<>();
/**
* 签名认证配置
*/
private final List<SignSecure> sign = new ArrayList<>();
}

37
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;
}

37
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;
}

37
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;
}
Loading…
Cancel
Save