@Test(expected = ConnectionRefusedException.class) public void testConnectRefused() throws Exception { final Host host = new Host(new DAVSSLProtocol(), "localhost", 2121); final DAVSession session = new DAVSession(host, new CertificateStoreX509TrustManager(new DisabledCertificateTrustCallback(), new DefaultTrustManagerHostnameCallback(host), new DefaultCertificateStore()), new CertificateStoreX509KeyManager(new DisabledCertificateIdentityCallback(), host, new DefaultCertificateStore())); try { session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); } catch(ConnectionRefusedException e) { assertEquals("Connection failed", e.getMessage()); throw e; } }
@Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final CredentialsProvider provider = new BasicCredentialsProvider(); if(preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)) ); } else { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); } provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); client.setCredentials(provider); if(preferences.getBoolean("webdav.basic.preemptive")) { switch(proxy.getType()) { case DIRECT: case SOCKS: client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")) ); break; default: client.disablePreemptiveAuthentication(); } } else { client.disablePreemptiveAuthentication(); } if(host.getCredentials().isPassed()) { log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this)); return; } try { final Path home = new DefaultHomeFinderService(this).find(); try { client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new ValidatingResponseHandler<Void>() { @Override public Void handleResponse(final HttpResponse response) throws IOException { if(Arrays.stream(response.getAllHeaders()).anyMatch(header -> HttpHeaders.SERVER.equals(header.getName()) && StringUtils.contains(header.getValue(), "Microsoft-IIS"))) { if(log.isDebugEnabled()) { log.debug("Microsoft-IIS backend detected"); } list = new MicrosoftIISDAVListService(DAVSession.this, new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this)); timestamp = new MicrosoftIISDAVTimestampFeature(DAVSession.this); attributes = new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this); if(preferences.getBoolean("webdav.microsoftiis.header.translate")) { read = new MicrosoftIISDAVReadFeature(DAVSession.this); find = new MicrosoftIISDAVFindFeature(DAVSession.this); } } this.validateResponse(response); return null; } }); } catch(SardineException e) { switch(e.getStatusCode()) { case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_METHOD_NOT_ALLOWED: log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase())); cancel.verify(); this.getFeature(ListService.class).list(home, new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { try { cancel.verify(); } catch(ConnectionCanceledException e) { throw new ListCanceledException(list, e); } } }); break; case HttpStatus.SC_BAD_REQUEST: if(preferences.getBoolean("webdav.basic.preemptive")) { log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase())); cancel.verify(); client.disablePreemptiveAuthentication(); client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new VoidResponseHandler()); } else { throw new DAVExceptionMappingService().map(e); } break; default: throw new DAVExceptionMappingService().map(e); } } } catch(SardineException e) { throw new DAVExceptionMappingService().map(e); } catch(IOException e) { throw new HttpExceptionMappingService().map(e); } }
DAVSession extends HttpSession<DAVClient> { @Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final CredentialsProvider provider = new BasicCredentialsProvider(); if(preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)) ); } else { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); } provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); client.setCredentials(provider); if(preferences.getBoolean("webdav.basic.preemptive")) { switch(proxy.getType()) { case DIRECT: case SOCKS: client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")) ); break; default: client.disablePreemptiveAuthentication(); } } else { client.disablePreemptiveAuthentication(); } if(host.getCredentials().isPassed()) { log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this)); return; } try { final Path home = new DefaultHomeFinderService(this).find(); try { client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new ValidatingResponseHandler<Void>() { @Override public Void handleResponse(final HttpResponse response) throws IOException { if(Arrays.stream(response.getAllHeaders()).anyMatch(header -> HttpHeaders.SERVER.equals(header.getName()) && StringUtils.contains(header.getValue(), "Microsoft-IIS"))) { if(log.isDebugEnabled()) { log.debug("Microsoft-IIS backend detected"); } list = new MicrosoftIISDAVListService(DAVSession.this, new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this)); timestamp = new MicrosoftIISDAVTimestampFeature(DAVSession.this); attributes = new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this); if(preferences.getBoolean("webdav.microsoftiis.header.translate")) { read = new MicrosoftIISDAVReadFeature(DAVSession.this); find = new MicrosoftIISDAVFindFeature(DAVSession.this); } } this.validateResponse(response); return null; } }); } catch(SardineException e) { switch(e.getStatusCode()) { case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_METHOD_NOT_ALLOWED: log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase())); cancel.verify(); this.getFeature(ListService.class).list(home, new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { try { cancel.verify(); } catch(ConnectionCanceledException e) { throw new ListCanceledException(list, e); } } }); break; case HttpStatus.SC_BAD_REQUEST: if(preferences.getBoolean("webdav.basic.preemptive")) { log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase())); cancel.verify(); client.disablePreemptiveAuthentication(); client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new VoidResponseHandler()); } else { throw new DAVExceptionMappingService().map(e); } break; default: throw new DAVExceptionMappingService().map(e); } } } catch(SardineException e) { throw new DAVExceptionMappingService().map(e); } catch(IOException e) { throw new HttpExceptionMappingService().map(e); } } }
DAVSession extends HttpSession<DAVClient> { @Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final CredentialsProvider provider = new BasicCredentialsProvider(); if(preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)) ); } else { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); } provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); client.setCredentials(provider); if(preferences.getBoolean("webdav.basic.preemptive")) { switch(proxy.getType()) { case DIRECT: case SOCKS: client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")) ); break; default: client.disablePreemptiveAuthentication(); } } else { client.disablePreemptiveAuthentication(); } if(host.getCredentials().isPassed()) { log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this)); return; } try { final Path home = new DefaultHomeFinderService(this).find(); try { client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new ValidatingResponseHandler<Void>() { @Override public Void handleResponse(final HttpResponse response) throws IOException { if(Arrays.stream(response.getAllHeaders()).anyMatch(header -> HttpHeaders.SERVER.equals(header.getName()) && StringUtils.contains(header.getValue(), "Microsoft-IIS"))) { if(log.isDebugEnabled()) { log.debug("Microsoft-IIS backend detected"); } list = new MicrosoftIISDAVListService(DAVSession.this, new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this)); timestamp = new MicrosoftIISDAVTimestampFeature(DAVSession.this); attributes = new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this); if(preferences.getBoolean("webdav.microsoftiis.header.translate")) { read = new MicrosoftIISDAVReadFeature(DAVSession.this); find = new MicrosoftIISDAVFindFeature(DAVSession.this); } } this.validateResponse(response); return null; } }); } catch(SardineException e) { switch(e.getStatusCode()) { case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_METHOD_NOT_ALLOWED: log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase())); cancel.verify(); this.getFeature(ListService.class).list(home, new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { try { cancel.verify(); } catch(ConnectionCanceledException e) { throw new ListCanceledException(list, e); } } }); break; case HttpStatus.SC_BAD_REQUEST: if(preferences.getBoolean("webdav.basic.preemptive")) { log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase())); cancel.verify(); client.disablePreemptiveAuthentication(); client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new VoidResponseHandler()); } else { throw new DAVExceptionMappingService().map(e); } break; default: throw new DAVExceptionMappingService().map(e); } } } catch(SardineException e) { throw new DAVExceptionMappingService().map(e); } catch(IOException e) { throw new HttpExceptionMappingService().map(e); } } DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key);  DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key, final RedirectCallback redirect); }
DAVSession extends HttpSession<DAVClient> { @Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final CredentialsProvider provider = new BasicCredentialsProvider(); if(preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)) ); } else { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); } provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); client.setCredentials(provider); if(preferences.getBoolean("webdav.basic.preemptive")) { switch(proxy.getType()) { case DIRECT: case SOCKS: client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")) ); break; default: client.disablePreemptiveAuthentication(); } } else { client.disablePreemptiveAuthentication(); } if(host.getCredentials().isPassed()) { log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this)); return; } try { final Path home = new DefaultHomeFinderService(this).find(); try { client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new ValidatingResponseHandler<Void>() { @Override public Void handleResponse(final HttpResponse response) throws IOException { if(Arrays.stream(response.getAllHeaders()).anyMatch(header -> HttpHeaders.SERVER.equals(header.getName()) && StringUtils.contains(header.getValue(), "Microsoft-IIS"))) { if(log.isDebugEnabled()) { log.debug("Microsoft-IIS backend detected"); } list = new MicrosoftIISDAVListService(DAVSession.this, new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this)); timestamp = new MicrosoftIISDAVTimestampFeature(DAVSession.this); attributes = new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this); if(preferences.getBoolean("webdav.microsoftiis.header.translate")) { read = new MicrosoftIISDAVReadFeature(DAVSession.this); find = new MicrosoftIISDAVFindFeature(DAVSession.this); } } this.validateResponse(response); return null; } }); } catch(SardineException e) { switch(e.getStatusCode()) { case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_METHOD_NOT_ALLOWED: log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase())); cancel.verify(); this.getFeature(ListService.class).list(home, new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { try { cancel.verify(); } catch(ConnectionCanceledException e) { throw new ListCanceledException(list, e); } } }); break; case HttpStatus.SC_BAD_REQUEST: if(preferences.getBoolean("webdav.basic.preemptive")) { log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase())); cancel.verify(); client.disablePreemptiveAuthentication(); client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new VoidResponseHandler()); } else { throw new DAVExceptionMappingService().map(e); } break; default: throw new DAVExceptionMappingService().map(e); } } } catch(SardineException e) { throw new DAVExceptionMappingService().map(e); } catch(IOException e) { throw new HttpExceptionMappingService().map(e); } } DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key);  DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key, final RedirectCallback redirect); @Override DAVClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt); @Override void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel); @Override boolean alert(final ConnectionCallback callback); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); }
DAVSession extends HttpSession<DAVClient> { @Override public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final CredentialsProvider provider = new BasicCredentialsProvider(); if(preferences.getBoolean("webdav.ntlm.windows.authentication.enable") && WinHttpClients.isWinAuthAvailable()) { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new WindowsCredentialsProvider(new BasicCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM)) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider()).getCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO)) ); } else { provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new NTCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword(), preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain")) ); } provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.BASIC), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.DIGEST), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); provider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.KERBEROS), new UsernamePasswordCredentials(host.getCredentials().getUsername(), host.getCredentials().getPassword())); client.setCredentials(provider); if(preferences.getBoolean("webdav.basic.preemptive")) { switch(proxy.getType()) { case DIRECT: case SOCKS: client.enablePreemptiveAuthentication(host.getHostname(), host.getPort(), host.getPort(), Charset.forName(preferences.getProperty("http.credentials.charset")) ); break; default: client.disablePreemptiveAuthentication(); } } else { client.disablePreemptiveAuthentication(); } if(host.getCredentials().isPassed()) { log.warn(String.format("Skip verifying credentials with previous successful authentication event for %s", this)); return; } try { final Path home = new DefaultHomeFinderService(this).find(); try { client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new ValidatingResponseHandler<Void>() { @Override public Void handleResponse(final HttpResponse response) throws IOException { if(Arrays.stream(response.getAllHeaders()).anyMatch(header -> HttpHeaders.SERVER.equals(header.getName()) && StringUtils.contains(header.getValue(), "Microsoft-IIS"))) { if(log.isDebugEnabled()) { log.debug("Microsoft-IIS backend detected"); } list = new MicrosoftIISDAVListService(DAVSession.this, new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this)); timestamp = new MicrosoftIISDAVTimestampFeature(DAVSession.this); attributes = new MicrosoftIISDAVAttributesFinderFeature(DAVSession.this); if(preferences.getBoolean("webdav.microsoftiis.header.translate")) { read = new MicrosoftIISDAVReadFeature(DAVSession.this); find = new MicrosoftIISDAVFindFeature(DAVSession.this); } } this.validateResponse(response); return null; } }); } catch(SardineException e) { switch(e.getStatusCode()) { case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_METHOD_NOT_ALLOWED: log.warn(String.format("Failed HEAD request to %s with %s. Retry with PROPFIND.", host, e.getResponsePhrase())); cancel.verify(); this.getFeature(ListService.class).list(home, new DisabledListProgressListener() { @Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { try { cancel.verify(); } catch(ConnectionCanceledException e) { throw new ListCanceledException(list, e); } } }); break; case HttpStatus.SC_BAD_REQUEST: if(preferences.getBoolean("webdav.basic.preemptive")) { log.warn(String.format("Disable preemptive authentication for %s due to failure %s", host, e.getResponsePhrase())); cancel.verify(); client.disablePreemptiveAuthentication(); client.execute(new HttpHead(new DAVPathEncoder().encode(home)), new VoidResponseHandler()); } else { throw new DAVExceptionMappingService().map(e); } break; default: throw new DAVExceptionMappingService().map(e); } } } catch(SardineException e) { throw new DAVExceptionMappingService().map(e); } catch(IOException e) { throw new HttpExceptionMappingService().map(e); } } DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key);  DAVSession(final Host host, final X509TrustManager trust, final X509KeyManager key, final RedirectCallback redirect); @Override DAVClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt); @Override void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel); @Override boolean alert(final ConnectionCallback callback); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type);  }