Issue #8431 Servlet 6 allows dynamic listeners to call getters (#8432)

This commit is contained in:
Jan Bartel 2022-08-10 16:34:50 +10:00 committed by GitHub
parent 42f72268cf
commit 21944ab95c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View File

@ -2593,9 +2593,6 @@ public class ServletContextHandler extends ContextHandler implements Graceful
@Override
public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
{
if (!_enabled)
throw new UnsupportedOperationException();
if (_sessionHandler != null)
return _sessionHandler.getDefaultSessionTrackingModes();
return null;
@ -2604,9 +2601,6 @@ public class ServletContextHandler extends ContextHandler implements Graceful
@Override
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
{
if (!_enabled)
throw new UnsupportedOperationException();
if (_sessionHandler != null)
return _sessionHandler.getEffectiveSessionTrackingModes();
return null;
@ -2698,9 +2692,7 @@ public class ServletContextHandler extends ContextHandler implements Graceful
{
if (!isStarting())
throw new IllegalStateException();
if (!_enabled)
throw new UnsupportedOperationException();
int timeout = -1;
if (_sessionHandler != null)
{
@ -3259,9 +3251,6 @@ public class ServletContextHandler extends ContextHandler implements Graceful
@Override
public ClassLoader getClassLoader()
{
if (!_enabled)
throw new UnsupportedOperationException();
// no security manager just return the classloader
ClassLoader classLoader = ServletContextHandler.this.getClassLoader();
if (!isUsingSecurityManager())

View File

@ -297,24 +297,24 @@ public class ServletContextHandlerTest
try
{
sce.getServletContext().getDefaultSessionTrackingModes();
sce.getServletContext().setAttribute("MyContextListener.defaultSessionTrackingModes", Boolean.FALSE);
sce.getServletContext().setAttribute("MyContextListener.defaultSessionTrackingModes", Boolean.TRUE);
}
catch (UnsupportedOperationException e)
{
//Should NOT be able to call getDefaultSessionTrackingModes from programmatic SCL
sce.getServletContext().setAttribute("MyContextListener.defaultSessionTrackingModes", Boolean.TRUE);
//Servlet 6, should be able to call getDefaultSessionTrackingModes from programmatic SCL
sce.getServletContext().setAttribute("MyContextListener.defaultSessionTrackingModes", Boolean.FALSE);
}
assertNull(sce.getServletContext().getAttribute("MyContextListener.effectiveSessionTrackingModes"));
try
{
sce.getServletContext().getEffectiveSessionTrackingModes();
sce.getServletContext().setAttribute("MyContextListener.effectiveSessionTrackingModes", Boolean.FALSE);
sce.getServletContext().setAttribute("MyContextListener.effectiveSessionTrackingModes", Boolean.TRUE);
}
catch (UnsupportedOperationException e)
{
//Should NOT be able to call getEffectiveSessionTrackingModes from programmatic SCL
sce.getServletContext().setAttribute("MyContextListener.effectiveSessionTrackingModes", Boolean.TRUE);
//Servlet 6,, should be able to call getEffectiveSessionTrackingModes from programmatic SCL
sce.getServletContext().setAttribute("MyContextListener.effectiveSessionTrackingModes", Boolean.FALSE);
}
assertNull(sce.getServletContext().getAttribute("MyContextListener.setSessionTrackingModes"));
@ -345,12 +345,12 @@ public class ServletContextHandlerTest
try
{
sce.getServletContext().getSessionTimeout();
sce.getServletContext().setAttribute("MyContextListener.getSessionTimeout", Boolean.FALSE);
sce.getServletContext().setAttribute("MyContextListener.getSessionTimeout", Boolean.TRUE);
}
catch (UnsupportedOperationException e)
{
//Should NOT be able to call getSessionTimeout from this SCL
sce.getServletContext().setAttribute("MyContextListener.getSessionTimeout", Boolean.TRUE);
//Servlet 6 should be able to call getSessionTimeout from this SCL
sce.getServletContext().setAttribute("MyContextListener.getSessionTimeout", Boolean.FALSE);
}
}
}