简体   繁体   English

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

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

I'm implementing REST API and we are directly streaming the response using StreamingResponseBody of springboot.我正在实现 REST API,我们使用 springboot 的StreamingResponseBody直接流式传输响应。 We are receiving query parameter through JSON and we are sending the database response by directly streaming.我们通过 JSON 接收查询参数,我们通过直接流发送数据库响应。

We want to lock down access to the URL to a particular Domain or set of IP address - how can we achieve this?我们想锁定对 URL 的访问到特定域或 IP 地址集 - 我们如何实现这一点?

If you are using Java Configuration for Spring Boot Security than you have to use如果您使用 Java Configuration for Spring Boot Security,则必须使用

hasIpAddress()有IP地址()

in SecurityConfig class that extends WebSecurityConfigurerAdapter.在扩展 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.

相关问题 如何使用springboot使用bitbucket rest api获取所有存储库? - How can i use the bitbucket rest api to get all the repos using springboot? 我们如何使用 rest Api 读取文件,该文件存在于我的本地系统中? - how can we read a file using rest Api, which is locally present in my system? 如何使我的 SpringBoot 应用程序可以通过我的公共 IP 地址访问? - How can I make my SpringBoot app accessible with my public IP address? 如何在 SpringBoot 中获取 Rsocket 连接的远程 IP 地址 - How do I get the remote IP address for an Rsocket connection in SpringBoot 如何使用IP地址共享数据库? - How can I share my database using IP Address? 如何在Java中使用IP地址查找城市名称 - How can i find the City name using IP address in Java 如何在Java中检查网络类型?(使用IP地址) - How can I check network type in java?(using IP address) 如何在不使用 Java 中的 IP 的情况下获取 MAC 地址? - How can I get MAC Address without using the IP in Java? 如何在springboot rest api后端应用程序中存储用户个人资料图片 - how to store user profile pictures in springboot rest api backend application 我如何在Java中获取客户端系统的用户名和域名,因为我可以使用request.getRemoteHost获得IP地址和主机名 - How can i get the username and domain name of client system in java as i can get the ip address and host name using request.getRemoteHost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM