Author: remy.maucherat(a)jboss.com
Date: 2009-04-07 13:21:32 -0400 (Tue, 07 Apr 2009)
New Revision: 990
Modified:
trunk/java/org/apache/catalina/Context.java
trunk/java/org/apache/catalina/Wrapper.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/catalina/core/StandardWrapperValve.java
trunk/java/org/apache/catalina/startup/ContextConfig.java
Log:
- Add call to the login method. Error reporting could probably use some work (in some
cases, a SE could be thrown).
- Add tracking of chains.
Modified: trunk/java/org/apache/catalina/Context.java
===================================================================
--- trunk/java/org/apache/catalina/Context.java 2009-04-07 01:50:57 UTC (rev 989)
+++ trunk/java/org/apache/catalina/Context.java 2009-04-07 17:21:32 UTC (rev 990)
@@ -80,6 +80,21 @@
/**
+ * Return the authenticator that is configured for this context, or
+ * null if no authenticator has been configured.
+ */
+ public Authenticator getAuthenticator();
+
+
+ /**
+ * Set the authenticator for this context.
+ *
+ * @param authenticator the new Authenticator for this context
+ */
+ public void setAuthenticator(Authenticator authenticator);
+
+
+ /**
* Store the set of initialized application event listener objects,
* in the order they were specified in the web application deployment
* descriptor, for this application.
Modified: trunk/java/org/apache/catalina/Wrapper.java
===================================================================
--- trunk/java/org/apache/catalina/Wrapper.java 2009-04-07 01:50:57 UTC (rev 989)
+++ trunk/java/org/apache/catalina/Wrapper.java 2009-04-07 17:21:32 UTC (rev 990)
@@ -24,7 +24,9 @@
import javax.servlet.ServletRegistration;
import javax.servlet.UnavailableException;
+import org.apache.catalina.util.InstanceSupport;
+
/**
* A <b>Wrapper</b> is a Container that represents an individual servlet
* definition from the deployment descriptor of the web application. It
@@ -102,6 +104,12 @@
/**
+ * Return the InstanceSupport object for this Wrapper instance.
+ */
+ public InstanceSupport getInstanceSupport();
+
+
+ /**
* Return the context-relative URI of the JSP file for this servlet.
*/
public String getJspFile();
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-04-07 01:50:57 UTC (rev
989)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-04-07 17:21:32 UTC (rev
990)
@@ -2851,9 +2851,8 @@
}
public boolean isAsyncSupported() {
- // FIXME: Normally, this should be about checking that the Servlet has
- // async supported, and that all filters in the chain do too ?
- return false;
+ // FIXME: Check all the filter chain
+ return true;
}
public void setAsyncTimeout(long timeout) {
@@ -2876,22 +2875,23 @@
public boolean login(HttpServletResponse response) throws IOException,
ServletException {
- // FIXME: wrapped response is super evil :(
- if (response instanceof ResponseFacade) {
-
+ // FIXME: Ignoring the response param, which will hopefully go away
+ if (context.getAuthenticator() != null) {
+ return context.getAuthenticator().login(this, this.response);
+ } else {
+ // FIXME: error message for no available authenticator
+ throw new ServletException();
}
- return false;
}
public void login(String username, String password) throws ServletException {
Realm realm = context.getRealm();
userPrincipal = realm.authenticate(username, password);
- // FIXME: not sure how the login should be completed: set in the session, SSO,
etc etc ?
- // (apparently, no according to the javadoc)
if (userPrincipal == null) {
throw new ServletException();
}
- authType = "?";
+ // FIXME: authType value
+ authType = "LOGIN";
}
public void logout() throws ServletException {
Modified: trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-04-07 01:50:57 UTC
(rev 989)
+++ trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-04-07 17:21:32 UTC
(rev 990)
@@ -622,21 +622,21 @@
// Get the FilterChain Here
ApplicationFilterFactory factory = ApplicationFilterFactory.getInstance();
- ApplicationFilterChain filterChain = factory.createFilterChain(request,
- wrapper,servlet);
+ ApplicationFilterChain filterChain = factory.createFilterChain(request,
wrapper);
// Call the service() method for the allocated servlet instance
try {
String jspFile = wrapper.getJspFile();
- if (jspFile != null)
+ if (jspFile != null) {
request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
- else
+ } else {
request.removeAttribute(Globals.JSP_FILE_ATTR);
+ }
support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,
servlet, request, response);
// for includes/forwards
if ((servlet != null) && (filterChain != null)) {
- filterChain.doFilter(request, response);
- }
+ filterChain.doFilter(request, response);
+ }
// Servlet Service Method is called by the FilterChain
request.removeAttribute(Globals.JSP_FILE_ATTR);
support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterChain.java 2009-04-07 01:50:57
UTC (rev 989)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterChain.java 2009-04-07 17:21:32
UTC (rev 990)
@@ -62,6 +62,8 @@
import org.apache.catalina.Globals;
import org.apache.catalina.InstanceEvent;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.connector.RequestFacade;
import org.apache.catalina.security.SecurityUtil;
import org.apache.catalina.util.InstanceSupport;
import org.apache.catalina.util.StringManager;
@@ -119,11 +121,13 @@
// ----------------------------------------------------- Instance Variables
- // FIXME: Add a requestFacade field to be able to call release when done
- // FIXME: Add accessors for the internal structures
- // FIXME: Keep the wrapper, to be able to access the servlet registration
- // FIXME: Add an exec pointer field to know which element of the chain we are
running
+
+ /**
+ * Associated request facade.
+ */
+ private RequestFacade requestFacade = null;
+
/**
* Filters.
*/
@@ -132,6 +136,12 @@
/**
+ * The int which is used to track the component currently executed.
+ */
+ private int pointer = 0;
+
+
+ /**
* The int which is used to maintain the current position
* in the filter chain.
*/
@@ -141,16 +151,16 @@
/**
* The int which gives the current number of filters in the chain.
*/
- private int n = 0;
+ private int filterCount = 0;
/**
- * The servlet instance to be executed by this chain.
+ * The wrapper to be executed by this chain.
*/
- private Servlet servlet = null;
+ private Wrapper wrapper = null;
- /**
+ /**
* The string manager for our package.
*/
private static final StringManager sm =
@@ -158,13 +168,6 @@
/**
- * The InstanceSupport instance associated with our Wrapper (used to
- * send "before filter" and "after filter" events.
- */
- private InstanceSupport support = null;
-
-
- /**
* Static class array used when the SecurityManager is turned on and
* <code>doFilter</code> is invoked.
*/
@@ -244,8 +247,10 @@
ServletResponse response)
throws IOException, ServletException {
+ InstanceSupport support = wrapper.getInstanceSupport();
+
// Call the next filter if there is one
- if (pos < n) {
+ if (pos < filterCount) {
ApplicationFilterConfig filterConfig = filters[pos++];
Filter filter = null;
try {
@@ -296,6 +301,7 @@
}
// We fell off the end of the chain -- call the servlet instance
+ Servlet servlet = wrapper.getServlet();
try {
if (Globals.STRICT_SERVLET_COMPLIANCE) {
lastServicedRequest.set(request);
@@ -424,8 +430,9 @@
throws IOException, ServletException {
// Call the next filter if there is one
- if (pos < n) {
+ if (pos < filterCount) {
ApplicationFilterConfig filterConfig = filters[pos++];
+ pointer++;
HttpEventFilter filter = null;
try {
filter = (HttpEventFilter) filterConfig.getFilter();
@@ -451,7 +458,9 @@
/*support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event);*/
+ pointer--;
} catch (IOException e) {
+ pointer--;
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
@@ -459,6 +468,7 @@
*/
throw e;
} catch (ServletException e) {
+ pointer--;
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
@@ -466,6 +476,7 @@
*/
throw e;
} catch (RuntimeException e) {
+ pointer--;
/*
if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
@@ -473,6 +484,7 @@
*/
throw e;
} catch (Throwable e) {
+ pointer--;
/*if (filter != null)
support.fireInstanceEvent(InstanceEvent.AFTER_FILTER_EVENT,
filter, event, e);*/
@@ -483,6 +495,8 @@
}
// We fell off the end of the chain -- call the servlet instance
+ Servlet servlet = wrapper.getServlet();
+ pointer++;
try {
/*
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
@@ -505,25 +519,30 @@
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response);*/
+ pointer--;
} catch (IOException e) {
+ pointer--;
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (ServletException e) {
+ pointer--;
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (RuntimeException e) {
+ pointer--;
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
*/
throw e;
} catch (Throwable e) {
+ pointer--;
/*
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response, e);
@@ -546,13 +565,13 @@
*/
void addFilter(ApplicationFilterConfig filterConfig) {
- if (n == filters.length) {
+ if (filterCount == filters.length) {
ApplicationFilterConfig[] newFilters =
- new ApplicationFilterConfig[n + INCREMENT];
- System.arraycopy(filters, 0, newFilters, 0, n);
+ new ApplicationFilterConfig[filterCount + INCREMENT];
+ System.arraycopy(filters, 0, newFilters, 0, filterCount);
filters = newFilters;
}
- filters[n++] = filterConfig;
+ filters[filterCount++] = filterConfig;
}
@@ -562,13 +581,14 @@
*/
void release() {
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < filterCount; i++) {
filters[i] = null;
}
- n = 0;
+ filterCount = 0;
pos = 0;
- servlet = null;
- support = null;
+ pointer = 0;
+ wrapper = null;
+ requestFacade.releaseFilterChain();
}
@@ -578,40 +598,50 @@
*/
void reuse() {
pos = 0;
+ pointer = 0;
}
/**
- * Set the servlet that will be executed at the end of this chain.
+ * Set the wrapper that will be executed at the end of this chain.
*
- * @param servlet The Wrapper for the servlet to be executed
+ * @param servlet The Wrapper to be executed
*/
- void setServlet(Servlet servlet) {
+ void setWrapper(Wrapper wrapper) {
- this.servlet = servlet;
+ this.wrapper = wrapper;
}
/**
- * Set the InstanceSupport object used for event notifications
- * for this filter chain.
+ * Set the RequestFacade object used for removing the association of the
+ * chain from the request facade.
*
- * @param support The InstanceSupport object for our Wrapper
+ * @param requestFacade The RequestFacade object
*/
- void setSupport(InstanceSupport support) {
+ void setRequestFacade(RequestFacade requestFacade) {
- this.support = support;
+ this.requestFacade = requestFacade;
}
- // -------------------------------------------- AsyncProterties Inner Class
-
-
- protected class AsyncProperties {
- public boolean asyncSupported = true;
- public long timeout = -1;
+ public ApplicationFilterConfig[] getFilters() {
+ return filters;
}
+ public int getFilterCount() {
+ return filterCount;
+ }
+
+ public int getPointer() {
+ return pointer;
+ }
+
+ public Wrapper getWrapper() {
+ return wrapper;
+ }
+
+
}
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-04-07 01:50:57
UTC (rev 989)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-04-07 17:21:32
UTC (rev 990)
@@ -123,10 +123,9 @@
* a filter chain at all, return <code>null</code>.
*
* @param request The servlet request we are processing
- * @param servlet The servlet instance to be wrapped
+ * @param wrapper The servlet instance to be wrapped
*/
- public ApplicationFilterChain createFilterChain
- (ServletRequest request, Wrapper wrapper, Servlet servlet) {
+ public ApplicationFilterChain createFilterChain(ServletRequest request, Wrapper
wrapper) {
// get the dispatcher type
int dispatcher = -1;
@@ -146,7 +145,7 @@
if (request instanceof HttpServletRequest)
hreq = (HttpServletRequest)request;
// If there is no servlet to execute, return null
- if (servlet == null)
+ if (wrapper.getServlet() == null)
return (null);
boolean event = false;
@@ -187,15 +186,10 @@
requestFacade.setFilterChain(filterChain);
}
}
- // FIXME: Set the request field in the chain so that the chain removes itself
when it recycles
+ filterChain.setRequestFacade(requestFacade);
}
-
-
- filterChain.setServlet(servlet);
+ filterChain.setWrapper(wrapper);
- filterChain.setSupport
- (((StandardWrapper)wrapper).getInstanceSupport());
-
// Acquire the filter mappings for this Context
StandardContext context = (StandardContext) wrapper.getParent();
FilterMap filterMaps[] = context.findFilterMaps();
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-04-07 01:50:57 UTC (rev
989)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-04-07 17:21:32 UTC (rev
990)
@@ -63,6 +63,7 @@
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionListener;
+import org.apache.catalina.Authenticator;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Context;
@@ -231,6 +232,12 @@
/**
+ * The application authenticator for this Context. This is simply a reference
+ * and the authenticator should still be set as a valve.
+ */
+ private Authenticator authenticator = null;
+
+ /**
* The application available flag for this Context.
*/
private boolean available = false;
@@ -1009,6 +1016,31 @@
/**
+ * Return the application authenticator for this Context.
+ */
+ public Authenticator getAuthenticator() {
+
+ return (this.authenticator);
+
+ }
+
+
+ /**
+ * Set the application authenticator for this Context.
+ *
+ * @param authenticator The new application authenticator
+ */
+ public void setAuthenticator(Authenticator authenticator) {
+
+ Authenticator oldAuthenticator = this.authenticator;
+ this.authenticator = authenticator;
+ support.firePropertyChange("authenticator", oldAuthenticator,
+ this.authenticator);
+
+ }
+
+
+ /**
* Return the application available flag for this Context.
*/
public boolean getAvailable() {
@@ -4806,6 +4838,8 @@
applicationLifecycleListenersObjects = new Object[0];
instanceManager = null;
+ authenticator = null;
+
if(log.isDebugEnabled())
log.debug("resetContext " + oname);
}
Modified: trunk/java/org/apache/catalina/core/StandardWrapperValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-04-07 01:50:57 UTC
(rev 989)
+++ trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-04-07 17:21:32 UTC
(rev 990)
@@ -235,7 +235,7 @@
ApplicationFilterFactory factory =
ApplicationFilterFactory.getInstance();
ApplicationFilterChain filterChain =
- factory.createFilterChain(request, wrapper, servlet);
+ factory.createFilterChain(request, wrapper);
// Reset event flag value after creating the filter chain
request.setEventMode(false);
Modified: trunk/java/org/apache/catalina/startup/ContextConfig.java
===================================================================
--- trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-04-07 01:50:57 UTC (rev
989)
+++ trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-04-07 17:21:32 UTC (rev
990)
@@ -579,6 +579,9 @@
}
}
+ if (authenticator instanceof Authenticator) {
+ context.setAuthenticator((Authenticator) authenticator);
+ }
if (authenticator != null && context instanceof ContainerBase) {
Pipeline pipeline = ((ContainerBase) context).getPipeline();
if (pipeline != null) {