title: Spring Boot + Security + Multi HTTP Web Configuration
body: <p>I'm trying to do an example using spring-boot with spring security.  My idea is to create a web app and also provide an API, I would like to both have security; so I need to create a multi http web security configuration however it is not working.</p>
  
  <p>I followed this link <a href="http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#multiple-httpsecurity" rel="noreferrer">http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#multiple-httpsecurity</a> but no success.  And, I'm getting this error</p>
  
  <p><strong>Error creating bean with name 'webSecurityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer to already built object</strong></p>
  
  <p>The configuration that I'm using is the following:</p>
  
  <pre><code>@Configuration
  @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
  @EnableGlobalAuthentication
  @EnableGlobalMethodSecurity(securedEnabled = true)
  public class WebSecurityConfiguration { 
  
  @Autowired
  protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
      auth
          .inMemoryAuthentication()
              .withUser("user").password("12345").roles("USER").and()
              .withUser("admin").password("12345").roles("USER", "ADMIN");
  }
  
  @Configuration
  @Order(1)
  public static class ApiConfigurationAdapter extends
          WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .antMatcher("/api/**")
              .authorizeRequests()
                  .anyRequest().hasRole("ADMIN")
                  .and()
              .httpBasic();
      }
  }
  
  @Configuration
  @Order(2)
  public static class WebConfigurationAdapter extends
          WebSecurityConfigurerAdapter {
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web
              .ignoring()
                  .antMatchers("/resources/**");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()                    
                  .antMatchers("/", "/home").permitAll()
              .anyRequest()
                  .authenticated()
              .and()
                  .formLogin()
                      .loginPage("/login").permitAll()
              .and()
                  .logout().permitAll();
      }
      }
  }
  </code></pre>
  
  <p>Thanks in advance</p>