如何使用Java白名单动态IP地址?
应用程序IP地址是动态变化的,所以我想从应用程序URL获取IP地址,并想使用Java而不使用XML列出白名单。请让我知道怎么做 我尝试了下面的代码,但它包含XML配置如何使用Java白名单动态IP地址?,java,networking,ip-address,Java,Networking,Ip Address,应用程序IP地址是动态变化的,所以我想从应用程序URL获取IP地址,并想使用Java而不使用XML列出白名单。请让我知道怎么做 我尝试了下面的代码,但它包含XML配置 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exc
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login").permitAll()
.antMatchers("/foos/**").hasIpAddress("11.11.11.11")
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and()
.csrf().disable();
}
<security:http>
<security:form-login/>
<security:intercept-url pattern="/login" access="permitAll()" />
<security:intercept-url pattern="/foos/**" access="hasIpAddress('11.11.11.11')" />
<security:intercept-url pattern="/**" access="isAuthenticated()" />
</security:http>
@配置
@启用Web安全性
公共类SecurityConfig扩展了WebSecurity配置适配器{
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http.authorizeRequests()
.antMatchers(“/login”).permitAll()
.antMatchers(“/foos/**”).hasIpAddress(“11.11.11.11”)
.anyRequest().authenticated()
.及()
.formLogin().permitAll()
.及()
.csrf().disable();
}
请显示您所做的工作?我已更新了代码