title: Redirect to error page in spring security pre authentication
body: <p>I am using Spring Security and using Pre-Authentication module as my application is authenticated using Siteminder.</p>
  
  <p>Following is the spring config XML</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:security="http://www.springframework.org/schema/security"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
    &lt;!-- http403EntryPoint --&gt;
  
  &lt;security:http use-expressions="true" auto-config="false" entry-point-ref="http403EntryPoint"&gt;
      &lt;!-- Additional http configuration omitted --&gt;
      &lt;security:intercept-url pattern="/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" /&gt;
  &lt;/security:http&gt;
  
  &lt;bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter"&gt;
      &lt;property name="principalRequestHeader" value="SM_USER"/&gt;
      &lt;property name="authenticationManager" ref="authenticationManager" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"&gt;
      &lt;property name="preAuthenticatedUserDetailsService"&gt;
          &lt;bean id="userDetailsServiceWrapper"  class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper"&gt;
              &lt;property name="userDetailsService" ref="customUserDetailsService"/&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;security:authentication-manager alias="authenticationManager"&gt;
      &lt;security:authentication-provider ref="preauthAuthProvider" /&gt;
  &lt;/security:authentication-manager&gt;   
  
  &lt;bean id="customUserDetailsService" class="com.vzw.iaas.security.service.CustomUserDetailsService"&gt;&lt;/bean&gt;
  &lt;bean id="http403EntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"&gt;&lt;/bean&gt;
  
  &lt;bean id="exceptionTranslationFilter"
   class="org.springframework.security.web.access.ExceptionTranslationFilter"&gt;
      &lt;property name="authenticationEntryPoint" ref="authenticationEntryPoint"/&gt;
      &lt;property name="accessDeniedHandler" ref="accessDeniedHandler"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="authenticationEntryPoint"
   class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&gt;
      &lt;property name="loginFormUrl" value="/NotAuthorized.html"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="accessDeniedHandler"
   class="org.springframework.security.web.access.AccessDeniedHandlerImpl"&gt;
      &lt;property name="errorPage" value="/accessDenied.html"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now when there is an exception i.e. when I am sending a request to the application without sending a SM_USER the appliaction instead of showing the error page i.e. in that case NotAuthorized.html throws and internal server 500 error.</p>
  
  <p>I would like to show my custom error pages in following scenarios.
  1. When there is an AuthenticationException
  2. When the user has no access.</p>
  
  <p>Can Spring Security masters tell me what I am missing here.</p>