JBossWeb SVN: r2023 - branches/7.0.x/java/org/apache/catalina/core.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-13 18:34:05 -0400 (Fri, 13 Apr 2012)
New Revision: 2023
Modified:
branches/7.0.x/java/org/apache/catalina/core/ContainerBase.java
Log:
Port patch: use the thread listener bind/unbind on the background process.
Modified: branches/7.0.x/java/org/apache/catalina/core/ContainerBase.java
===================================================================
--- branches/7.0.x/java/org/apache/catalina/core/ContainerBase.java 2012-04-13 22:31:25 UTC (rev 2022)
+++ branches/7.0.x/java/org/apache/catalina/core/ContainerBase.java 2012-04-13 22:34:05 UTC (rev 2023)
@@ -42,6 +42,7 @@
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
@@ -1598,10 +1599,16 @@
Thread.currentThread().setContextClassLoader
(container.getLoader().getClassLoader());
}
+ if (container instanceof Context) {
+ ((Context) container).getThreadBindingListener().bind();
+ }
container.backgroundProcess();
} catch (Throwable t) {
log.error("Exception invoking periodic operation: ", t);
} finally {
+ if (container instanceof Context) {
+ ((Context) container).getThreadBindingListener().unbind();
+ }
Thread.currentThread().setContextClassLoader(cl);
}
Container[] children = container.findChildren();
12 years, 8 months
JBossWeb SVN: r2022 - in branches/7.0.x: java/org/apache/coyote/http11 and 2 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-13 18:31:25 -0400 (Fri, 13 Apr 2012)
New Revision: 2022
Added:
branches/7.0.x/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java
Modified:
branches/7.0.x/java/org/apache/catalina/connector/Response.java
branches/7.0.x/java/org/apache/catalina/connector/ResponseFacade.java
branches/7.0.x/java/org/apache/coyote/http11/Http11AprProcessor.java
branches/7.0.x/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java
Log:
- Try to tweak for JBWEB-238.
- As an exception, don't add the void filter to the output for 1xx status codes. Not very good, but this wasn't there before.
- Add a new startUpgrade to allow reading and writing raw bytes of the "body" until the upgrade process is complete. Calling it is optional.
Modified: branches/7.0.x/java/org/apache/catalina/connector/Response.java
===================================================================
--- branches/7.0.x/java/org/apache/catalina/connector/Response.java 2012-04-13 16:38:32 UTC (rev 2021)
+++ branches/7.0.x/java/org/apache/catalina/connector/Response.java 2012-04-13 22:31:25 UTC (rev 2022)
@@ -1342,6 +1342,29 @@
}
+ public void startUpgrade() {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.ise"));
+
+ if (!connector.hasIoEvents())
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.noEvents"));
+
+ if (!request.isEventMode() || request.getAsyncContext() != null)
+ throw new IllegalStateException
+ (sm.getString("coyoteResponse.upgrade.noHttpEventServlet"));
+
+ // Ignore any call from an included servlet
+ if (included)
+ return;
+
+ request.getCoyoteRequest().action(ActionCode.UPGRADE, null);
+
+ }
+
+
public void sendUpgrade()
throws IOException {
@@ -1361,9 +1384,6 @@
if (included)
return;
- // Clear any data content that has been buffered
- resetBuffer();
-
// Output required by RFC2616. Protocol specific headers should have
// already been set.
setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
Modified: branches/7.0.x/java/org/apache/catalina/connector/ResponseFacade.java
===================================================================
--- branches/7.0.x/java/org/apache/catalina/connector/ResponseFacade.java 2012-04-13 16:38:32 UTC (rev 2021)
+++ branches/7.0.x/java/org/apache/catalina/connector/ResponseFacade.java 2012-04-13 22:31:25 UTC (rev 2022)
@@ -455,6 +455,16 @@
}
+ public void startUpgrade() {
+
+ if (isCommitted())
+ throw new IllegalStateException
+ (/*sm.getString("responseBase.reset.ise")*/);
+
+ response.startUpgrade();
+
+ }
+
public void sendUpgrade()
throws IOException {
Modified: branches/7.0.x/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- branches/7.0.x/java/org/apache/coyote/http11/Http11AprProcessor.java 2012-04-13 16:38:32 UTC (rev 2021)
+++ branches/7.0.x/java/org/apache/coyote/http11/Http11AprProcessor.java 2012-04-13 22:31:25 UTC (rev 2022)
@@ -1657,7 +1657,7 @@
}
int statusCode = response.getStatus();
- if ((statusCode == 101) || (statusCode == 204) || (statusCode == 205)
+ if ((statusCode == 204) || (statusCode == 205)
|| (statusCode == 304)) {
// No entity body
outputBuffer.addActiveFilter
@@ -1665,6 +1665,10 @@
entityBody = false;
contentDelimitation = true;
}
+ if (statusCode >= 100 && statusCode < 200) {
+ entityBody = false;
+ contentDelimitation = true;
+ }
MessageBytes methodMB = request.method();
if (methodMB.equals("HEAD")) {
Modified: branches/7.0.x/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java
===================================================================
--- branches/7.0.x/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java 2012-04-13 16:38:32 UTC (rev 2021)
+++ branches/7.0.x/java/org/jboss/servlet/http/UpgradableHttpServletResponse.java 2012-04-13 22:31:25 UTC (rev 2022)
@@ -26,11 +26,20 @@
/**
* Upgradable HTTP Servlet response.
- *
- * @author remm
*/
public interface UpgradableHttpServletResponse {
+ /**
+ * Start the connection upgrade process. After calling this method,
+ * data will be available raw from the connection. Calling this method
+ * is optional if no read/write are needed during the upgrade process.
+ */
+ public void startUpgrade();
+
+ /**
+ * Send the switching protocol HTTP status and commit the response by
+ * flushing the buffer.
+ */
public void sendUpgrade()
throws IOException;
Added: branches/7.0.x/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java
===================================================================
--- branches/7.0.x/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java (rev 0)
+++ branches/7.0.x/test/java/org/jboss/web/upgrade/Upgrade00ServletTest.java 2012-04-13 22:31:25 UTC (rev 2022)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.web.upgrade;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.servlet.http.HttpEvent;
+import org.jboss.servlet.http.HttpEventServlet;
+import org.jboss.servlet.http.UpgradableHttpServletResponse;
+
+@WebServlet("/upgrade00")
+public class Upgrade00ServletTest extends HttpServlet implements HttpEventServlet {
+
+ int count = 0;
+
+ public void event(HttpEvent event) throws IOException, ServletException {
+ System.out.println("[" + event.getHttpServletRequest().getSession(true).getId() + "] " + event.getType());
+ ServletInputStream is = null;
+ ServletOutputStream os = null;
+ switch (event.getType()) {
+ case BEGIN:
+ event.setTimeout(20000);
+ HttpServletResponse response = event.getHttpServletResponse();
+ if (response instanceof UpgradableHttpServletResponse) {
+ ((UpgradableHttpServletResponse) response).startUpgrade();
+ } else {
+ throw new IllegalStateException("Cannot upgrade connection");
+ }
+ is = event.getHttpServletRequest().getInputStream();
+ byte[] buf = new byte[1024];
+ int n = is.read(buf);
+ // Do something with the content
+ os = event.getHttpServletResponse().getOutputStream();
+ os.println("Read: " + n);
+ if (n > 0) {
+ os.write(buf, 0, n);
+ }
+ response.setHeader("Upgrade", "WebSocket");
+ response.setHeader("Sec-WebSocket-Protocol", "sample");
+ response.setHeader("Connection", "Upgrade");
+ ((UpgradableHttpServletResponse) response).sendUpgrade();
+ break;
+ case END:
+ break;
+ case ERROR:
+ event.close();
+ break;
+ case EVENT:
+ os = event.getHttpServletResponse().getOutputStream();
+ // Using while (true): Not checking if the connection is available to writing immediately
+ // will cause the write to be performed in blocking mode.
+ // boolean b = true;
+ // while (b) {
+ while (event.isWriteReady()) {
+ if (count % 100 == 0) {
+ os.println((count++) + " ");
+ } else {
+ os.print((count++) + " ");
+ }
+ }
+ //if (event.ready())
+ // os.flush();
+ break;
+ case READ:
+ is = event.getHttpServletRequest().getInputStream();
+ // Using while (true): Not checking if input is available will trigger a blocking
+ // read. No other event should be triggered (the current READ event will be in progress
+ // until the read timeouts, which will trigger an ERROR event due to an IOException).
+ // while (true) {
+ while (is.available() > 0) {
+ int c = is.read();
+ if (c > 0) {
+ System.out.print((char) c);
+ } else {
+ System.out.print(c);
+ break;
+ }
+ }
+ System.out.println();
+ break;
+ case TIMEOUT:
+ // This will cause a generic event to be sent to the servlet every time the connection is idle for
+ // a while.
+ event.resume();
+ break;
+ case WRITE:
+ break;
+ }
+ }
+
+}
12 years, 8 months
JBossWeb SVN: r2021 - in trunk: webapps/docs and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-13 12:38:32 -0400 (Fri, 13 Apr 2012)
New Revision: 2021
Modified:
trunk/java/org/apache/catalina/core/ContainerBase.java
trunk/webapps/docs/changelog.xml
Log:
Add a thread listener bind/unbind around the background processing.
Modified: trunk/java/org/apache/catalina/core/ContainerBase.java
===================================================================
--- trunk/java/org/apache/catalina/core/ContainerBase.java 2012-04-12 15:02:30 UTC (rev 2020)
+++ trunk/java/org/apache/catalina/core/ContainerBase.java 2012-04-13 16:38:32 UTC (rev 2021)
@@ -42,6 +42,7 @@
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
@@ -1598,10 +1599,16 @@
Thread.currentThread().setContextClassLoader
(container.getLoader().getClassLoader());
}
+ if (container instanceof Context) {
+ ((Context) container).getThreadBindingListener().bind();
+ }
container.backgroundProcess();
} catch (Throwable t) {
log.error("Exception invoking periodic operation: ", t);
} finally {
+ if (container instanceof Context) {
+ ((Context) container).getThreadBindingListener().unbind();
+ }
Thread.currentThread().setContextClassLoader(cl);
}
Container[] children = container.findChildren();
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2012-04-12 15:02:30 UTC (rev 2020)
+++ trunk/webapps/docs/changelog.xml 2012-04-13 16:38:32 UTC (rev 2021)
@@ -37,6 +37,9 @@
<fix>
<jboss-jira>AS7-4469</jboss-jira>: Fix SSL session id attribute name (standardized in Servlet 3). (remm)
</fix>
+ <fix>
+ Use the thread listener bind/unbind in the background process. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
12 years, 8 months
JBossWeb SVN: r2020 - in trunk: java/org/apache/coyote/http11 and 4 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-12 11:02:30 -0400 (Thu, 12 Apr 2012)
New Revision: 2020
Modified:
trunk/java/org/apache/catalina/Globals.java
trunk/java/org/apache/coyote/http11/Http11Processor.java
trunk/java/org/apache/tomcat/util/buf/EncodingToCharset.java
trunk/java/org/apache/tomcat/util/net/Constants.java
trunk/java/org/apache/tomcat/util/net/SSLSupport.java
trunk/java/org/apache/tomcat/util/net/jsse/JSSESupport.java
trunk/webapps/docs/changelog.xml
Log:
AS7-4469: Also fix session id attribute that got standardized in Servlet 3.
Modified: trunk/java/org/apache/catalina/Globals.java
===================================================================
--- trunk/java/org/apache/catalina/Globals.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/catalina/Globals.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -119,6 +119,8 @@
* for this SSL connection (as an object of type java.lang.String).
*/
public static final String SSL_SESSION_ID_ATTR =
+ "javax.servlet.request.ssl_session_id";
+ public static final String SSL_SESSION_ID_OLD_ATTR =
"javax.servlet.request.ssl_session";
Modified: trunk/java/org/apache/coyote/http11/Http11Processor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11Processor.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/coyote/http11/Http11Processor.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -1054,20 +1054,16 @@
if (sslSupport != null) {
Object sslO = sslSupport.getCipherSuite();
if (sslO != null)
- request.setAttribute
- (SSLSupport.CIPHER_SUITE_KEY, sslO);
+ request.setAttribute(org.apache.tomcat.util.net.Constants.CIPHER_SUITE_KEY, sslO);
sslO = sslSupport.getPeerCertificateChain(false);
if (sslO != null)
- request.setAttribute
- (SSLSupport.CERTIFICATE_KEY, sslO);
+ request.setAttribute(org.apache.tomcat.util.net.Constants.CERTIFICATE_KEY, sslO);
sslO = sslSupport.getKeySize();
if (sslO != null)
- request.setAttribute
- (SSLSupport.KEY_SIZE_KEY, sslO);
+ request.setAttribute(org.apache.tomcat.util.net.Constants.KEY_SIZE_KEY, sslO);
sslO = sslSupport.getSessionId();
if (sslO != null)
- request.setAttribute
- (SSLSupport.SESSION_ID_KEY, sslO);
+ request.setAttribute(org.apache.tomcat.util.net.Constants.SESSION_ID_KEY, sslO);
}
} catch (Exception e) {
log.warn(sm.getString("http11processor.socket.ssl"), e);
@@ -1142,9 +1138,8 @@
}
try {
Object sslO = sslSupport.getPeerCertificateChain(true);
- if( sslO != null) {
- request.setAttribute
- (SSLSupport.CERTIFICATE_KEY, sslO);
+ if (sslO != null) {
+ request.setAttribute(org.apache.tomcat.util.net.Constants.CERTIFICATE_KEY, sslO);
}
} catch (Exception e) {
log.warn(sm.getString("http11processor.socket.ssl"), e);
Modified: trunk/java/org/apache/tomcat/util/buf/EncodingToCharset.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/EncodingToCharset.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/tomcat/util/buf/EncodingToCharset.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -35,6 +35,9 @@
private static final Map<String, Charset> encodingToCharsetCache =
new HashMap<String, Charset>();
+ public static final Charset ISO_8859_1;
+ public static final Charset UTF_8;
+
static {
for (Charset charset: Charset.availableCharsets().values()) {
encodingToCharsetCache.put(charset.name().toUpperCase(Locale.US), charset);
@@ -42,6 +45,8 @@
encodingToCharsetCache.put(alias.toUpperCase(Locale.US), charset);
}
}
+ ISO_8859_1 = encodingToCharsetCache.get("ISO-8859-1");
+ UTF_8 = encodingToCharsetCache.get("UTF-8");
}
public static Charset toCharset(String encoding)
Modified: trunk/java/org/apache/tomcat/util/net/Constants.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/Constants.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/tomcat/util/net/Constants.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -47,7 +47,7 @@
* The Request attribute key for the session id.
* This one is a Tomcat extension to the Servlet spec.
*/
- public static final String SESSION_ID_KEY = "javax.servlet.request.ssl_session";
+ public static final String SESSION_ID_KEY = "javax.servlet.request.ssl_session_id";
}
Modified: trunk/java/org/apache/tomcat/util/net/SSLSupport.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/SSLSupport.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/tomcat/util/net/SSLSupport.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -27,28 +27,8 @@
*/
public interface SSLSupport {
- /**
- * The Request attribute key for the cipher suite.
- */
- public static final String CIPHER_SUITE_KEY = "javax.servlet.request.cipher_suite";
/**
- * The Request attribute key for the key size.
- */
- public static final String KEY_SIZE_KEY = "javax.servlet.request.key_size";
-
- /**
- * The Request attribute key for the client certificate chain.
- */
- public static final String CERTIFICATE_KEY = "javax.servlet.request.X509Certificate";
-
- /**
- * The Request attribute key for the session id.
- * This one is a Tomcat extension to the Servlet spec.
- */
- public static final String SESSION_ID_KEY = "javax.servlet.request.ssl_session";
-
- /**
* A mapping table to determine the number of effective bits in the key
* when using a cipher suite containing the specified cipher name. The
* underlying data came from the TLS Specification (RFC 2246), Appendix C.
Modified: trunk/java/org/apache/tomcat/util/net/jsse/JSSESupport.java
===================================================================
--- trunk/java/org/apache/tomcat/util/net/jsse/JSSESupport.java 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/java/org/apache/tomcat/util/net/jsse/JSSESupport.java 2012-04-12 15:02:30 UTC (rev 2020)
@@ -31,6 +31,7 @@
import javax.net.ssl.SSLSocket;
import javax.security.cert.X509Certificate;
+import org.apache.tomcat.util.net.Constants;
import org.apache.tomcat.util.net.SSLSupport;
/** JSSESupport
@@ -195,7 +196,7 @@
SSLSupport.CipherData c_aux[]=ciphers;
if (session == null)
return null;
- Integer keySize = (Integer) session.getValue(KEY_SIZE_KEY);
+ Integer keySize = (Integer) session.getValue(Constants.KEY_SIZE_KEY);
if (keySize == null) {
int size = 0;
String cipherSuite = session.getCipherSuite();
@@ -205,8 +206,8 @@
break;
}
}
- keySize = new Integer(size);
- session.putValue(KEY_SIZE_KEY, keySize);
+ keySize = Integer.valueOf(size);
+ session.putValue(Constants.KEY_SIZE_KEY, keySize);
}
return keySize;
}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2012-04-12 14:22:08 UTC (rev 2019)
+++ trunk/webapps/docs/changelog.xml 2012-04-12 15:02:30 UTC (rev 2020)
@@ -34,6 +34,9 @@
<fix>
<jboss-jira>AS7-4469</jboss-jira>: Rebase SSL valve used by mod_headers. (remm)
</fix>
+ <fix>
+ <jboss-jira>AS7-4469</jboss-jira>: Fix SSL session id attribute name (standardized in Servlet 3). (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
12 years, 8 months
JBossWeb SVN: r2019 - in trunk: webapps/docs and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-12 10:22:08 -0400 (Thu, 12 Apr 2012)
New Revision: 2019
Modified:
trunk/java/org/apache/catalina/valves/LocalStrings.properties
trunk/java/org/apache/catalina/valves/SSLValve.java
trunk/webapps/docs/changelog.xml
Log:
AS7-4469: Rebase SSL valve.
Modified: trunk/java/org/apache/catalina/valves/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/valves/LocalStrings.properties 2012-04-10 01:06:26 UTC (rev 2018)
+++ trunk/java/org/apache/catalina/valves/LocalStrings.properties 2012-04-12 14:22:08 UTC (rev 2019)
@@ -29,6 +29,10 @@
# Remote IP valve
remoteIpValve.syntax=Invalid regular expressions [{0}] provided.
+# SSL valve
+sslValve.certError=Failed to process certificate string [{0}] to create a java.security.cert.X509Certificate object
+sslValve.invalidProvider=The SSL provider specified on the connector associated with this request of [{0}] is invalid. The certificate data could not be processed.
+
# HTTP status reports
http.100=The client may continue ({0}).
http.101=The server is switching protocols according to the "Upgrade" header ({0}).
Modified: trunk/java/org/apache/catalina/valves/SSLValve.java
===================================================================
--- trunk/java/org/apache/catalina/valves/SSLValve.java 2012-04-10 01:06:26 UTC (rev 2018)
+++ trunk/java/org/apache/catalina/valves/SSLValve.java 2012-04-12 14:22:08 UTC (rev 2019)
@@ -14,102 +14,116 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.catalina.valves;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.ByteArrayInputStream;
-
+import java.security.NoSuchProviderException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.servlet.ServletException;
-import org.apache.catalina.valves.ValveBase;
+import org.apache.catalina.Globals;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
-import org.apache.catalina.util.StringManager;
+import org.apache.tomcat.util.buf.EncodingToCharset;
+import org.jboss.logging.Logger;
-/*
- * Valve to fill the SSL informations in the request
- * mod_header is used to fill the headers and the valve
- * will fill the parameters of the request.
+/**
+ * When using mod_proxy_http, the client SSL information is not included in the
+ * protocol (unlike mod_jk and mod_proxy_ajp). To make the client SSL
+ * information available to Tomcat, some additional configuration is required.
+ * In httpd, mod_headers is used to add the SSL information as HTTP headers. In
+ * Tomcat, this valve is used to read the information from the HTTP headers and
+ * insert it into the request.<p>
+ *
+ * <b>Note: Ensure that the headers are always set by httpd for all requests to
+ * prevent a client spoofing SSL information by sending fake headers. </b><p>
+ *
* In httpd.conf add the following:
- * <IfModule ssl_module>
+ * <pre>
+ * <IfModule ssl_module>
* RequestHeader set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"
* RequestHeader set SSL_CIPHER "%{SSL_CIPHER}s"
* RequestHeader set SSL_SESSION_ID "%{SSL_SESSION_ID}s"
* RequestHeader set SSL_CIPHER_USEKEYSIZE "%{SSL_CIPHER_USEKEYSIZE}s"
- * </IfModule>
+ * </IfModule>
+ * </pre>
*
- * @author Jean-Frederic Clere
- * @version $Revision$, $Date$
+ * In server.xml, configure this valve under the Engine element in server.xml:
+ * <pre>
+ * <Engine ...>
+ * <Valve className="org.apache.catalina.valves.SSLValve" />
+ * <Host ... />
+ * </Engine>
+ * </pre>
*/
+public class SSLValve extends ValveBase {
-public class SSLValve
- extends ValveBase {
-/*
- private static final String info =
- "SSLValve/1.0";
- protected static StringManager sm =
- StringManager.getManager(Constants.Package);
- public String getInfo() {
- return (info);
+ private static Logger log = Logger.getLogger(SSLValve.class);
+
+ //------------------------------------------------------ Constructor
+ public SSLValve() {
}
- public String toString() {
- StringBuffer sb = new StringBuffer("SSLValve[");
- if (container != null)
- sb.append(container.getName());
- sb.append("]");
- return (sb.toString());
- }
- */
+
public String mygetHeader(Request request, String header) {
String strcert0 = request.getHeader(header);
- if (strcert0 == null)
+ if (strcert0 == null) {
return null;
+ }
/* mod_header writes "(null)" when the ssl variable is no filled */
- if ("(null)".equals(strcert0))
+ if ("(null)".equals(strcert0)) {
return null;
+ }
return strcert0;
- }
+ }
+
+ @Override
public void invoke(Request request, Response response)
throws IOException, ServletException {
-
/* mod_header converts the '\n' into ' ' so we have to rebuild the client certificate */
String strcert0 = mygetHeader(request, "ssl_client_cert");
if (strcert0 != null && strcert0.length()>28) {
String strcert1 = strcert0.replace(' ', '\n');
String strcert2 = strcert1.substring(28, strcert1.length()-26);
- String strcert3 = new String("-----BEGIN CERTIFICATE-----\n");
+ String strcert3 = "-----BEGIN CERTIFICATE-----\n";
String strcert4 = strcert3.concat(strcert2);
String strcerts = strcert4.concat("\n-----END CERTIFICATE-----\n");
- // ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes("UTF-8"));
- ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes());
+ ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes(EncodingToCharset.ISO_8859_1));
X509Certificate jsseCerts[] = null;
+ String providerName = (String) request.getConnector().getProperty(
+ "clientCertProvider");
try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ CertificateFactory cf;
+ if (providerName == null) {
+ cf = CertificateFactory.getInstance("X.509");
+ } else {
+ cf = CertificateFactory.getInstance("X.509", providerName);
+ }
X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
jsseCerts = new X509Certificate[1];
jsseCerts[0] = cert;
} catch (java.security.cert.CertificateException e) {
- System.out.println("SSLValve failed " + strcerts);
- System.out.println("SSLValve failed " + e);
+ log.warn(sm.getString("sslValve.certError", strcerts), e);
+ } catch (NoSuchProviderException e) {
+ log.error(sm.getString("sslValve.invalidProvider", providerName), e);
}
- request.setAttribute("javax.servlet.request.X509Certificate", jsseCerts);
+ request.setAttribute(Globals.CERTIFICATES_ATTR, jsseCerts);
}
strcert0 = mygetHeader(request, "ssl_cipher");
if (strcert0 != null) {
- request.setAttribute("javax.servlet.request.cipher_suite", strcert0);
+ request.setAttribute(Globals.CIPHER_SUITE_ATTR, strcert0);
}
strcert0 = mygetHeader(request, "ssl_session_id");
if (strcert0 != null) {
- request.setAttribute("javax.servlet.request.ssl_session", strcert0);
+ request.setAttribute(Globals.SSL_SESSION_ID_ATTR, strcert0);
}
strcert0 = mygetHeader(request, "ssl_cipher_usekeysize");
if (strcert0 != null) {
- request.setAttribute("javax.servlet.request.key_size", strcert0);
+ request.setAttribute(Globals.KEY_SIZE_ATTR, Integer.valueOf(strcert0));
}
getNext().invoke(request, response);
}
+
}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2012-04-10 01:06:26 UTC (rev 2018)
+++ trunk/webapps/docs/changelog.xml 2012-04-12 14:22:08 UTC (rev 2019)
@@ -31,6 +31,9 @@
<add>
Protocol upgrade API. (remm)
</add>
+ <fix>
+ <jboss-jira>AS7-4469</jboss-jira>: Rebase SSL valve used by mod_headers. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
12 years, 8 months
JBossWeb SVN: r2017 - in trunk: java/org/apache/jasper/runtime and 1 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2012-04-06 11:40:00 -0400 (Fri, 06 Apr 2012)
New Revision: 2017
Modified:
trunk/java/org/apache/jasper/compiler/Validator.java
trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
trunk/webapps/docs/changelog.xml
Log:
Use per webapp expression factory.
Modified: trunk/java/org/apache/jasper/compiler/Validator.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Validator.java 2012-04-03 03:42:15 UTC (rev 2016)
+++ trunk/java/org/apache/jasper/compiler/Validator.java 2012-04-06 15:40:00 UTC (rev 2017)
@@ -27,6 +27,7 @@
import javax.el.ELException;
import javax.el.ExpressionFactory;
import javax.el.FunctionMapper;
+import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.tagext.FunctionInfo;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.PageData;
@@ -37,7 +38,6 @@
import javax.servlet.jsp.tagext.TagLibraryInfo;
import javax.servlet.jsp.tagext.ValidationMessage;
-import org.apache.el.lang.ELSupport;
import org.apache.jasper.JasperException;
import org.apache.jasper.el.ELContextImpl;
import org.xml.sax.Attributes;
@@ -497,8 +497,7 @@
new JspUtil.ValidAttribute("doctype-public"),
new JspUtil.ValidAttribute("doctype-system") };
- private static final ExpressionFactory EXPRESSION_FACTORY =
- ExpressionFactory.newInstance();
+ private final ExpressionFactory expressionFactory;
/*
* Constructor
@@ -507,6 +506,11 @@
this.pageInfo = compiler.getPageInfo();
this.err = compiler.getErrorDispatcher();
this.loader = compiler.getCompilationContext().getClassLoader();
+ // Get the cached EL expression factory for this context
+ expressionFactory =
+ JspFactory.getDefaultFactory().getJspApplicationContext(
+ compiler.getCompilationContext().getServletContext()).
+ getExpressionFactory();
}
public void visit(Node.JspRoot n) throws JasperException {
@@ -1166,7 +1170,7 @@
Boolean.TYPE == expectedClass ||
expectedClass.isEnum()) {
try {
- EXPRESSION_FACTORY.coerceToType(attrs.getValue(i), expectedClass);
+ expressionFactory.coerceToType(attrs.getValue(i), expectedClass);
} catch (Exception e) {
err.jspError
(n, "jsp.error.coerce_to_type",
Modified: trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java
===================================================================
--- trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java 2012-04-03 03:42:15 UTC (rev 2016)
+++ trunk/java/org/apache/jasper/runtime/JspApplicationContextImpl.java 2012-04-06 15:40:00 UTC (rev 2017)
@@ -50,8 +50,8 @@
private final static String KEY = JspApplicationContextImpl.class.getName();
- private final static ExpressionFactory expressionFactory =
- ExpressionFactory.newInstance();
+ private final ExpressionFactory expressionFactory =
+ ExpressionFactory.newInstance();
private final List<ELContextListener> contextListeners = new ArrayList<ELContextListener>();
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2012-04-03 03:42:15 UTC (rev 2016)
+++ trunk/webapps/docs/changelog.xml 2012-04-06 15:40:00 UTC (rev 2017)
@@ -41,6 +41,9 @@
<fix>
<bug>52970</bug>: Fix enum as method invocation argument in EL. (markt)
</fix>
+ <fix>
+ Use per webapp expression factory. (markt)
+ </fix>
</changelog>
</subsection>
</section>
12 years, 8 months