Merge branch 'master' into jetty-8

This commit is contained in:
Jesse McConnell 2012-08-16 17:10:35 -05:00
commit c82871b10f
13 changed files with 521 additions and 2 deletions

15
header-template.txt Normal file
View File

@ -0,0 +1,15 @@
========================================================================
Copyright (c) ${copyright-range} Mort Bay Consulting Pty. Ltd.
------------------------------------------------------------------------
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
and Apache License v2.0 which accompanies this distribution.
The Eclipse Public License is available at
http://www.eclipse.org/legal/epl-v10.html
The Apache License v2.0 is available at
http://www.opensource.org/licenses/apache2.0.php
You may elect to redistribute this code under either of these licenses.
========================================================================

View File

@ -188,8 +188,8 @@ public class FormAuthenticator extends LoginAuthenticator
if (!mandatory)
return _deferred;
if (isLoginOrErrorPage(URIUtil.addPaths(request.getServletPath(),request.getPathInfo())))
return Authentication.NOT_CHECKED;
if (isLoginOrErrorPage(URIUtil.addPaths(request.getServletPath(),request.getPathInfo())) &&!DeferredAuthentication.isDeferred(response))
return _deferred;
HttpSession session = request.getSession(true);

View File

@ -0,0 +1,43 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
import java.awt.Toolkit;
/**
* AWTLeakPreventer
*
* See https://issues.jboss.org/browse/AS7-3733
*
* The java.awt.Toolkit class has a static field that is the default toolkit.
* Creating the default toolkit causes the creation of an EventQueue, which has a
* classloader field initialized by the thread context class loader.
*
*/
public class AWTLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
LOG.debug("Pinning classloader for java.awt.EventQueue using "+loader);
Toolkit.getDefaultToolkit();
}
}

View File

@ -0,0 +1,57 @@
// ========================================================================
// Copyright (c) 2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.preventers;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* AbstractLeakPreventer
*
* Abstract base class for code that seeks to avoid pinning of webapp classloaders by using the jetty classloader to
* proactively call the code that pins them (generally pinned as static data members, or as static
* data members that are daemon threads (which use the context classloader)).
*
* Instances of subclasses of this class should be set with Server.addBean(), which will
* ensure that they are called when the Server instance starts up, which will have the jetty
* classloader in scope.
*
*/
public abstract class AbstractLeakPreventer extends AbstractLifeCycle
{
protected static final Logger LOG = Log.getLogger(AbstractLeakPreventer.class);
/* ------------------------------------------------------------ */
abstract public void prevent(ClassLoader loader);
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
prevent(getClass().getClassLoader());
super.doStart();
}
finally
{
Thread.currentThread().setContextClassLoader(loader);
}
}
}

View File

@ -0,0 +1,36 @@
// ========================================================================
// Copyright (c) 2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.preventers;
import javax.imageio.ImageIO;
/**
* AppContextLeakPreventer
*
* Cause the classloader that is pinned by AppContext.getAppContext() to be
* a container or system classloader, not a webapp classloader.
*
* Inspired by Tomcat JreMemoryLeakPrevention.
*/
public class AppContextLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
@Override
public void prevent(ClassLoader loader)
{
LOG.debug("Pinning classloader for AppContext.getContext() with "+loader);
ImageIO.getUseCache();
}
}

View File

@ -0,0 +1,52 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* DOMLeakPreventer
*
* See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6916498
*
* Prevent the RuntimeException that is a static member of AbstractDOMParser
* from pinning a webapp classloader by causing it to be set here by a non-webapp classloader.
*
* Note that according to the bug report, a heap dump may not identify the GCRoot, making
* it difficult to identify the cause of the leak.
*
*/
public class DOMLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
factory.newDocumentBuilder();
}
catch (Exception e)
{
LOG.warn(e);
}
}
}

View File

@ -0,0 +1,37 @@
// ========================================================================
// Copyright (c) 2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.preventers;
import java.sql.DriverManager;
/**
* DriverManagerLeakPreventer
*
* Cause DriverManager.getCallerClassLoader() to be called, which will pin the classloader.
*
* Inspired by Tomcat JreMemoryLeakPrevention.
*/
public class DriverManagerLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
@Override
public void prevent(ClassLoader loader)
{
LOG.debug("Pinning DriverManager classloader with "+loader);
DriverManager.getDrivers();
}
}

