title: spring security disable authentication ip based
body: <p>I'm writing an application which should use the authentication features of spring-security. The configuration is almost finished. </p>
  
  <p>The problem: I don't know how to disable the authentication and -redirect for requests from localhost / ip-range.
  We are using the Java Config for spring-security. There is the hasIpAddress function. But i don't think add this to each rules is the best solution.</p>
  
  <p>Current configuration (nothing special):</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
  
      http.authorizeRequests()
              .antMatchers("/", "/home").permitAll()
              .antMatchers("/config/**").hasRole("ADMIN")
              // ...
              .anyRequest().authenticated()
  
              .and()
              .formLogin()
              .loginPage("/login")
              .permitAll()
  
              .and()
              .logout()
              .permitAll();
  }
  
  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
      // TODO: change to LDAP
      auth.inMemoryAuthentication().withUser("testuser").password("password").roles("USER");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Similar Topic:
  <a href="https://stackoverflow.com/questions/10147161/authenticating-by-ip-address-in-spring-3-1-smartest-way-to-do-that">Authenticating By IP Address In Spring 3.1: Smartest Way To Do That?</a>
  skips the authentication via ldap, but not the redirect, if I converted the config right</p>
  
  <p>Thanks in advance</p>