title: How to add matchers to HttpSecurity spring web secure
body: <p>I try to implement spring security, but I have many roles and privileges, then I want to add the roles dynamically to each other resources. Like it:</p>
  
  <pre><code>@Override
  protected void configure(HttpSecurity http) throws Exception {
      super.configure(http);
  
  
      //PageRequest p = new PageRequest(0, 1000);
  
      List&lt;RolePrivilegeConfig&gt; rolePrivilegesConfig=rolePrivilegeConfigService.findAll();
  
      for (RolePrivilegeConfig rolePrivilegeConfig : rolePrivilegesConfig) {
  
          http.authorizeRequests()
          .antMatchers("/login").permitAll()
          .antMatchers(rolePrivilegeConfig.getResource())
          .access(rolePrivilegeConfig.getRoleName())
          .anyRequest().authenticated();               
      } }
  </code></pre>
  
  <p>I have this error:</p>
  
  <blockquote>
    <p>Failed to instantiate [javax.servlet.Filter]: Factory method
    'springSecurityFilterChain' threw exception; nested exception is
    java.lang.IllegalStateException: Can't configure antMatchers after
    anyRequest.</p>
  </blockquote>
  
  <p>How can I put all matchers and call request after?</p>