基于url模式的不同规则在React式spring安全中的应用

ogsagwnx  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(199)

我有不同的端点组,比如api、登录和开放访问。
只想为登录端点触发oauth。401没有有效会话的api终结点出现错误。
我试图将多个securitywebfilterchain定义放入其中。但它不起作用。它为所有URL提供401。

@Bean
    @Order(1)
    public SecurityWebFilterChain openAccess(ServerHttpSecurity http) {
        http.authorizeExchange(
                exchanges ->
                        exchanges
                                .pathMatchers("/", "/ping", "/view/home", "/actuator/**")
                                .permitAll())
                .httpBasic()
                .disable()
                .formLogin()
                .disable()
                .csrf()
                .csrfTokenRepository(csrfTokenRepository());
        return http.build();
    }

    @Bean
    @Order(2)
    public SecurityWebFilterChain apiSecurity(ServerHttpSecurity http) {
        http.authorizeExchange(
                exchanges ->
                        exchanges
                                .pathMatchers("/api/user/")
                                .hasAuthority(
                                        PRODUCT
                                                .getAccessName()
                                                .toLowerCase()))
                .httpBasic()
                .disable()
                .formLogin()
                .disable()
                .csrf()
                .csrfTokenRepository(csrfTokenRepository());
        return http.build();
    }

    @Bean
    @Order(3)
    public SecurityWebFilterChain oauthAccess(ServerHttpSecurity http) {
        http.authorizeExchange(
                exchanges ->
                        exchanges
                                .pathMatchers("/kp/oauth2/**")
                                .permitAll()
                                .pathMatchers("/login")
                                .authenticated())
                .httpBasic()
                .disable()
                .formLogin()
                .disable()
                .csrf()
                .csrfTokenRepository(csrfTokenRepository())
                .and()
                .logout()
                .logoutUrl("/logout")
                .logoutSuccessHandler(
                        logoutSuccessHandler("/logout.com/logout?service=" + casServerUrl))
                .and()
                .oauth2Login();
        return http.build();
    }

以下是应用程序启动日志:https://gist.github.com/rajeevprasanna/122b4e42f048b2c07eb80f60cd423f34
当我输入url时http://localhost:8080/login 在浏览器中,它给出了一个401错误。希望它根据我的配置触发oauth流吗https://gist.github.com/rajeevprasanna/aa0d586fc86cbd31e103c5c3f8a3fc06
更新:我尝试修改代码并添加了securitymatcher。但是在oauth身份验证中遇到了不同的问题。在so上单独发布的问题:spring security未重定向到给定的oauth身份验证url

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题