vmassol 2003/03/08 12:38:20
Modified: framework/src/java/share/org/apache/cactus/client/authentication
AbstractAuthentication.java
BasicAuthentication.java FormAuthentication.java
framework/src/java/share/org/apache/cactus
BaseWebRequest.java WebRequest.java
framework/src/java/share/org/apache/cactus/client/connector/http
JdkConnectionHelper.java DefaultHttpClient.java
ConnectionHelper.java
HttpClientConnectionHelper.java
documentation/docs/xdocs changes.xml
Log:
Added ability to add any additional HTTP parameters to the request used by Cactus to
the Form-based authentication security URL. Suggested by Jason Arndt [EMAIL PROTECTED]
Revision Changes Path
1.8 +6 -24
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/AbstractAuthentication.java
Index: AbstractAuthentication.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/AbstractAuthentication.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractAuthentication.java 22 Feb 2003 11:31:49 -0000 1.7
+++ AbstractAuthentication.java 8 Mar 2003 20:38:20 -0000 1.8
@@ -90,11 +90,6 @@
protected String password;
/**
- * Cactus configuration
- */
- private Configuration configuration;
-
- /**
* @param theName user name of the Credential
* @param thePassword user password of the Credential
*/
@@ -105,23 +100,6 @@
}
/**
- * Sets the Cactus configuration so that authentication methods
- * can get access to Cactus configuration properties. For example,
- * this is needed by the <code>FormAuthentication</code>.
- *
* @param theConfiguration the Cactus configuration
*/
- public void setConfiguration(Configuration theConfiguration)
- {
- this.configuration = theConfiguration;
- }
-
- /**
- * @return the Cactus configuration
*/
- public Configuration getConfiguration()
- {
- return this.configuration;
- }
-
- /**
* Sets the user name.
*
* @param theName user name of the Credential
@@ -173,8 +151,12 @@
*
* @param theRequest the request object that will be sent to the Cactus
* Redirector over HTTP
+ * @param theConfiguration the Cactus configuration so that
+ * authentication methods can get access to Cactus configuration
+ * properties
*/
- public abstract void configure(WebRequest theRequest);
+ public abstract void configure(WebRequest theRequest,
+ Configuration theConfiguration);
/**
* @return the user password of the Credential
1.8 +5 -3
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/BasicAuthentication.java
Index: BasicAuthentication.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/BasicAuthentication.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BasicAuthentication.java 3 Jan 2003 15:35:43 -0000 1.7
+++ BasicAuthentication.java 8 Mar 2003 20:38:20 -0000 1.8
@@ -60,6 +60,7 @@
import java.text.StringCharacterIterator;
import org.apache.cactus.WebRequest;
+import org.apache.cactus.configuration.Configuration;
/**
* Basic Authentication support.
@@ -209,9 +210,10 @@
}
/**
- * @see AbstractAuthentication#configure(WebRequest)
+ * @see AbstractAuthentication#configure(WebRequest, Configuration)
*/
- public void configure(WebRequest theRequest)
+ public void configure(WebRequest theRequest,
+ Configuration theConfiguration)
{
// According to HTTP 1.0 Spec:
// basic-credentials = "Basic" SP basic-cookie
1.11 +38 -16
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/FormAuthentication.java
Index: FormAuthentication.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/FormAuthentication.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FormAuthentication.java 23 Feb 2003 09:21:17 -0000 1.10
+++ FormAuthentication.java 8 Mar 2003 20:38:20 -0000 1.11
@@ -63,6 +63,7 @@
import org.apache.cactus.WebRequest;
import org.apache.cactus.client.connector.http.ConnectionHelper;
import org.apache.cactus.client.connector.http.ConnectionHelperFactory;
+import org.apache.cactus.configuration.Configuration;
import org.apache.cactus.configuration.WebConfiguration;
import org.apache.cactus.util.ChainedRuntimeException;
import org.apache.commons.logging.Log;
@@ -108,7 +109,13 @@
* We store the session id cookie so that this instance can
* be reused for another test.
*/
private String sessionId = null;
-
+
+ /**
+ * [EMAIL PROTECTED] WebRequest} object that will be used to connect to the
+ * security URL.
+ */
+ private WebRequest securityRequest = new WebRequest();
+
/**
* @param theName user name of the Credential
* @param thePassword user password of the Credential
@@ -135,14 +142,15 @@
}
/**
- * @see AbstractAuthentication#configure(WebRequest)
+ * @see AbstractAuthentication#configure(WebRequest, Configuration)
*/
- public void configure(WebRequest theRequest)
+ public void configure(WebRequest theRequest,
+ Configuration theConfiguration)
{
// Only authenticate the first time this instance is used.
if (this.sessionId == null)
{
- authenticate(theRequest);
+ authenticate(theRequest, theConfiguration);
}
// Sets the session id cookie for the next request.
@@ -151,6 +159,16 @@
theRequest.addCookie(this.sessionIdCookieName, this.sessionId);
}
}
+
+ /**
+ * @return the [EMAIL PROTECTED] WebRequest} that will be used to connect to the
+ * security URL. It can be used to add additional HTTP parameters such
+ * as proprietary ones required by some containers.
+ */
+ public WebRequest getSecurityRequest()
+ {
+ return this.securityRequest;
+ }
/**
* This sets the URL to use when attempting to log in. This method is used
@@ -168,15 +186,16 @@
* the context URL defined in the Cactus configuration with
* "/j_security_check" appended.
*
+ * @param theConfiguration the Cactus configuration
* @return the URL that is being used to attempt to login.
*/
- public URL getSecurityCheckURL()
+ public URL getSecurityCheckURL(Configuration theConfiguration)
{
if (this.securityCheckURL == null)
{
// Configure default
String stringUrl =
- ((WebConfiguration) getConfiguration()).getContextURL()
+ ((WebConfiguration) theConfiguration).getContextURL()
+ "/j_security_check";
try
@@ -200,8 +219,10 @@
/**
* Authenticate the principal by calling the security URL.
*
- * @param theRequest the web request used to connect to the Redirector
*/
- public void authenticate(WebRequest theRequest)
+ * @param theRequest the web request used to connect to the Redirector
* @param theConfiguration the Cactus configuration
+ */
+ public void authenticate(WebRequest theRequest,
+ Configuration theConfiguration)
{
//Note: This method needs refactoring. It is too complex.
@@ -209,16 +230,16 @@
{
// Create a helper that will connect to a restricted resource.
- String resource = ((WebConfiguration) getConfiguration())
- .getRedirectorURL(theRequest);
+ String resource = ((WebConfiguration) theConfiguration).
+ getRedirectorURL(theRequest);
ConnectionHelper helper =
ConnectionHelperFactory.getConnectionHelper(resource,
- getConfiguration());
+ theConfiguration);
// Make the connection using a default web request.
- HttpURLConnection connection = helper.connect(
- new WebRequest((WebConfiguration) getConfiguration()));
+ HttpURLConnection connection =
+ helper.connect(this.securityRequest, theConfiguration);
// Clean any existing session ID.
sessionId = null;
@@ -257,12 +278,13 @@
// Create a helper that will connect to the security check URL.
helper = ConnectionHelperFactory.getConnectionHelper(
- getSecurityCheckURL().toString(), getConfiguration());
+ getSecurityCheckURL(theConfiguration).toString(),
+ (WebConfiguration) theConfiguration);
// Configure a web request with the JSESSIONID cookie,
// the username and the password.
WebRequest request = new WebRequest(
- (WebConfiguration) getConfiguration());
+ (WebConfiguration) theConfiguration);
request.addCookie(sessionIdCookieName, sessionId);
request.addParameter("j_username", getName(),
WebRequest.POST_METHOD);
@@ -270,7 +292,7 @@
WebRequest.POST_METHOD);
// Make the connection using the configured web request.
- connection = helper.connect(request);
+ connection = helper.connect(request, theConfiguration);
// If we get back a response code of 302, it means we were
// redirected to the context root after successfully logging in.
1.4 +20 -6
jakarta-cactus/framework/src/java/share/org/apache/cactus/BaseWebRequest.java
Index: BaseWebRequest.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/BaseWebRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BaseWebRequest.java 22 Feb 2003 11:31:49 -0000 1.3
+++ BaseWebRequest.java 8 Mar 2003 20:38:20 -0000 1.4
@@ -129,6 +129,16 @@
private AbstractAuthentication authentication;
/**
+ * Default constructor that requires that
+ * [EMAIL PROTECTED] #setConfiguration(Configuration)} be called before the
methods
+ * requiring a configuration object.
+ *
+ */
+ public BaseWebRequest()
+ {
+ }
+
+ /**
* @param theConfiguration the Cactus configuration
*/
public BaseWebRequest(Configuration theConfiguration)
@@ -145,6 +155,15 @@
}
/**
+ * @param theConfiguration the cactus configuration to assign to this
+ * request
+ */
+ public void setConfiguration(Configuration theConfiguration)
+ {
+ this.configuration = theConfiguration;
+ }
+
+ /**
* Sets the content type that will be set in the http request
*
* @param theContentType the content type
@@ -661,11 +680,6 @@
AbstractAuthentication theAuthenticationObject)
{
this.authentication = theAuthenticationObject;
-
- // Sets the Cactus configuration. It is performed here so that
- // Cactus users do not have to bother with setting it on the
- // Authentication object they create.
- this.authentication.setConfiguration(getConfiguration());
}
/**
1.17 +18 -2
jakarta-cactus/framework/src/java/share/org/apache/cactus/WebRequest.java
Index: WebRequest.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/WebRequest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WebRequest.java 23 Feb 2003 09:21:17 -0000 1.16
+++ WebRequest.java 8 Mar 2003 20:38:20 -0000 1.17
@@ -94,6 +94,16 @@
private String redirectorName;
/**
+ * Default constructor that requires that
+ * [EMAIL PROTECTED] #setConfiguration(Configuration)} be called before the
methods
+ * requiring a configuration object.
+ *
+ */
+ public WebRequest()
+ {
+ }
+
+ /**
* @param theConfiguration the Cactus configuration
*/
public WebRequest(WebConfiguration theConfiguration)
{
@@ -263,6 +273,12 @@
*/
public HttpSessionCookie getSessionCookie()
{
+ if (getConfiguration() == null)
+ {
+ throw new ChainedRuntimeException("setConfiguration() should have "
+ + "been called prior to calling getSessionCookie()");
+ }
+
ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(
((WebConfiguration) getConfiguration()).getRedirectorURL(this),
getConfiguration());
@@ -276,7 +292,7 @@
HttpURLConnection resultConnection;
try
{
- resultConnection = helper.connect(request);
+ resultConnection = helper.connect(request, getConfiguration());
}
catch (Throwable e)
{
1.2 +6 -4
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/JdkConnectionHelper.java
Index: JdkConnectionHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/JdkConnectionHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JdkConnectionHelper.java 23 Feb 2003 09:21:17 -0000 1.1
+++ JdkConnectionHelper.java 8 Mar 2003 20:38:20 -0000 1.2
@@ -70,6 +70,7 @@
import org.apache.cactus.WebRequest;
import org.apache.cactus.client.authentication.AbstractAuthentication;
+import org.apache.cactus.configuration.Configuration;
import org.apache.cactus.util.ChainedRuntimeException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -113,9 +114,10 @@
}
/**
- * @see ConnectionHelper#connect(WebRequest)
+ * @see ConnectionHelper#connect(WebRequest, Configuration)
*/
- public HttpURLConnection connect(WebRequest theRequest) throws Throwable
+ public HttpURLConnection connect(WebRequest theRequest,
+ Configuration theConfiguration) throws Throwable
{
URL url = new URL(this.url);
@@ -126,7 +128,7 @@
if (authentication != null)
{
- authentication.configure(theRequest);
+ authentication.configure(theRequest, theConfiguration);
}
1.2 +5 -3
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/DefaultHttpClient.java
Index: DefaultHttpClient.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/DefaultHttpClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultHttpClient.java 23 Feb 2003 09:21:17 -0000 1.1
+++ DefaultHttpClient.java 8 Mar 2003 20:38:20 -0000 1.2
@@ -193,7 +193,8 @@
this.configuration.getRedirectorURL(theRequest),
this.configuration);
- HttpURLConnection connection = helper.connect(theRequest);
+ HttpURLConnection connection =
+ helper.connect(theRequest, this.configuration);
// Wrap the connection to ensure that all servlet output is read
// before we ask for results
@@ -239,7 +240,8 @@
this.configuration.getRedirectorURL(resultsRequest),
this.configuration);
- HttpURLConnection resultConnection = helper.connect(resultsRequest);
+ HttpURLConnection resultConnection =
+ helper.connect(resultsRequest, this.configuration);
// Read the test result
WebTestResultParser parser = new WebTestResultParser();
1.2 +5 -2
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/ConnectionHelper.java
Index: ConnectionHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/ConnectionHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConnectionHelper.java 23 Feb 2003 09:21:17 -0000 1.1
+++ ConnectionHelper.java 8 Mar 2003 20:38:20 -0000 1.2
@@ -59,6 +59,7 @@
import java.net.HttpURLConnection;
import org.apache.cactus.WebRequest;
+import org.apache.cactus.configuration.Configuration;
/**
* Helper class to open an HTTP connection to the server redirector and pass
@@ -77,8 +78,10 @@
*
* @param theRequest the request containing all data to pass to the
* server redirector.
+ * @param theConfiguration the Cactus configuration
* @return the HTTP Connection used to connect to the redirector.
* @exception Throwable if an unexpected error occured
*/
- HttpURLConnection connect(WebRequest theRequest) throws Throwable;
+ HttpURLConnection connect(WebRequest theRequest,
+ Configuration theConfiguration) throws Throwable;
}
1.2 +6 -4
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/HttpClientConnectionHelper.java
Index: HttpClientConnectionHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/HttpClientConnectionHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpClientConnectionHelper.java 23 Feb 2003 09:21:17 -0000 1.1
+++ HttpClientConnectionHelper.java 8 Mar 2003 20:38:20 -0000 1.2
@@ -65,6 +65,7 @@
import org.apache.cactus.WebRequest;
import org.apache.cactus.client.authentication.AbstractAuthentication;
+import org.apache.cactus.configuration.Configuration;
import org.apache.cactus.util.UrlUtil;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
@@ -102,9 +103,10 @@
}
/**
- * @see ConnectionHelper#connect(WebRequest)
+ * @see ConnectionHelper#connect(WebRequest, Configuration)
*/
- public HttpURLConnection connect(WebRequest theRequest) throws Throwable
+ public HttpURLConnection connect(WebRequest theRequest,
+ Configuration theConfiguration) throws Throwable
{
URL url = new URL(this.url);
@@ -115,7 +117,7 @@
if (authentication != null)
{
- authentication.configure(theRequest);
+ authentication.configure(theRequest, theConfiguration);
}
// Add the parameters that need to be passed as part of the URL
1.84 +4 -0 jakarta-cactus/documentation/docs/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- changes.xml 26 Feb 2003 07:07:12 -0000 1.83
+++ changes.xml 8 Mar 2003 20:38:20 -0000 1.84
@@ -58,6 +58,10 @@
<release version="1.5" date="- in CVS">
<action dev="VMA" type="add">
+ Added ability to add any additional HTTP parameters to the request
+ used by Cactus to the Form-based authentication security URL.
+ </action>
+ <action dev="VMA" type="add">
Added support for running pure JUnit TestCase on the server side
using Cactus. This is possible by using a new
<code>ServletTestSuite</code> Test Suite.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]