【发布时间】:2019-01-01 06:25:55
【问题描述】:
我想允许匿名访问,仅限于特定 IP 地址子网,访问 URL。
网址是:
http://10.102.34.98:880/auth/tokens/revoke/blabla 其中 auth 是网络应用的上下文根。
访问IP地址为10.102.34.98 访问IP地址的子网掩码为255.255.255.0 trusted.client.subnet 属性设置为 10.102.34.0/24
匿名访问工作正常:
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.requestMatchers()
.antMatchers("/login", "/oauth/authorize","/tokens/revoke/**")
.and()
.authorizeRequests()
.antMatchers("/tokens/revoke/**").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
}
但是一旦我将permitAll() 替换为hasIpAddress(),我就会被重定向到我的登录页面。
如何允许受 IP 地址子网限制的匿名访问?
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.requestMatchers()
.antMatchers("/login", "/oauth/authorize","/tokens/revoke/**")
.and()
.authorizeRequests()
.antMatchers("/tokens/revoke/**").hasIpAddress(environment.getProperty("trusted.client.subnet"))
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
}
更新 1:
最后是这段代码强制显示登录表单。我希望它不会考虑到这一点,因为它已经通过了 IP 地址白名单。
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
【问题讨论】:
-
你叫什么网址?
-
/tokens/revoke/blabla