Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zlt2000
microservices-platform
提交
51b69faa
microservices-platform
项目概览
zlt2000
/
microservices-platform
8 个月 前同步成功
通知
16
Star
4
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
51b69faa
编写于
6月 10, 2022
作者:
Z
zhult13
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
自定义 ServerWebExchangeMatcher
上级
ff19ee3e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
0 deletion
+41
-0
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/CustomBearerTokenExtractor.java
...auth2/common/service/impl/CustomBearerTokenExtractor.java
+2
-0
zlt-gateway/sc-gateway/src/main/java/com/central/gateway/auth/CustomServerWebExchangeMatchers.java
...central/gateway/auth/CustomServerWebExchangeMatchers.java
+38
-0
zlt-gateway/sc-gateway/src/main/java/com/central/gateway/config/ResourceServerConfiguration.java
...m/central/gateway/config/ResourceServerConfiguration.java
+1
-0
未找到文件。
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/service/impl/CustomBearerTokenExtractor.java
浏览文件 @
51b69faa
package
com.central.oauth2.common.service.impl
;
import
com.central.oauth2.common.properties.SecurityProperties
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor
;
import
org.springframework.stereotype.Component
;
...
...
@@ -19,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@ConditionalOnClass
(
HttpServletRequest
.
class
)
@Component
public
class
CustomBearerTokenExtractor
extends
BearerTokenExtractor
{
@Resource
...
...
zlt-gateway/sc-gateway/src/main/java/com/central/gateway/auth/CustomServerWebExchangeMatchers.java
0 → 100644
浏览文件 @
51b69faa
package
com.central.gateway.auth
;
import
com.central.oauth2.common.properties.SecurityProperties
;
import
org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
/**
* 自定义 ServerWebExchangeMatcher
* 解决只要请求携带access_token,排除鉴权的url依然会被拦截
*
* @author zlt
* @version 1.0
* @date 2022/6/10
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
public
class
CustomServerWebExchangeMatchers
implements
ServerWebExchangeMatcher
{
private
final
SecurityProperties
securityProperties
;
private
final
AntPathMatcher
antPathMatcher
=
new
AntPathMatcher
();
public
CustomServerWebExchangeMatchers
(
SecurityProperties
securityProperties
)
{
this
.
securityProperties
=
securityProperties
;
}
@Override
public
Mono
<
MatchResult
>
matches
(
ServerWebExchange
exchange
)
{
for
(
String
url
:
securityProperties
.
getIgnore
().
getUrls
())
{
if
(
antPathMatcher
.
match
(
url
,
exchange
.
getRequest
().
getURI
().
getPath
()))
{
return
MatchResult
.
notMatch
();
}
}
return
MatchResult
.
match
();
}
}
zlt-gateway/sc-gateway/src/main/java/com/central/gateway/config/ResourceServerConfiguration.java
浏览文件 @
51b69faa
...
...
@@ -48,6 +48,7 @@ public class ResourceServerConfiguration {
oauth2Filter
.
setServerAuthenticationConverter
(
tokenAuthenticationConverter
);
oauth2Filter
.
setAuthenticationFailureHandler
(
new
ServerAuthenticationEntryPointFailureHandler
(
entryPoint
));
oauth2Filter
.
setAuthenticationSuccessHandler
(
new
Oauth2AuthSuccessHandler
());
oauth2Filter
.
setRequiresAuthenticationMatcher
(
new
CustomServerWebExchangeMatchers
(
securityProperties
));
http
.
addFilterAt
(
oauth2Filter
,
SecurityWebFiltersOrder
.
AUTHENTICATION
);
ServerHttpSecurity
.
AuthorizeExchangeSpec
authorizeExchange
=
http
.
authorizeExchange
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录