You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2006/10/03 19:41:08 UTC
svn commit: r452580 - in
/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs:
provider/http/ provider/webdav/ util/
Author: imario
Date: Tue Oct 3 10:41:07 2006
New Revision: 452580
URL: http://svn.apache.org/viewvc?view=rev&rev=452580
Log:
VFS-86: added proxy authenticator
VFS-87: allow to pass in cookies for already authenticated connections
OnCall cache decorator: fixed CCE in Webdav fs
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavClientFactory.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileSystemConfigBuilder.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/UserAuthenticatorUtils.java
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java Tue Oct 3 10:41:07 2006
@@ -19,9 +19,13 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.UserAuthenticator;
+import org.apache.commons.vfs.UserAuthenticationData;
+import org.apache.commons.vfs.util.UserAuthenticatorUtils;
/**
* Create a HttpClient instance
@@ -55,6 +59,32 @@
if (proxyHost != null && proxyPort > 0)
{
config.setProxy(proxyHost, proxyPort);
+ }
+
+ UserAuthenticator proxyAuth = HttpFileSystemConfigBuilder.getInstance().getProxyAuthenticator(fileSystemOptions);
+ if (proxyAuth != null)
+ {
+ UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[]
+ {
+ UserAuthenticationData.USERNAME,
+ UserAuthenticationData.PASSWORD
+ });
+
+ if (authData != null)
+ {
+ final UsernamePasswordCredentials proxyCreds =
+ new UsernamePasswordCredentials(
+ UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
+ UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
+
+ client.getState().setProxyCredentials(null, proxyHost, proxyCreds);
+ }
+ }
+
+ Cookie[] cookies = HttpFileSystemConfigBuilder.getInstance().getCookies(fileSystemOptions);
+ if (cookies != null)
+ {
+ client.getState().addCookies(cookies);
}
}
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java Tue Oct 3 10:41:07 2006
@@ -17,6 +17,8 @@
import org.apache.commons.vfs.FileSystemConfigBuilder;
import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.UserAuthenticator;
+import org.apache.commons.httpclient.Cookie;
/**
* Configuration options for HTTP
@@ -110,6 +112,38 @@
return ((Number) getParam(opts, "proxyPort")).intValue();
}
+ /**
+ * Set the proxy authenticator where the system should get the credentials from
+ */
+ public void setProxyAuthenticator(FileSystemOptions opts, UserAuthenticator authenticator)
+ {
+ setParam(opts, "proxyAuthenticator", authenticator);
+ }
+
+ /**
+ * Get the proxy authenticator where the system should get the credentials from
+ */
+ public UserAuthenticator getProxyAuthenticator(FileSystemOptions opts)
+ {
+ return (UserAuthenticator) getParam(opts, "proxyAuthenticator");
+ }
+
+ /**
+ * The cookies to add to the reqest
+ */
+ public void setCookies(FileSystemOptions opts, Cookie[] cookies)
+ {
+ setParam(opts, "cookies", cookies);
+ }
+
+ /**
+ * The cookies to add to the reqest
+ */
+ public Cookie[] getCookies(FileSystemOptions opts)
+ {
+ return (Cookie[]) getParam(opts, "cookies");
+ }
+
protected Class getConfigClass()
{
return HttpFileSystem.class;
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavClientFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavClientFactory.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavClientFactory.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavClientFactory.java Tue Oct 3 10:41:07 2006
@@ -17,8 +17,12 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpURL;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.Cookie;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.UserAuthenticator;
+import org.apache.commons.vfs.UserAuthenticationData;
import org.apache.commons.vfs.util.UserAuthenticatorUtils;
import org.apache.webdav.lib.WebdavResource;
@@ -66,6 +70,26 @@
{
// resource = new WebdavResource(url, proxyHost, proxyPort);
resource.setProxy(proxyHost, proxyPort);
+ }
+
+ UserAuthenticator proxyAuth = WebdavFileSystemConfigBuilder.getInstance().getProxyAuthenticator(fileSystemOptions);
+ if (proxyAuth != null)
+ {
+ UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[]
+ {
+ UserAuthenticationData.USERNAME,
+ UserAuthenticationData.PASSWORD
+ });
+
+ if (authData != null)
+ {
+ final UsernamePasswordCredentials proxyCreds =
+ new UsernamePasswordCredentials(
+ UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)),
+ UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
+
+ resource.setProxyCredentials(proxyCreds);
+ }
}
}
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java Tue Oct 3 10:41:07 2006
@@ -29,6 +29,7 @@
import org.apache.commons.vfs.provider.URLFileName;
import org.apache.commons.vfs.util.MonitorOutputStream;
import org.apache.commons.vfs.util.RandomAccessMode;
+import org.apache.commons.vfs.util.FileObjectUtils;
import org.apache.webdav.lib.BaseProperty;
import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.DepthSupport;
@@ -254,7 +255,7 @@
private void processParentDavResource() throws FileSystemException
{
- WebdavFileObject parent = (WebdavFileObject) getParent();
+ WebdavFileObject parent = (WebdavFileObject) FileObjectUtils.getAbstractFileObject(getParent());
try
{
// after this our resource should be reset
@@ -328,11 +329,11 @@
continue;
}
- WebdavFileObject fo = (WebdavFileObject) getFileSystem().resolveFile(
+ WebdavFileObject fo = (WebdavFileObject) FileObjectUtils.getAbstractFileObject(getFileSystem().resolveFile(
getFileSystem().getFileSystemManager().resolveName(
getName(),
davName,
- NameScope.CHILD));
+ NameScope.CHILD)));
fo.setDavResource(dav);
// vfs[i] = fo;
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileSystemConfigBuilder.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileSystemConfigBuilder.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileSystemConfigBuilder.java Tue Oct 3 10:41:07 2006
@@ -17,6 +17,8 @@
import org.apache.commons.vfs.FileSystemConfigBuilder;
import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.UserAuthenticator;
+import org.apache.commons.httpclient.Cookie;
/**
* Configuration options for WebDav
@@ -110,6 +112,22 @@
return ((Number) getParam(opts, "proxyPort")).intValue();
}
+ /**
+ * Set the proxy authenticator where the system should get the credentials from
+ */
+ public void setProxyAuthenticator(FileSystemOptions opts, UserAuthenticator authenticator)
+ {
+ setParam(opts, "proxyAuthenticator", authenticator);
+ }
+
+ /**
+ * Get the proxy authenticator where the system should get the credentials from
+ */
+ public UserAuthenticator getProxyAuthenticator(FileSystemOptions opts)
+ {
+ return (UserAuthenticator) getParam(opts, "proxyAuthenticator");
+ }
+
protected Class getConfigClass()
{
return WebDavFileSystem.class;
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/UserAuthenticatorUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/UserAuthenticatorUtils.java?view=diff&rev=452580&r1=452579&r2=452580
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/UserAuthenticatorUtils.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/UserAuthenticatorUtils.java Tue Oct 3 10:41:07 2006
@@ -49,15 +49,23 @@
public static UserAuthenticationData authenticate(FileSystemOptions opts, UserAuthenticationData.Type[] authenticatorTypes)
{
UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts);
- if (auth == null)
- {
- return null;
- }
-
- return auth.requestAuthentication(authenticatorTypes);
+ return authenticate(auth, authenticatorTypes);
}
- /**
+ /**
+ * if there is a authenticator the authentication will take place, else null will be reutrned
+ */
+ public static UserAuthenticationData authenticate(UserAuthenticator auth, UserAuthenticationData.Type[] authenticatorTypes)
+ {
+ if (auth == null)
+ {
+ return null;
+ }
+
+ return auth.requestAuthentication(authenticatorTypes);
+ }
+
+ /**
* converts a string to a char array (null safe)
*/
public static char[] toChar(String string)
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org