Author: remy.maucherat(a)jboss.com
Date: 2008-03-31 09:42:42 -0400 (Mon, 31 Mar 2008)
New Revision: 569
Modified:
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/catalina/connector/LocalStrings.properties
trunk/java/org/apache/catalina/realm/RealmBase.java
trunk/java/org/apache/catalina/servlets/CGIServlet.java
trunk/webapps/docs/changelog.xml
Log:
- Port 3 patches.
- Remove hackish code to get the System environment in the CGI Servlet.
- 44529: No roles (deny all) trumps no auth-constraint (allow all).
- 44673: Fix ServletInputStream still readable when closed.
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-03-31 13:13:26 UTC (rev
568)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-03-31 13:42:42 UTC (rev
569)
@@ -25,6 +25,7 @@
import java.util.HashMap;
import org.apache.catalina.security.SecurityUtil;
+import org.apache.catalina.util.StringManager;
import org.apache.coyote.ActionCode;
import org.apache.coyote.Request;
import org.apache.tomcat.util.buf.B2CConverter;
@@ -47,6 +48,13 @@
// -------------------------------------------------------------- Constants
+ /**
+ * The string manager for this package.
+ */
+ protected static StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
public static final String DEFAULT_ENCODING =
org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
public static final int DEFAULT_BUFFER_SIZE = 8*1024;
@@ -266,6 +274,9 @@
public int available() {
+ if (eof || closed) {
+ return -1;
+ }
int available = 0;
if (state == BYTE_STATE) {
available = bb.getLength();
@@ -336,12 +347,20 @@
public int readByte()
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
return bb.substract();
}
public int read(byte[] b, int off, int len)
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
return bb.substract(b, off, len);
}
@@ -390,6 +409,10 @@
public int read()
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
return cb.substract();
}
@@ -402,6 +425,10 @@
public int read(char[] cbuf, int off, int len)
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
return cb.substract(cbuf, off, len);
}
@@ -409,6 +436,9 @@
public long skip(long n)
throws IOException {
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
if (n < 0) {
throw new IllegalArgumentException();
}
@@ -440,6 +470,10 @@
public boolean ready()
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
return (available() > 0);
}
@@ -451,6 +485,10 @@
public void mark(int readAheadLimit)
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
if (cb.getLength() <= 0) {
cb.setOffset(0);
cb.setEnd(0);
@@ -476,6 +514,10 @@
public void reset()
throws IOException {
+
+ if (closed)
+ throw new IOException(sm.getString("inputBuffer.streamClosed"));
+
if (state == CHAR_STATE) {
if (markPos < 0) {
throw new IOException();
Modified: trunk/java/org/apache/catalina/connector/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/connector/LocalStrings.properties 2008-03-31 13:13:26
UTC (rev 568)
+++ trunk/java/org/apache/catalina/connector/LocalStrings.properties 2008-03-31 13:42:42
UTC (rev 569)
@@ -49,9 +49,6 @@
coyoteRequest.attributeEvent=Exception thrown by attributes event listener
coyoteRequest.parseParameters=Exception thrown whilst processing POSTed parameters
coyoteRequest.postTooLarge=Parameters were not parsed because the size of the posted data
was too big. Use the maxPostSize attribute of the connector to resolve this if the
application should accept large POSTs.
-requestFacade.nullRequest=The request object has been recycled and is no longer
associated with this facade
-responseFacade.nullResponse=The response object has been recycled and is no longer
associated with this facade
-cometEvent.nullRequest=The event object has been recycled and is no longer associated
with a request
#
# MapperListener
@@ -63,5 +60,11 @@
mapperListener.unregisterContext=Unregister Context {0}
mapperListener.registerWrapper=Register Wrapper {0} in Context {1}
+#
+# Others
+#
-
+requestFacade.nullRequest=The request object has been recycled and is no longer
associated with this facade
+responseFacade.nullResponse=The response object has been recycled and is no longer
associated with this facade
+cometEvent.nullRequest=The event object has been recycled and is no longer associated
with a request
+inputBuffer.streamClosed=Stream closed
Modified: trunk/java/org/apache/catalina/realm/RealmBase.java
===================================================================
--- trunk/java/org/apache/catalina/realm/RealmBase.java 2008-03-31 13:13:26 UTC (rev 568)
+++ trunk/java/org/apache/catalina/realm/RealmBase.java 2008-03-31 13:42:42 UTC (rev 569)
@@ -751,7 +751,7 @@
// Which user principal have we already authenticated?
Principal principal = request.getPrincipal();
boolean status = false;
- boolean denyfromall = false;
+ boolean denyFromAll = false;
for(int i=0; i < constraints.length; i++) {
SecurityConstraint constraint = constraints[i];
@@ -774,18 +774,17 @@
if( log.isDebugEnabled() )
log.debug("No roles ");
status = false; // No listed roles means no access at all
- denyfromall = true;
+ denyFromAll = true;
+ break;
} else {
if(log.isDebugEnabled())
log.debug("Passing all access");
- return (true);
+ status = true;
}
} else if (principal == null) {
if (log.isDebugEnabled())
log.debug(" No user authenticated, cannot grant access");
- status = false;
- } else if(!denyfromall) {
-
+ } else {
for (int j = 0; j < roles.length; j++) {
if (hasRole(principal, roles[j]))
status = true;
@@ -795,7 +794,7 @@
}
}
- if (allRolesMode != AllRolesMode.STRICT_MODE && !status &&
principal != null) {
+ if (!denyFromAll && allRolesMode != AllRolesMode.STRICT_MODE &&
!status && principal != null) {
if (log.isDebugEnabled()) {
log.debug("Checking for all roles mode: " + allRolesMode);
}
Modified: trunk/java/org/apache/catalina/servlets/CGIServlet.java
===================================================================
--- trunk/java/org/apache/catalina/servlets/CGIServlet.java 2008-03-31 13:13:26 UTC (rev
568)
+++ trunk/java/org/apache/catalina/servlets/CGIServlet.java 2008-03-31 13:42:42 UTC (rev
569)
@@ -304,13 +304,7 @@
Boolean.valueOf(getServletConfig().getInitParameter("passShellEnvironment")).booleanValue();
if (passShellEnvironment) {
- try {
- shellEnv.putAll(getShellEnvironment());
- } catch (IOException ioe) {
- ServletException e = new ServletException(
- "Unable to read shell environment variables", ioe);
- throw e;
- }
+ shellEnv.putAll(System.getenv());
}
if (getServletConfig().getInitParameter("executable") != null) {
@@ -631,62 +625,12 @@
} //doGet
-
/** For future testing use only; does nothing right now */
public static void main(String[] args) {
System.out.println("$Header$");
}
- /**
- * Get all shell environment variables. Have to do it this rather ugly way
- * as the API to obtain is not available in 1.4 and earlier APIs.
- *
- * See <a
href="http://www.rgagnon.com/javadetails/java-0150.html">Read environment
- * variables from an application</a> for original source and article.
- */
- private Hashtable<String,String> getShellEnvironment() throws IOException {
- Hashtable<String,String> envVars = new Hashtable<String,String>();
- Process p = null;
- Runtime r = Runtime.getRuntime();
- String OS = System.getProperty("os.name").toLowerCase();
- boolean ignoreCase;
- if (OS.indexOf("windows 9") > -1) {
- p = r.exec( "command.com /c set" );
- ignoreCase = true;
- } else if ( (OS.indexOf("nt") > -1)
- || (OS.indexOf("windows 20") > -1)
- || (OS.indexOf("windows xp") > -1) ) {
- // thanks to JuanFran for the xp fix!
- p = r.exec( "cmd.exe /c set" );
- ignoreCase = true;
- } else {
- // our last hope, we assume Unix (thanks to H. Ware for the fix)
- p = r.exec( "env" );
- ignoreCase = false;
- }
-
- BufferedReader br = new BufferedReader
- ( new InputStreamReader( p.getInputStream() ) );
- String line;
- while( (line = br.readLine()) != null ) {
- int idx = line.indexOf( '=' );
- String key = line.substring( 0, idx );
- String value = line.substring( idx+1 );
- if (ignoreCase) {
- key = key.toUpperCase();
- }
- envVars.put(key, value);
- }
- return envVars;
- }
-
-
-
-
-
-
-
/**
* Encapsulates the CGI environment and rules to derive
* that environment from the servlet container and request information.
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-03-31 13:13:26 UTC (rev 568)
+++ trunk/webapps/docs/changelog.xml 2008-03-31 13:42:42 UTC (rev 569)
@@ -39,6 +39,15 @@
<update>
Add Comet EOF event when the end of the stream is reached without an error.
(remm)
</update>
+ <fix>
+ Remove hackish code to get the System environment in the CGI Servlet. (markt)
+ </fix>
+ <fix>
+ <bug>44529</bug>: No roles (deny all) trumps no auth-constraint
(allow all). (markt)
+ </fix>
+ <fix>
+ <bug>44673</bug>: Fix ServletInputStream still readable when closed.
(markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
@@ -72,6 +81,10 @@
Move the parameters backend to the probably more efficient MultiMap from
Hashtable,
and remove the nesting capabilities inherited from Tomcat 3. (remm)
</update>
+ <update>
+ Repackage MimeHeaders and Parameters using inner classes, and remove all
obsolete
+ collections. (remm)
+ </update>
</changelog>
</subsection>
</section>