Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 75284 invoked from network); 3 Oct 2006 17:41:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Oct 2006 17:41:14 -0000 Received: (qmail 45976 invoked by uid 500); 3 Oct 2006 17:41:12 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 45940 invoked by uid 500); 3 Oct 2006 17:41:12 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 45929 invoked by uid 500); 3 Oct 2006 17:41:12 -0000 Received: (qmail 45924 invoked by uid 99); 3 Oct 2006 17:41:12 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Oct 2006 10:41:12 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:59587] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 97/76-08153-7B0A2254 for ; Tue, 03 Oct 2006 10:41:11 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DE32F1A981A; Tue, 3 Oct 2006 10:41:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r452580 - in /jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs: provider/http/ provider/webdav/ util/ Date: Tue, 03 Oct 2006 17:41:08 -0000 To: commons-cvs@jakarta.apache.org From: imario@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061003174108.DE32F1A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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