ib          2004/02/25 08:33:21

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib Tag:
                        SLIDE_2_0_RELEASE_BRANCH WebdavSession.java
                        WebdavResource.java
  Log:
  Allow to provide custom credentials for authentication. This will most
  likely be used when NTLM authentication is required.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.2.2.2   +28 -7     
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavSession.java
  
  Index: WebdavSession.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavSession.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- WebdavSession.java        5 Feb 2004 15:51:21 -0000       1.2.2.1
  +++ WebdavSession.java        25 Feb 2004 16:33:21 -0000      1.2.2.2
  @@ -73,6 +73,11 @@
       protected HttpClient client;
   
       /**
  +     * Credentials to use for authentication
  +     */
  +    protected Credentials hostCredentials = null;
  +
  +    /**
        * The hostname to use for the proxy, if any
        */
       protected String proxyHost = null;
  @@ -146,12 +151,19 @@
               if (proxyHost != null && proxyPort > 0)
                   hostConfig.setProxy(proxyHost, proxyPort);
   
  -            String userName = httpURL.getUser();
  -            if (userName != null && userName.length() > 0) {
  -                String password = httpURL.getPassword();
  +            if (hostCredentials == null) {
  +                String userName = httpURL.getUser();
  +                if (userName != null && userName.length() > 0) {
  +                    hostCredentials =
  +                        new UsernamePasswordCredentials(userName,
  +                                                        httpURL.getPassword());
  +                }
  +            }
  +
  +            if (hostCredentials != null) {
                   HttpState clientState = client.getState();
                   clientState.setCredentials(null, httpURL.getHost(),
  -                    new UsernamePasswordCredentials(userName, password));
  +                                           hostCredentials);
                   clientState.setAuthenticationPreemptive(true);
               }
   
  @@ -162,6 +174,15 @@
           }
   
           return client;
  +    }
  +
  +    /**
  +     * Set credentials for authentication.
  +     *
  +     * @param credentials The credentials to use for authentication.
  +     */
  +    public void setCredentials(Credentials credentials) {
  +        hostCredentials = credentials;
       }
   
       /** Set proxy info, to use proxying.
  
  
  
  1.3.2.3   +41 -3     
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
  retrieving revision 1.3.2.2
  retrieving revision 1.3.2.3
  diff -u -r1.3.2.2 -r1.3.2.3
  --- WebdavResource.java       5 Feb 2004 15:51:21 -0000       1.3.2.2
  +++ WebdavResource.java       25 Feb 2004 16:33:21 -0000      1.3.2.3
  @@ -210,6 +210,26 @@
        * The constructor.
        *
        * @param httpURL The specified http URL.
  +     * @param credentials The credentials to use for authentication.
  +     * @param action The action to set properties of this resource.
  +     * @param depth The depth to find properties.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setDefaultAction(int)
  +     */
  +    public WebdavResource(HttpURL httpURL, Credentials credentials, int action,
  +                          int depth)
  +        throws HttpException, IOException {
  +
  +        setCredentials(credentials);
  +        setHttpURL(httpURL, action, depth);
  +    }
  +
  +
  +    /**
  +     * The constructor.
  +     *
  +     * @param httpURL The specified http URL.
        * @param action The action to set properties of this resource.
        * @param depth The depth to find properties.
        * @exception HttpException
  @@ -306,6 +326,24 @@
       public WebdavResource(String escapedHttpURL)
           throws HttpException, IOException {
   
  +        setHttpURL(escapedHttpURL);
  +    }
  +
  +
  +    /**
  +     * The constructor.
  +     * It must be put an escaped http URL as an argument.
  +     *
  +     * @param escapedHttpURL The escaped http URL string.
  +     * @param credentials The credentials used for Authentication.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setDefaultAction(int)
  +     */
  +    public WebdavResource(String escapedHttpURL, Credentials credentials)
  +        throws HttpException, IOException {
  +
  +        setCredentials(credentials);
           setHttpURL(escapedHttpURL);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to