Author: remy.maucherat(a)jboss.com
Date: 2009-04-06 21:29:59 -0400 (Mon, 06 Apr 2009)
New Revision: 988
Modified:
trunk/java/org/apache/catalina/Authenticator.java
trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/connector/RequestFacade.java
trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
Log:
- Add code to build the execution stack in the request.
- Map the login method.
Modified: trunk/java/org/apache/catalina/Authenticator.java
===================================================================
--- trunk/java/org/apache/catalina/Authenticator.java 2009-04-06 17:11:45 UTC (rev 987)
+++ trunk/java/org/apache/catalina/Authenticator.java 2009-04-07 01:29:59 UTC (rev 988)
@@ -18,7 +18,15 @@
package org.apache.catalina;
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+
+
/**
* An <b>Authenticator</b> is a component (usually a Valve or Container)
that
* provides some sort of authentication service. The interface itself has no
@@ -31,6 +39,8 @@
*/
public interface Authenticator {
-
-
+ public boolean login(Request request, Response response)
+ throws IOException, ServletException;
+ public boolean login(Request request, HttpServletResponse response)
+ throws IOException, ServletException;
}
Modified: trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java
===================================================================
--- trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java 2009-04-06
17:11:45 UTC (rev 987)
+++ trunk/java/org/apache/catalina/authenticator/AuthenticatorBase.java 2009-04-07
01:29:59 UTC (rev 988)
@@ -30,6 +30,7 @@
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.Authenticator;
import org.apache.catalina.Container;
@@ -50,7 +51,6 @@
import org.apache.catalina.util.StringManager;
import org.apache.catalina.valves.ValveBase;
import org.jboss.logging.Logger;
-import org.jboss.logging.Logger;
/**
@@ -370,6 +370,39 @@
/**
+ * Login.
+ *
+ * @param request Request we are processing
+ * @param response Response we are creating
+ * @param config Login configuration describing how authentication
+ * should be performed
+ *
+ * @exception IOException if an input/output error occurs
+ */
+ public boolean login(Request request, Response response)
+ throws IOException, ServletException {
+ return authenticate(request, response, this.context.getLoginConfig());
+ }
+
+
+ /**
+ * Login.
+ *
+ * @param request Request we are processing
+ * @param response Response we are creating
+ * @param config Login configuration describing how authentication
+ * should be performed
+ *
+ * @exception IOException if an input/output error occurs
+ */
+ public boolean login(Request request, HttpServletResponse response)
+ throws IOException, ServletException {
+ // FIXME
+ return false;
+ }
+
+
+ /**
* Enforce the security restrictions in the web application deployment
* descriptor of our associated Context.
*
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-04-06 17:11:45 UTC (rev
987)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-04-07 01:29:59 UTC (rev
988)
@@ -88,6 +88,7 @@
import org.apache.catalina.Realm;
import org.apache.catalina.Session;
import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.ApplicationFilterChain;
import org.apache.catalina.core.ApplicationFilterFactory;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.catalina.util.Enumerator;
@@ -242,6 +243,12 @@
/**
+ * Async timeout.
+ */
+ protected long asyncTimeout = 300000L;
+
+
+ /**
* Associated event.
*/
protected HttpEventImpl event = null;
@@ -437,6 +444,7 @@
}
asyncContext = null;
+ asyncTimeout = 300000;
authType = null;
inputBuffer.recycle();
usingInputStream = false;
@@ -455,6 +463,7 @@
localPort = -1;
localAddr = null;
localName = null;
+ currentFilterChain = 0;
attributes.clear();
notes.clear();
@@ -581,28 +590,55 @@
/**
- * Filter chain associated with the request.
+ * Filter chains associated with the request.
*/
- protected FilterChain filterChain = null;
-
+ protected ArrayList<ApplicationFilterChain> filterChains = new
ArrayList<ApplicationFilterChain>();
+
+
/**
+ * Number of filter chains used.
+ */
+ protected int currentFilterChain = 0;
+
+
+ /**
* Get filter chain associated with the request.
*/
- public FilterChain getFilterChain() {
- return (this.filterChain);
+ public ApplicationFilterChain getFilterChain() {
+ if (currentFilterChain < filterChains.size()) {
+ return filterChains.get(currentFilterChain++);
+ } else {
+ return null;
+ }
}
+
/**
* Set filter chain associated with the request.
*
* @param filterChain new filter chain
*/
- public void setFilterChain(FilterChain filterChain) {
- this.filterChain = filterChain;
+ public void setFilterChain(ApplicationFilterChain filterChain) {
+ if (currentFilterChain < filterChains.size()) {
+ filterChains.set(currentFilterChain++, filterChain);
+ } else {
+ filterChains.add(filterChain);
+ currentFilterChain++;
+ }
}
/**
+ * Set filter chain associated with the request.
+ *
+ * @param filterChain new filter chain
+ */
+ public void releaseFilterChain() {
+ currentFilterChain--;
+ }
+
+
+ /**
* Return the Host within which this Request is being processed.
*/
public Host getHost() {
@@ -2811,7 +2847,7 @@
}
public void setAsyncTimeout(long timeout) {
- setTimeout((timeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)
timeout);
+ this.asyncTimeout = timeout;
}
public AsyncContext startAsync() throws IllegalStateException {
@@ -2820,6 +2856,9 @@
public AsyncContext startAsync(ServletRequest servletRequest,
ServletResponse servletResponse) throws IllegalStateException {
+ // FIXME: check is supported
+ // FIXME: get async timeout according to what was configured in the filter
chains
+ setTimeout((asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)
asyncTimeout);
asyncContext = new AsyncContextImpl(servletRequest, servletResponse);
eventMode = true;
return asyncContext;
@@ -2827,13 +2866,22 @@
public boolean login(HttpServletResponse response) throws IOException,
ServletException {
- // TODO Auto-generated method stub
+ // FIXME: wrapped response is super evil :(
+ if (response instanceof ResponseFacade) {
+
+ }
return false;
}
public void login(String username, String password) throws ServletException {
- // TODO Auto-generated method stub
-
+ 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 = "?";
}
public void logout() throws ServletException {
Modified: trunk/java/org/apache/catalina/connector/RequestFacade.java
===================================================================
--- trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-04-06 17:11:45 UTC
(rev 987)
+++ trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-04-07 01:29:59 UTC
(rev 988)
@@ -41,6 +41,7 @@
import javax.servlet.http.HttpSession;
import org.apache.catalina.Globals;
+import org.apache.catalina.core.ApplicationFilterChain;
import org.apache.catalina.security.SecurityUtil;
import org.apache.catalina.util.StringManager;
@@ -1041,6 +1042,44 @@
}
+ /**
+ * Get filter chain associated with the request.
+ */
+ public ApplicationFilterChain getFilterChain() {
+ if (request == null) {
+ throw new IllegalStateException(
+ sm.getString("requestFacade.nullRequest"));
+ }
+ return request.getFilterChain();
+ }
+
+
+ /**
+ * Set filter chain associated with the request.
+ *
+ * @param filterChain new filter chain
+ */
+ public void setFilterChain(ApplicationFilterChain filterChain) {
+ if (request == null) {
+ throw new IllegalStateException(
+ sm.getString("requestFacade.nullRequest"));
+ }
+ request.setFilterChain(filterChain);
+ }
+
+
+ /**
+ * Release the current filter chain.
+ */
+ public void releaseFilterChain() {
+ if (request == null) {
+ throw new IllegalStateException(
+ sm.getString("requestFacade.nullRequest"));
+ }
+ request.releaseFilterChain();
+ }
+
+
public ServletResponse getServletResponse() {
if (request == null) {
throw new IllegalStateException(
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterChain.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterChain.java 2009-04-06 17:11:45
UTC (rev 987)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterChain.java 2009-04-07 01:29:59
UTC (rev 988)
@@ -53,7 +53,7 @@
* @version $Revision$ $Date$
*/
-final class ApplicationFilterChain implements FilterChain, HttpEventFilterChain {
+public final class ApplicationFilterChain implements FilterChain, HttpEventFilterChain {
// Used to enforce requirements of SRV.8.2 / SRV.14.2.5.1
private final static ThreadLocal lastServicedRequest;
@@ -69,6 +69,7 @@
}
}
+
// -------------------------------------------------------------- Constants
@@ -90,7 +91,11 @@
// ----------------------------------------------------- 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
+
/**
* Filters.
*/
@@ -572,5 +577,13 @@
}
+
+ // -------------------------------------------- AsyncProterties Inner Class
+
+
+ protected class AsyncProperties {
+ public boolean asyncSupported = true;
+ public long timeout = -1;
+ }
}
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-04-06 17:11:45
UTC (rev 987)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterFactory.java 2009-04-07 01:29:59
UTC (rev 988)
@@ -21,11 +21,13 @@
import javax.servlet.Servlet;
import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestWrapper;
import javax.servlet.http.HttpServletRequest;
import org.apache.catalina.Globals;
import org.apache.catalina.Wrapper;
import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.RequestFacade;
import org.apache.catalina.deploy.FilterMap;
import org.jboss.servlet.http.HttpEventFilter;
@@ -119,31 +121,48 @@
if (servlet == null)
return (null);
- boolean comet = false;
+ boolean event = false;
+ // Get the request facade object
+ RequestFacade requestFacade = null;
+ if (request instanceof Request) {
+ Request coreRequest = (Request) request;
+ event = coreRequest.isEventMode();
+ requestFacade = (RequestFacade) coreRequest.getRequest();
+ } else {
+ ServletRequest current = request;
+ while (current != null) {
+ // If we run into the container request we are done
+ if (current instanceof RequestFacade) {
+ requestFacade = (RequestFacade) current;
+ break;
+ }
+ // Advance to the next request in the chain
+ current = ((ServletRequestWrapper) current).getRequest();
+ }
+ }
+
// Create and initialize a filter chain object
ApplicationFilterChain filterChain = null;
- if (request instanceof Request) {
- Request req = (Request) request;
- comet = req.isEventMode();
+ if (requestFacade == null) {
+ // Not normal: some async functions and tracing will be disabled
+ filterChain = new ApplicationFilterChain();
+ } else {
+ // Add this filter chain to the request facade
if (Globals.IS_SECURITY_ENABLED) {
- // Security: Do not recycle
filterChain = new ApplicationFilterChain();
- if (comet) {
- req.setFilterChain(filterChain);
- }
+ requestFacade.setFilterChain(filterChain);
} else {
- filterChain = (ApplicationFilterChain) req.getFilterChain();
+ filterChain = requestFacade.getFilterChain();
if (filterChain == null) {
filterChain = new ApplicationFilterChain();
- req.setFilterChain(filterChain);
+ requestFacade.setFilterChain(filterChain);
}
}
- } else {
- // Request dispatcher in use
- filterChain = new ApplicationFilterChain();
+ // FIXME: Set the request field in the chain so that the chain removes itself
when it recycles
}
-
+
+
filterChain.setServlet(servlet);
filterChain.setSupport
@@ -173,16 +192,16 @@
; // FIXME - log configuration problem
continue;
}
- boolean isCometFilter = false;
- if (comet) {
+ boolean isEventFilter = false;
+ if (event) {
try {
- isCometFilter = filterConfig.getFilter() instanceof HttpEventFilter;
+ isEventFilter = filterConfig.getFilter() instanceof HttpEventFilter;
} catch (Exception e) {
// Note: The try catch is there because getFilter has a lot of
// declared exceptions. However, the filter is allocated much
// earlier
}
- if (isCometFilter) {
+ if (isEventFilter) {
filterChain.addFilter(filterConfig);
}
} else {
@@ -203,16 +222,16 @@
; // FIXME - log configuration problem
continue;
}
- boolean isCometFilter = false;
- if (comet) {
+ boolean isEventFilter = false;
+ if (event) {
try {
- isCometFilter = filterConfig.getFilter() instanceof HttpEventFilter;
+ isEventFilter = filterConfig.getFilter() instanceof HttpEventFilter;
} catch (Exception e) {
// Note: The try catch is there because getFilter has a lot of
// declared exceptions. However, the filter is allocated much
// earlier
}
- if (isCometFilter) {
+ if (isEventFilter) {
filterChain.addFilter(filterConfig);
}
} else {