Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java白名单动态IP地址?_Java_Networking_Ip Address - Fatal编程技术网

如何使用Java白名单动态IP地址?

如何使用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

应用程序IP地址是动态变化的,所以我想从应用程序URL获取IP地址,并想使用Java而不使用XML列出白名单。请让我知道怎么做

我尝试了下面的代码,但它包含XML配置

@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();
}

请显示您所做的工作?我已更新了代码