View File

@ -0,0 +1,60 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
import java.lang.reflect.Method;
/**
* GCThreadLeakPreventer
*
* Prevents a call to sun.misc.GC.requestLatency pinning a webapp classloader
* by calling it with a non-webapp classloader. The problem appears to be that
* when this method is called, a daemon thread is created which takes the
* context classloader. A known caller of this method is the RMI impl. See
* http://stackoverflow.com/questions/6626680/does-java-garbage-collection-log-entry-full-gc-system-mean-some-class-called
*
* This preventer will start the thread with the longest possible interval, although
* subsequent calls can vary that. Recommend to only use this class if you're doing
* RMI.
*
* Inspired by Tomcat JreMemoryLeakPrevention.
*
*/
public class GCThreadLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
try
{
Class clazz = Class.forName("sun.misc.GC");
Method requestLatency = clazz.getMethod("requestLatency", new Class[] {long.class});
requestLatency.invoke(null, Long.valueOf(Long.MAX_VALUE-1));
}
catch (ClassNotFoundException e)
{
LOG.ignore(e);
}
catch (Exception e)
{
LOG.warn(e);
}
}
}

View File

@ -0,0 +1,45 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
/**
* Java2DLeakPreventer
*
* Prevent pinning of webapp classloader by pre-loading sun.java2d.Disposer class
* before webapp classloaders are created.
*
* See https://issues.apache.org/bugzilla/show_bug.cgi?id=51687
*
*/
public class Java2DLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("sun.java2d.Disposer", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.ignore(e);
}
}
}

View File

@ -0,0 +1,47 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
/**
* LDAPLeakPreventer
*
* If com.sun.jndi.LdapPoolManager class is loaded and the system property
* com.sun.jndi.ldap.connect.pool.timeout is set to a nonzero value, a daemon
* thread is started which can pin a webapp classloader if it is the first to
* load the LdapPoolManager.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*
*/
public class LDAPLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("com.sun.jndi.LdapPoolManager", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.ignore(e);
}
}
}

View File

@ -0,0 +1,45 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
/**
* LoginConfigurationLeakPreventer
*
* The javax.security.auth.login.Configuration class keeps a static reference to the
* thread context classloader. We prevent a webapp context classloader being used for
* that by invoking the classloading here.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*/
public class LoginConfigurationLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("javax.security.auth.login.Configuration", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.warn(e);
}
}
}

View File

@ -0,0 +1,40 @@
//========================================================================
//Copyright 2012 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.eclipse.jetty.util.preventers;
import java.security.Security;
/**
* SecurityProviderLeakPreventer
*
* Some security providers, such as sun.security.pkcs11.SunPKCS11 start a deamon thread,
* which will use the thread context classloader. Load them here to ensure the classloader
* is not a webapp classloader.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*/
public class SecurityProviderLeakPreventer extends AbstractLeakPreventer
{
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.util.preventers.AbstractLeakPreventer#prevent(java.lang.ClassLoader)
*/
@Override
public void prevent(ClassLoader loader)
{
Security.getProviders();
}
}

42
pom.xml
View File

@ -729,5 +729,47 @@
</plugins>
</build>
</profile>
<profile>
<id>license-check</id>
<build>
<plugins>
<plugin>
<inherited>false</inherited>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.10.b1</version>
<configuration>
<header>header-template.txt</header>
<failIfMissing>true</failIfMissing>
<aggregate>true</aggregate>
<strictCheck>true</strictCheck>
<properties>
<copyright-range>${project.inceptionYear}-2012</copyright-range>
</properties>
<mapping>
<java>DOUBLESLASH_STYLE</java>
</mapping>
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>jetty-util/src/main/java/org/eclipse/jetty/util/security/UnixCrypt.java</exclude>
<exclude>jetty-policy/src/main/java/org/eclipse/jetty/policy/loader/DefaultPolicyLoader.java</exclude>
<exclude>jetty-policy/src/main/java/org/eclipse/jetty/policy/loader/PolicyFileScanner.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>check-headers</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>