costin 01/01/28 23:09:14 Modified: src/facade22/org/apache/tomcat/facade JspInterceptor.java src/share/org/apache/tomcat/modules/aaa AccessInterceptor.java src/share/org/apache/tomcat/modules/generators ErrorHandler.java StaticInterceptor.java src/share/org/apache/tomcat/util ByteChunk.java CharChunk.java MessageBytes.java src/share/org/apache/tomcat/util/test DefaultMatcher.java GTest.java Log: - fix bug in ErrorHandler ( the "original URI" was wrongly displayed in 404) - check WEB-INF and META-INF in AccessInterceptor ( where all access control should be done, instead of relying on every module on doing it ) - Few changes in StaticInterceptor to behave closer to apache. Also, redirects are sent only if the request passes the access control ( it's not a big deal, but it's safer this way ) - Added some code to do WEB-INF insensitive match without object allocation. - few fixes in the test driver Revision Changes Path 1.10 +1 -1 jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java Index: JspInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JspInterceptor.java 2001/01/28 19:45:52 1.9 +++ JspInterceptor.java 2001/01/29 07:08:37 1.10 @@ -495,7 +495,7 @@ } // if( debug > 3) - log.log( "Compiling: " + jspFile + " to " + + ctx.log( "Compiling: " + jspFile + " to " + mangler.getServletClassName()); //XXX old servlet - destroy(); 1.4 +17 -4 jakarta-tomcat/src/share/org/apache/tomcat/modules/aaa/AccessInterceptor.java Index: AccessInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/aaa/AccessInterceptor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AccessInterceptor.java 2001/01/09 21:26:07 1.3 +++ AccessInterceptor.java 2001/01/29 07:08:45 1.4 @@ -238,20 +238,33 @@ Context ctx=req.getContext(); SecurityConstraints ctxSec=(SecurityConstraints)ctx.getContainer(). getNote( secMapNote ); - if( ctxSec==null || ctxSec.patterns==0 ) return 0; // fast exit + // do the check for the "special patterns" MessageBytes reqURIMB=req.requestURI(); + String ctxPath= ctx.getPath(); + int ctxPathLen=ctxPath.length(); + + // quick test + if( reqURIMB.startsWithIgnoreCase( "/META-INF", ctxPathLen) ) { + return 403; + } + if( reqURIMB.startsWithIgnoreCase( "/WEB-INF", ctxPathLen) ) { + return 403; + } + + // if we don't have any other constraints, return + if( ctxSec==null || ctxSec.patterns==0 ) return 0; // fast exit + if (reqURIMB.indexOf('%') >= 0 || reqURIMB.indexOf( '+' ) >= 0) { log("Shouldn't happen - the request is decoded earlier"); reqURIMB.unescapeURL(); } String reqURI = req.requestURI().toString(); - String ctxPath= ctx.getPath(); - String path=reqURI.substring( ctxPath.length()); + String path=reqURI.substring( ctxPathLen); String method=req.method().toString(); if( debug > 1 ) log( "checking " + path ); - + for( int i=0; i< ctxSec.patterns ; i++ ) { Container ct=ctxSec.securityPatterns[i]; if( match( ct, path, method ) ) { 1.4 +10 -8 jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java Index: ErrorHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/ErrorHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ErrorHandler.java 2001/01/07 00:17:06 1.3 +++ ErrorHandler.java 2001/01/29 07:08:50 1.4 @@ -128,6 +128,7 @@ // Default status handlers ctx.addServlet( new RedirectHandler(this)); ctx.addErrorPage( "302", "tomcat.redirectHandler"); + ctx.addErrorPage( "301", "tomcat.redirectHandler"); ctx.addServlet( new NotFoundHandler(this, showDebugInfo)); ctx.addErrorPage( "404", "tomcat.notFoundHandler"); } @@ -173,7 +174,7 @@ if( errorPath != null ) { errorServlet=getHandlerForPath( cm, ctx, errorPath ); - // Make sure Jsps will work + // Make sure Jsps will work - needed if the error page is a jsp req.setAttribute( "javax.servlet.include.request_uri", ctx.getPath() + "/" + errorPath ); req.setAttribute( "javax.servlet.include.servlet_path", errorPath ); @@ -378,14 +379,10 @@ throws Exception { res.setContentType("text/html"); // ISO-8859-1 default - - String requestURI = (String)req. - getAttribute("javax.servlet.include.request_uri"); - - if (requestURI == null) { - requestURI = req.requestURI().toString(); - } + // "javax.servlet.include.request_uri" is set to this handler + String requestURI = req.requestURI().toString(); + if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "NotFoundHandler.buff"); @@ -668,6 +665,11 @@ String location = (String) req.getAttribute("javax.servlet.error.message"); Context ctx=req.getContext(); + + if( res.getStatus() != 301 && + res.getStatus() != 302 ) { + res.setStatus( 301 ); + } location = makeAbsolute(req, location); 1.4 +21 -16 jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java Index: StaticInterceptor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/generators/StaticInterceptor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StaticInterceptor.java 2001/01/28 21:46:00 1.3 +++ StaticInterceptor.java 2001/01/29 07:08:52 1.4 @@ -159,6 +159,16 @@ if( debug > 0 ) log( "DefaultServlet: welcome file: " + welcomeFile); + // consistent with Apache + if( welcomeFile==null && ! requestURI.endsWith("/") ) { + String redirectURI= requestURI + "/"; + req.setAttribute("javax.servlet.error.message", + redirectURI); + if( debug > 0) log( "Redirect " + redirectURI ); + req.setHandler( ctx.getServletByName( "tomcat.redirectHandler")); + return 0; + } + // Doesn't matter if we are or not in include if( welcomeFile == null ) { // normal dir, no welcome. @@ -167,15 +177,6 @@ return 0; } - // consistent with Apache - if( ! requestURI.endsWith("/") ) { - String redirectURI= requestURI + "/"; - req.setAttribute("javax.servlet.error.message", - redirectURI); - if( debug > 0) log( "Redirect " + redirectURI ); - return 301; - } - // Send redirect to the welcome file. // This is consistent with other web servers and avoids // gray areas in the spec - if the welcome file is a jsp, @@ -188,7 +189,11 @@ req.setAttribute("javax.servlet.error.message", redirectURI); if( debug > 0) log( "Redirect " + redirectURI ); - return 301; + // allow processing to go on - another mapper may change the + // outcome, we are just the default ( preventive for bad ordering, + // in correct config Static is the last one anyway ). + req.setHandler( ctx.getServletByName( "tomcat.redirectHandler")); + return 0; } private static String concatPath( String s1, String s2 ) { @@ -317,14 +322,14 @@ log("Ends with \\/. " + absPath); return null; } - if (absPath.length() > base.length()) + if (absPath.length() > base.length()) { String relPath=absPath.substring( base.length() + 1); if( debug>0) log( "RelPath = " + relPath ); String relPathU=relPath.toUpperCase(); if ( relPathU.startsWith("WEB-INF") || - relPathU.startsWith("META-INF")) { + relPathU.startsWith("META-INF")) { return null; } } @@ -386,13 +391,13 @@ String relPath=absPath.substring( base.length() + 1); String relPathU=relPath.toUpperCase(); if ( relPathU.startsWith("WEB-INF") || - relPathU.startsWith("META-INF")) { - context.getContextManager().handleStatus( req, res, 404); - return; + relPathU.startsWith("META-INF")) { + context.getContextManager().handleStatus( req, res, 404); + return; } } - if( sbNote==0 ) { + if( sbNote==0 ) { sbNote=req.getContextManager().getNoteId(ContextManager.REQUEST_NOTE, "RedirectHandler.buff"); } 1.5 +21 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/ByteChunk.java Index: ByteChunk.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/ByteChunk.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ByteChunk.java 2001/01/04 13:14:41 1.4 +++ ByteChunk.java 2001/01/29 07:08:56 1.5 @@ -319,6 +319,27 @@ return true; } + /** + * Returns true if the message bytes starts with the specified string. + * @param s the string + */ + public boolean startsWithIgnoreCase(String s, int pos) { + byte[] b = bytes; + int len = s.length(); + if (b == null || len+pos > bytesLen) { + return false; + } + int off = bytesOff+pos; + for (int i = 0; i < len; i++) { + if (Ascii.toLower( b[off++] ) != Ascii.toLower( s.charAt(i))) { + return false; + } + } + return true; + } + + + // based on ap_unescape_url ( util.c, Apache2.0 ) public int unescapeURL() { 1.5 +19 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/CharChunk.java Index: CharChunk.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/CharChunk.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CharChunk.java 2001/01/04 13:14:41 1.4 +++ CharChunk.java 2001/01/29 07:08:57 1.5 @@ -244,6 +244,25 @@ return true; } + /** + * Returns true if the message bytes starts with the specified string. + * @param s the string + */ + public boolean startsWithIgnoreCase(String s, int pos) { + char[] c = chars; + int len = s.length(); + if (c == null || len+pos > charsLen) { + return false; + } + int off = charsOff+pos; + for (int i = 0; i < len; i++) { + if (Ascii.toLower( c[off++] ) != Ascii.toLower( s.charAt(i))) { + return false; + } + } + return true; + } + // -------------------- Hash code -------------------- 1.16 +40 -0 jakarta-tomcat/src/share/org/apache/tomcat/util/MessageBytes.java Index: MessageBytes.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MessageBytes.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- MessageBytes.java 2000/12/30 07:54:16 1.15 +++ MessageBytes.java 2001/01/29 07:08:58 1.16 @@ -408,6 +408,32 @@ } } + /** + * Returns true if the message bytes starts with the specified string. + * @param s the string + */ + public boolean startsWithIgnoreCase(String s, int pos) { + switch (type) { + case T_STR: + if( strValue==null ) return false; + if( strValue.length() < pos + s.length() ) return false; + + for( int i=0; i<s.length(); i++ ) { + if( Ascii.toLower( s.charAt( i ) ) != + Ascii.toLower( strValue.charAt( pos + i ))) { + return false; + } + } + return true; + case T_CHARS: + return charC.startsWithIgnoreCase( s, pos ); + case T_BYTES: + return byteC.startsWithIgnoreCase( s, pos ); + default: + return false; + } + } + // -------------------- Hash code -------------------- @@ -463,6 +489,20 @@ public int indexOf(char c) { return indexOf( c, 0); + } + + // Inefficient initial implementation. Will be replaced on the next + // round of tune-up + public int indexOf(String s, int starting) { + toString(); + return strValue.indexOf( s, starting ); + } + + public int indexOfIgnoreCase(String s, int starting) { + toString(); + String upper=strValue.toUpperCase(); + String sU=s.toUpperCase(); + return upper.indexOf( sU, starting ); } /** 1.7 +4 -4 jakarta-tomcat/src/share/org/apache/tomcat/util/test/DefaultMatcher.java Index: DefaultMatcher.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/DefaultMatcher.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DefaultMatcher.java 2001/01/28 19:53:11 1.6 +++ DefaultMatcher.java 2001/01/29 07:09:08 1.7 @@ -275,10 +275,10 @@ Enumeration e=expectHeaders.keys(); while( e.hasMoreElements()) { String key=(String)e.nextElement(); - Header h=(Header)expectHeaders.get(key); - String value=h.getValue(); - h=(Header)headers.get(key); - String respValue=h.getValue(); + Header expH=(Header)expectHeaders.get(key); + String value=expH.getValue(); + Header resH=(Header)headers.get(key); + String respValue=(resH==null)? "": resH.getValue(); if( respValue==null || respValue.indexOf( value ) <0 ) { log("ERROR expecting header " + key + ":" + value + " \nGOT: " + respValue+ " HEADERS(" + 1.7 +21 -6 jakarta-tomcat/src/share/org/apache/tomcat/util/test/GTest.java Index: GTest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/test/GTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- GTest.java 2001/01/28 21:46:01 1.6 +++ GTest.java 2001/01/29 07:09:10 1.7 @@ -91,9 +91,10 @@ String description="No description"; - PrintWriter out=defaultOutput; - String outType=defaultOutType; - int debug=defaultDebug; + PrintWriter out=null; + String outType=null; + int debug=-1; + boolean result=false; public GTest() { @@ -146,6 +147,14 @@ return testProperties; } + public static void resetGTest() { + GTest.getTestResults().setSize(0); + GTest.getTestFailures().setSize(0); + GTest.getTestSuccess().setSize(0); + GTest.getTestProperties().clear(); + HttpClient.getHttpClients().clear(); + } + // -------------------- GTest behavior -------------------- public void setWriter( PrintWriter pw ) { out=pw; @@ -192,6 +201,7 @@ } public String getComment() { + if(comment==null) return ""; return comment.getText(); } @@ -288,8 +298,12 @@ // -------------------- Execute the request -------------------- public void execute() { - try { + // System.out.println("XXX " + outType + " " + defaultOutType); + if( out==null) out=defaultOutput; + if( outType==null) outType=defaultOutType; + if( debug==-1) debug=defaultDebug; + httpClient.execute(); Response resp=httpClient.getResponse(); @@ -335,7 +349,7 @@ out.println("FAIL " + msg ); out.println("Message: " + matcher.getMessage()); } - + out.flush(); } private void htmlReport() { @@ -392,6 +406,7 @@ ex.printStackTrace(out); out.println("</pre><br>"); } + out.flush(); } private void xmlReport() { @@ -413,7 +428,7 @@ ex.printStackTrace(out); out.println("</pre><br>"); } - + out.flush(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]