我已经创建了一个Spring Boot项目,并且没有实现安全性。根据要求,我必须只允许1个IP地址访问API端点(假设IP地址为11.11.11.11)。我尝试了以下方法,但没有这些方法。如果有人可以帮助我了解缺失的内容,请。
1st try ----
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public FilterRegistrationBean remoteAddressFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
RemoteAddrFilter filter = new RemoteAddrFilter();
filter.setAllow("11.11.11.11");
filterRegistrationBean.setFilter(filter);
filterRegistrationBean.addUrlPatterns("/*");
return filterRegistrationBean;
}
}
2nd try ----
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/*").hasIpAddress("11.11.11.11");
}
}