title: How to disable security filter for particular URL in spring boot
body: <p>Hi I added rest web service for my project..When I call to the rest service without login to my account, my rest services redirect to login page... How can I remove this feature for only web service URL.... Other URLs need to this security....</p>
  
  <p>This is my security configuration</p>
  
  <pre><code>package lk.slsi.security.configuration;
  
  import lk.slsi.security.services.AuthenticationService;
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
  import org.springframework.security.web.util.matcher.RequestMatcher;
  
  import javax.servlet.http.HttpServletRequest;
  import org.springframework.security.config.annotation.web.builders.WebSecurity;
  
  /**
   * Created by ignotus on 1/26/2017.
   */
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
      private static final Logger logger = LogManager.getLogger(SecurityConfiguration.class);
  
      @Autowired
      private AuthenticationService authenticationService;
  
      private RequestMatcher requestMatcher = new RequestMatcher() {
  
          private AntPathRequestMatcher[] disableCsrfMatcher = {
                  new AntPathRequestMatcher("*/**")
          };
  
          @Override
          public boolean matches(HttpServletRequest httpServletRequest) {
              for (AntPathRequestMatcher match : disableCsrfMatcher) {
                  if (match.matches(httpServletRequest)) {
                      return false;
                  }
              }
              return true;
          }
      };
      @Override
          public void configure(WebSecurity web) throws Exception {
  
              web.ignoring().antMatchers("/restservice/**");
          }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http    
                  .authorizeRequests()
                  .antMatchers("/view/public/**").permitAll()
                  .anyRequest().authenticated()
                  .and()
                  .formLogin()
                  .loginPage("/login")
                  .permitAll()
                  .and().logout().invalidateHttpSession(true)
                  .permitAll().logoutSuccessUrl("/");
  
          http.csrf().disable();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) {
          ShaPasswordEncoder encoder = new ShaPasswordEncoder(224);
          try {
              auth.userDetailsService(authenticationService).passwordEncoder(encoder);
          } catch (Exception e) {
              logger.error("Error Occurred while authentication. [{}]", e);
          }
      }
  }
  </code></pre>
  
  <p>This is my rest service config class(JAX-RS)</p>
  
  <pre><code>@ApplicationPath("TransferPermit/SlsitoCustoms/")
  public class restConfig extends Application{
  
  }
  </code></pre>
  
  <p>This is my rest service controller</p>
  
  <pre><code>@Path("getby")
  public class webServiceforCustoms {
  
      @Autowired
      private permitServices permitServices;
  
      /**
       * Creates a new instance of GenericResource
       */
      public webServiceforCustoms() {
      }
  
      /**
       * Retrieves representation of an instance of lk.slsi.GenericResource
       *
       * @param id
       * @return an instance of java.lang.String
       */
  
      @GET
      @Produces(MediaType.APPLICATION_XML)
      @Path("/date/{dtIssue}")
      public List&lt;CustomsPermit&gt; getXmlbyDate(@PathParam("dtIssue") String dtIssue) {
          List&lt;CustomsPermit&gt; permitRelease = permitServices.getPermitByDate(dtIssue);
          return permitRelease;
      }
  
      @GET
      @Produces(MediaType.APPLICATION_XML)
      @Path("/id/{SNumber}")
      public CustomsPermit getXmlbyEntryNo(@PathParam("SNumber") String SNumber) {
          CustomsPermit permitRelease = permitServices.getPermitBySNumber(SNumber);
          return permitRelease;
      }
  
      @GET
      @Produces(MediaType.APPLICATION_XML)
      @Path("/vatno/{importerVAT}")
      public List&lt;CustomsPermit&gt; getXmlbyVATNo(@PathParam("importerVAT") String importerVAT) {
          List&lt;CustomsPermit&gt; permitRelease = permitServices.getPermitByImporterVAT(importerVAT);
          return permitRelease;
      }
  
      /**
       * PUT method for updating or creating an instance of GenericResourcer
       *
       * @param content representation for the resource
       */
      @PUT
      @Consumes(MediaType.APPLICATION_XML)
      public void putXml(String content) {
      }
  }
  </code></pre>