Merge remote-tracking branch 'origin/master' into jetty-9.1

This commit is contained in:
Greg Wilkins 2013-09-16 12:10:55 +10:00
commit 5a801d398d
4 changed files with 84 additions and 38 deletions

View File

@ -1177,16 +1177,30 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
while (target.startsWith("//"))
target=URIUtil.compactPath(target);
boolean isProtected = false;
int i=0;
while (!isProtected && i<_protectedTargets.length)
for (int i=0; i<_protectedTargets.length; i++)
{
isProtected = StringUtil.startsWithIgnoreCase(target, _protectedTargets[i++]);
String t=_protectedTargets[i];
if (StringUtil.startsWithIgnoreCase(target,t))
{
if (target.length()==t.length())
return true;
// Check that the target prefix really is a path segment, thus
// it can end with /, a query, a target or a parameter
char c=target.charAt(t.length());
if (c=='/'||c=='?'||c=='#'||c==';')
return true;
}
}
return isProtected;
return false;
}
/* ------------------------------------------------------------ */
/**
* @param targets Array of URL prefix. Each prefix is in the form /path and will match
* either /path exactly or /path/anything
*/
public void setProtectedTargets (String[] targets)
{
if (targets == null)
@ -1199,6 +1213,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
System.arraycopy(targets, 0, _protectedTargets, 0, targets.length);
}
/* ------------------------------------------------------------ */
public String[] getProtectedTargets ()
{
if (_protectedTargets == null)

View File

@ -437,6 +437,7 @@ public class ContextHandlerTest
assertTrue(handler.isProtectedTarget("/foo-inf/x/y/z"));
assertFalse(handler.isProtectedTarget("/foo/x/y/z"));
assertTrue(handler.isProtectedTarget("/foo-inf?x=y&z=1"));
assertFalse(handler.isProtectedTarget("/foo-inf-bar"));
protectedTargets = new String[4];
System.arraycopy(handler.getProtectedTargets(), 0, protectedTargets, 0, 2);

View File

@ -22,6 +22,12 @@ import java.util.Collection;
public interface Container
{
/* ------------------------------------------------------------ */
/**
* Add a bean. If the bean is-a {@link Listener}, then also do an implicit {@link #addEventListener(Listener)}.
* @param o the bean object to add
* @return true if the bean was added, false if it was already present
*/
public boolean addBean(Object o);
/**
@ -45,10 +51,25 @@ public interface Container
/**
* Removes the given bean.
* If the bean is-a {@link Listener}, then also do an implicit {@link #removeEventListener(Listener)}.
* @return whether the bean was removed
*/
public boolean removeBean(Object o);
/**
* Add an event listener.
* @see Container#addBean(Object), which also adds listeners if the bean is-a Listener
* @param listener
*/
public void addEventListener(Listener listener);
/**
* Remove an event listener.
* @see Container#removeBean(Object), which also adds listeners if the bean is-a Listener
* @param listener
*/
public void removeEventListener(Listener listener);
/**
* A listener for Container events.
* If an added bean implements this interface it will receive the events

View File

@ -27,6 +27,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.component.Container.Listener;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -239,25 +240,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
// if the bean is a Listener
if (o instanceof Container.Listener)
{
Container.Listener listener = (Container.Listener)o;
_listeners.add(listener);
// tell it about existing beans
for (Bean b:_beans)
{
listener.beanAdded(this,b._bean);
// handle inheritance
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
{
if (b._bean instanceof ContainerLifeCycle)
((ContainerLifeCycle)b._bean).addBean(listener, false);
else
((Container)b._bean).addBean(listener);
}
}
}
addEventListener((Container.Listener)o);
// Add the bean
_beans.add(new_bean);
@ -324,6 +307,31 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
return true;
}
@Override
public void addEventListener(Container.Listener listener)
{
if (_listeners.contains(listener))
return;
_listeners.add(listener);
// tell it about existing beans
for (Bean b:_beans)
{
listener.beanAdded(this,b._bean);
// handle inheritance
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
{
if (b._bean instanceof ContainerLifeCycle)
((ContainerLifeCycle)b._bean).addBean(listener, false);
else
((Container)b._bean).addBean(listener);
}
}
}
/**
* Manages a bean already contained by this aggregate, so that it is started/stopped/destroyed with this
@ -479,20 +487,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
l.beanRemoved(this,bean._bean);
if (bean._bean instanceof Container.Listener)
{
Container.Listener listener = (Container.Listener)bean._bean;
if (_listeners.remove(listener))
{
// remove existing beans
for (Bean b:_beans)
{
listener.beanRemoved(this,b._bean);
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
((Container)b._bean).removeBean(listener);
}
}
}
removeEventListener((Container.Listener)bean._bean);
// stop managed beans
if (bean._managed==Managed.MANAGED && bean._bean instanceof LifeCycle)
@ -515,7 +510,21 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
return false;
}
@Override
public void removeEventListener(Container.Listener listener)
{
if (_listeners.remove(listener))
{
// remove existing beans
for (Bean b:_beans)
{
listener.beanRemoved(this,b._bean);
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
((Container)b._bean).removeBean(listener);
}
}
}
@Override
public void setStopTimeout(long stopTimeout)