title: How to set-up spring security without inMemoryAuthentication?
body: <p>I've my spring security up and running. It's using my own authentication provider since the authentication is done by a host system.</p>
  
  <p>Since I want to have annotation based security I added <code>@EnableGlobalMethodSecurity(securedEnabled = true)</code> to my servlet configuration. </p>
  
  <p>Unfortunately this was triggering a <em>AuthenticationManager is required</em> exception. The only way to avoid this exception was to add a <code>configureGlobal</code> method to the servlet config with an <code>inMemoryAuthentication</code>.</p>
  
  <p>Obviously I don't want this inMemoryAuthentication since the application depends on my own host authentication. How can I get rid of the inMemoryAuthentication?</p>
  
  <p>This is my servlet configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @EnableGlobalMethodSecurity(securedEnabled = true)
  @Import({ 
      FooControllerConfig.class, 
  })
  public class FooServerletConfig {
  
      @Autowired
      //@formatter:off
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .inMemoryAuthentication()
                  .withUser("user").password("password").authorities("ROLE_USER");
      }
      //@formatter:on
  
  }
  </code></pre>
  
  <p>This is the security configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class FooSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      //@formatter:off
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authenticationProvider(aS400AuthenticationProvider())
              .formLogin()
                  .loginProcessingUrl("/authorized")
                  .passwordParameter("password")
                  .usernameParameter("clientId")
                  .successHandler(fooAuthenticationSuccessHandler())
                  .failureHandler(fooAuthenticationFailureHandler())
              .and()
              .csrf().disable()
              .rememberMe()
                  .rememberMeServices(fooRememberMeServices())
                  .key(CookieService.LIR_SESSION_COOKIE_NAME)
              .and()
              .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
              .and()
              .exceptionHandling().authenticationEntryPoint(new Http403ForbiddenEntryPoint());
              ;
      }
      //@formatter:on
  
  }
  </code></pre>
  
  <p>This is the exception I get if the <code>configureGlobal</code> method is missing:</p>
  
  <pre><code>SEVERE: Servlet /FOO threw load() exception
  java.lang.IllegalArgumentException: An AuthenticationManager is required
      at org.springframework.util.Assert.notNull(Assert.java:112)
      at org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:121)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
      at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      at javax.servlet.GenericServlet.init(GenericServlet.java:160)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:695)
  </code></pre>