【发布时间】:2019-05-01 02:40:32
【问题描述】:
我正在为 Spring Boot 应用程序中的几个内部端点设置基本身份验证。在进行基本身份验证检查之前,我有一个用例来进行 IP 白名单验证。使用 WebSecurityConfigurerAdapter 配置方法,我能够实现这一点,但是在 ip 白名单授权之前完成基本身份验证的顺序是相反的。
有没有办法让 IP 白名单优先于基本身份验证?
使用以下代码进行网络安全
return new WebSecurityConfigurerAdapter() {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.access("(hasIpAddress('xx.xx.xx.xx') and isAuthenticated()")
.and()
.httpBasic();
}
}
【问题讨论】:
-
没有内置方法。但是,最简单的方法是实现您自己的自定义过滤器。只需执行
javax.servlet.Filter。您可以使用addFilterBefore在 Spring 配置中添加过滤器。
标签: spring-boot spring-security basic-authentication