Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Spring boot Spring引导安全性允许来自给定IP地址的请求_Spring Boot_Spring Security Rest - Fatal编程技术网

Spring boot Spring引导安全性允许来自给定IP地址的请求

Spring boot Spring引导安全性允许来自给定IP地址的请求,spring-boot,spring-security-rest,Spring Boot,Spring Security Rest,我们有以下安全配置代码 @覆盖 受保护的无效配置(HttpSecurity HttpSecurity)引发异常{ httpSecurity.cors()和().csrf().disable().authorizeRequests().antMatchers(“/api/**”).anyRequest() .authenticated()和().exceptionHandling().accessDeniedPage(“/”)和() .sessionManagement().sessionCrea

我们有以下安全配置代码

@覆盖
受保护的无效配置(HttpSecurity HttpSecurity)引发异常{
httpSecurity.cors()和().csrf().disable().authorizeRequests().antMatchers(“/api/**”).anyRequest()
.authenticated()和().exceptionHandling().accessDeniedPage(“/”)和()
.sessionManagement().sessionCreationPolicy(sessionCreationPolicy.STATELESS);
}
获取/api/users
POST/api/用户
获取/api/users/{userId}

我们需要在Spring Boot应用程序中限制以下请求(不是所有请求),并且只允许在属性中给定的
ipaddress(多个ipaddress)
上进行这些请求。

尝试以下配置:

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.cors().and().csrf().disable().authorizeRequests()
                .antMatchers("/api/users/**").hasIpAddress("127.0.0.1")
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated().and().exceptionHandling().accessDeniedPage("/").and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

谢谢你的帖子,在这里我们需要配置多个IPAddress。我刚刚试过,如下所示,似乎这是可行的@重写受保护的无效配置(HttpSecurity HttpSecurity)引发异常{HttpSecurity.cors()和().csrf().disable().authorizeRequests().antMatchers(“/api/users/**”).access(“hasIpAddress('10.00.07.9')或hasIpAddress('10.00.00.60'))和().anyRequest().authenticated()和().exceptionHandling().accessDeniedPage(“/”)和().sessionManagement().sessionCreationPolicy(sessionCreationPolicy.STATELESS);}