Bug 18040 - Entering <error-page> in web.xml for error code 401 BASIC unexpected behaviour
Summary: Entering <error-page> in web.xml for error code 401 BASIC unexpected behaviour
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 4
Classification: Unclassified
Component: Unknown (show other bugs)
Version: 4.1.24
Hardware: Macintosh other
: P3 normal with 5 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 13430 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-16 15:15 UTC by adam neilson
Modified: 2005-03-24 14:39 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description adam neilson 2003-03-16 15:15:19 UTC
when trying to use a custom error page for my webapp with BASIC auth, i get no 
name/pass challenge, i'm fowarded straight to the 401 error page

in my web.xml i have 
<snippet>

 <error-page>
        <error-code>401</error-code>
        <location>/error/401.html</location>
    </error-page>

<snip>....</snip>

    <security-constraint>
        <web-resource-collection>
           <web-resource-name>MyApplication</web-resource-name>
               <url-pattern>/admin/*</url-pattern>
               <url-pattern>/servlet/com.myapp.admin.*</url-pattern>
               <http-method>GET</http-method>
               <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>myappadmin</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
         <auth-method>BASIC</auth-method>
         <realm-name>MyApplication Realm</realm-name>
    </login-config>
    <security-role>
         <role-name>myappadmin</role-name>
    </security-role>
</snippet>
Comment 1 Pradeep Krishnan 2003-07-25 15:02:34 UTC
The following works in Tomcat 4.1.24:

Convert your error page to a jsp and add the following to the top of the file:
<%
String realmName = "xxx; // Specify the realm name from web.xml
response.setHeader("WWW-Authenticate",
			   "Basic realm=\"" + realmName + "\"");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
%>
Comment 2 Mark Thomas 2004-05-10 20:48:20 UTC
The 401 response is actually part of the BASIC authentication process (see RFC 
2616 for full details) as well as the response when BASIC authentication 
fails. This specification of an error page for 401 interfers with this dual 
use.

401 should perhaps be a special case but the servlet spec does not treat it as 
such. The work-around described above (or something that achieves the same 
thing) is the way to go if you want a custom error page for a 401.

Strictly this bug report is INVALID as tomcat is doing what the spec says it 
should.
Comment 3 Mark Thomas 2005-03-24 23:39:26 UTC
*** Bug 13430 has been marked as a duplicate of this bug. ***