繁体   English   中英

如何在我们使用 springboot 的 Rest API 应用程序中将域或 IP 地址列入白名单?

[英]How can I whitelist Domain or IP address in a Rest API application in which we are using springboot?

我正在实现 REST API,我们使用 springboot 的StreamingResponseBody直接流式传输响应。 我们通过 JSON 接收查询参数,我们通过直接流发送数据库响应。

我们想锁定对 URL 的访问到特定域或 IP 地址集 - 我们如何实现这一点?

如果您使用 Java Configuration for Spring Boot Security,则必须使用

有IP地址()

在扩展 WebSecurityConfigurerAdapter 的 SecurityConfig class 中。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
           .antMatchers("/login").permitAll()
           .antMatchers("/api/example/**").hasIpAddress("1.1.1.1")
           .anyRequest().authenticated()
           .and()
           .formLogin().permitAll()
           .and()
           .csrf().disable();
    }

    // Rest of Code ...

 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM