title: Spring Security 3.1 Run-As
body: <p>I am trying to get the Run-As feature in Spring Security 3.1 to work. The strange thing is that I cannot find a single example. Even the <a href="http://www.packtpub.com/spring-security-3/book" rel="noreferrer">Spring Security Book</a> does not cover the topic at all.</p>
  
  <p>Here is the security part of my application context.</p>
  
  <pre><code>&lt;security:global-method-security
          pre-post-annotations="enabled"&gt;
      &lt;security:expression-handler ref="customExpressionHandler"/&gt;
  &lt;/security:global-method-security&gt;
  
  &lt;bean id="runAsManager"
        class="org.springframework.security.access.intercept.RunAsManagerImpl"&gt;
      &lt;property name="key" value="my_run_as_password"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="runAsAuthenticationProvider"
        class="org.springframework.security.access.intercept.RunAsImplAuthenticationProvider"&gt;
      &lt;property name="key" value="my_run_as_password"/&gt;
  &lt;/bean&gt;
  &lt;security:http auto-config="true" create-session="always"&gt;
      &lt;security:remember-me key="njc2"/&gt;
      &lt;security:session-management invalid-session-url="/sessionTimeout.html"/&gt;
      &lt;security:intercept-url pattern="/**" access="ROLE_USER"/&gt;
      &lt;security:form-login login-page='/login.html'
                           authentication-success-handler-ref="njcAuthenticationSuccessHandler"
                           authentication-failure-url="/login-failure.html"/&gt;
      &lt;security:logout invalidate-session="true" logout-url="/j_spring_security_logout"
                       logout-success-url="/login.html"/&gt;
  &lt;/security:http&gt;
  </code></pre>
  
  <p>At runtime Spring 'magically' creates an instance of <code>org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor</code> but does not wire my <code>runAsManager</code> and therefore uses the <code>NullRunAsManager</code> that is created by default.</p>
  
  <p>Can you show me a valid Spring Security 3.1 example that demonstrates run as and using JSR-250 annotations such as <code>@RunAs</code>?</p>