title: Spring Security Authentication manager autowiring
body: <p>after few desperate hours trying to find out why is not my custom authentication manager autowiring, I came here for a little help.
  So I've got Web application, running on Spring (with Stripes). Authentication is done by my custom class. Everything works fine - in jsp, i can use jsp tags and everyting, http interceptor works as it should. But when i try to autowire authentication manager into Jersey "REST class" , everything goes wrong and nothing is injected.</p>
  
  <p>So, in web xml i've got both context files:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          /WEB-INF/spring-context.xml
          /WEB-INF/spring-security.xml
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>spring-security.xml:</p>
  
  <pre><code>&lt;context:component-scan base-package="org.springframework.security" /&gt;
  &lt;context:annotation-config/&gt;
  
  &lt;http use-expressions="true" auto-config="true"&gt;
  
  &lt;/http&gt;
  
  &lt;authentication-manager alias="authManager"&gt;
      &lt;authentication-provider ref="AuthenticationManagerBean" /&gt;
  &lt;/authentication-manager&gt; 
  
  &lt;beans:bean id="AuthenticationManagerBean" class="com.manager.services.MyAuthenticationManager"/&gt;
  &lt;beans:bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler" /&gt;
  </code></pre>
  
  <p>And inside of Jersey action bean is something like this:</p>
  
  <pre><code>@Inject
  @Qualifier("authManager")
  protected AuthenticationManager authenticationManager;
  </code></pre>
  
  <p>The whole application builds ok, jetty server start without problems (both MyAuthenticationManager and org.springframework.security.authenticationManager are succesfully pre-instatiated), but when try to use autowired authmanager, im getting null pointer.</p>
  
  <p><strong>EDIT:</strong>
  I have succesfully autowired AuthenticationManager into Stripes' Action Beans, but there is still problem with Jersey's action beans, where construction @Inject @Qualifier(...) doesnt work for AuthManager (but works for other autowired beans, altough without @Qualifier, just @Inject).</p>
  
  <p><strong>EDIT 2:</strong>
  After few hours trying to find out why Spring doesn't inject authenticationManager into Jersey Beans, I solved the problem with:</p>
  
  <pre><code>@Inject
  @InjectParam("org.springframework.security.authenticationManager")
  protected AuthenticationManager authenticationManager;
  </code></pre>
  
  <p>I don't know wheter is it good solution or isn't, but it's working and spring now inject correct authentication manager.</p>