You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by gl...@locus.apache.org on 2000/08/05 18:01:21 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/request AccessInterceptor.java

glenn       00/08/05 09:01:20

  Modified:    src/share/org/apache/tomcat/request AccessInterceptor.java
  Log:
  Basic HTTP Authentication was broken with Apache/JServ, it would return
  status 500 because no content was being sent with the status 401.
  Added output of a Not Authorized page to basicAuthHandler.
  
  Revision  Changes    Path
  1.16      +22 -0     jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java
  
  Index: AccessInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AccessInterceptor.java	2000/08/02 02:17:27	1.15
  +++ AccessInterceptor.java	2000/08/05 16:01:20	1.16
  @@ -63,8 +63,10 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.core.Constants;
   import org.apache.tomcat.util.*;
  +import javax.servlet.*;
   import javax.servlet.http.*;
   import java.util.*;
  +import java.io.*;
   
   // XXX maybe it's a good idea to use a different model for adding secuirty
   // constraints - we use Container now because we want to generalize all
  @@ -343,6 +345,26 @@
   	res.setStatus( 401 );
   	res.setHeader( "WWW-Authenticate",
   		       "Basic realm=\"" + realm + "\"");
  +        // return some content to prevent error 500
  +	// and notify the user they are not authorized if BasicAuth fails
  +        res.setContentType("text/html");        // ISO-8859-1 default  
  +
  +        StringBuffer buf = new StringBuffer();
  + 
  +        buf.append("<html><head><title>Not Authorized</title></head>");
  +        buf.append("<body>Not Authorized</body></html>");
  +        String body = buf.toString(); 
  +        res.setContentLength(buf.length());
  + 
  +        if( res.isUsingStream() ) {
  +            ServletOutputStream out = res.getOutputStream(); 
  +            out.print(body);
  +            out.flush();   
  +        } else {
  +            PrintWriter out = res.getWriter();
  +            out.print(body);
  +            out.flush();
  +        }
       }
   }