Skip to content

Commit

Permalink
Only set credentials provider for password authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Aug 7, 2023
1 parent 4bd0725 commit e4f3972
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,46 @@ protected void logout() throws BackgroundException {

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
final CredentialsProvider provider = new BasicCredentialsProvider();
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:
// Enable preemptive authentication. See HttpState#setAuthenticationPreemptive
client.enablePreemptiveAuthentication(host.getHostname(),
host.getPort(),
host.getPort(),
Charset.forName(preferences.getProperty("http.credentials.charset"))
);
break;
default:
client.disablePreemptiveAuthentication();
if(host.getProtocol().isPasswordConfigurable()) {
final CredentialsProvider provider = new BasicCredentialsProvider();
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:
// Enable preemptive authentication. See HttpState#setAuthenticationPreemptive
client.enablePreemptiveAuthentication(host.getHostname(),
host.getPort(),
host.getPort(),
Charset.forName(preferences.getProperty("http.credentials.charset"))
);
break;
default:
client.disablePreemptiveAuthentication();
}
}
else {
client.disablePreemptiveAuthentication();
}
}
else {
client.disablePreemptiveAuthentication();
}
if(host.getCredentials().isPassed()) {
if(log.isWarnEnabled()) {
Expand Down

0 comments on commit e4f3972

Please sign in to comment.