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);}