Springboot安全过滤器混乱

问题描述 投票:0回答:1

我一直在关注如何使用 Springboot 设置安全性的教程。有人可以向我解释一下这条线的作用吗:

.oauth2ResourceServer((oauth2) -> oauth2
                .jwt(Customizer.withDefaults())
            )

它只是确保 Bearer 令牌是 JWT 格式吗?或者它是否真的联系Google(我用它来登录)来验证JWT令牌

它位于: @豆 public SecurityFilterChain filterChain(HttpSecurity http) 抛出异常 {

    http
        .authorizeHttpRequests(request -> request
                .requestMatchers("/api/secure/**")
                .authenticated()
                .anyRequest().permitAll())
        .oauth2ResourceServer((oauth2) -> oauth2
            .jwt(Customizer.withDefaults())
        )
        .sessionManagement((session) ->
                session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        )
        .cors(Customizer.withDefaults()
        );

    http.csrf(csrf->csrf.disable());
    return http.build();
}
spring-boot oauth
1个回答
0
投票

您需要了解的所有内容都可以在文档中找到有关OAuth 2.0资源服务器部分的配置和工作方式

作为简短的解释:

您告诉

spring-security
,您的资源服务器部分仅支持使用 oauth2ResourceServer()
DSL
jwt 令牌类型。另外
Customizer.withDefaults()
表示所有可以具有
jwt
的配置(如
decoder
),因此其中一个将作为默认配置。

您可以在上面的参考资料中找到有关其工作原理以及为何以这种方式工作的更多详细信息和深入理解。

© www.soinside.com 2019 - 2024. All rights reserved.