Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringWebFlux安全性允许除一个Url外的所有Url_Java_Spring_Spring Security_Spring Webflux - Fatal编程技术网

Java SpringWebFlux安全性允许除一个Url外的所有Url

Java SpringWebFlux安全性允许除一个Url外的所有Url,java,spring,spring-security,spring-webflux,Java,Spring,Spring Security,Spring Webflux,我想允许在特定控制器中定义除一个以外的所有URL 假设我的控制器公开了3个基本url/users “/”列出所有用户 “/{id}”按id列出用户 “/admin”获取用户的管理员级别详细信息 我想允许除最后一个用户外的任何用户访问1和2个URL 我一直在做这样的事情 @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { http.authorizeExchange

我想允许在特定控制器中定义除一个以外的所有URL

假设我的控制器公开了3个基本url
/users

  • “/”列出所有用户
  • “/{id}”按id列出用户
  • “/admin”获取用户的管理员级别详细信息
  • 我想允许除最后一个用户外的任何用户访问1和2个URL

    我一直在做这样的事情

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        http.authorizeExchange()
            .pathMatchers("/users/**")
            .permitAll()
            .pathMatchers("/users/admin")
            .hasRole("ADMIN")
            .anyExchange()
            .authenticated()
            .and()
            .httpBasic()
            .and()
            .formLogin();
        return http.build();
    }
    
    但它不起作用。我也试过相反的方法,即

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        http.authorizeExchange()
            .pathMatchers("/users/admin")
            .hasRole("ADMIN")
            .anyExchange()
            .authenticated()
            .pathMatchers("/users/**")
            .permitAll()
            .and()
            .httpBasic()
            .and()
            .formLogin();
        return http.build();
    }
    
    由于
    anyExchange()
    已经注册,因此无法联系到下一个
    路径匹配器

    我找到了解决方案。
    anyExchange()
    authenticated()
    导致问题
    anyExchange()
    不允许进一步添加任何路径匹配程序,而
    authenticated()
    正在使整个应用程序安全,从而导致每个url提示进行身份验证

    删除这两个选项是有效的

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        http.authorizeExchange()
            .pathMatchers("/users/admin/**")
            .hasRole("ADMIN")
            .pathMatchers("/**").permitAll()
            .and().httpBasic();
        return http.build();
    }