Skip to content

Commit

Permalink
Fix #14876.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jul 2, 2023
1 parent 9df1f38 commit 71a56aa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
5 changes: 5 additions & 0 deletions owncloud/pom.xml
Expand Up @@ -39,6 +39,11 @@
<artifactId>webdav</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.cyberduck</groupId>
<artifactId>oauth</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
Expand Down
Expand Up @@ -17,8 +17,10 @@

import ch.cyberduck.core.Host;
import ch.cyberduck.core.ListService;
import ch.cyberduck.core.LoginCallback;
import ch.cyberduck.core.UrlProvider;
import ch.cyberduck.core.dav.DAVSession;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Home;
Expand All @@ -36,15 +38,49 @@
import ch.cyberduck.core.nextcloud.NextcloudShareProvider;
import ch.cyberduck.core.nextcloud.NextcloudUrlProvider;
import ch.cyberduck.core.nextcloud.NextcloudWriteFeature;
import ch.cyberduck.core.oauth.OAuth2AuthorizationService;
import ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor;
import ch.cyberduck.core.oauth.OAuth2RequestInterceptor;
import ch.cyberduck.core.proxy.Proxy;
import ch.cyberduck.core.ssl.X509KeyManager;
import ch.cyberduck.core.ssl.X509TrustManager;
import ch.cyberduck.core.threading.CancelCallback;

import org.apache.http.impl.client.HttpClientBuilder;

import com.sun.tools.javac.comp.Flow;

import static ch.cyberduck.core.oauth.OAuth2AuthorizationService.CYBERDUCK_REDIRECT_URI;

public class OwncloudSession extends DAVSession {

private OAuth2RequestInterceptor authorizationService;

public OwncloudSession(final Host host, final X509TrustManager trust, final X509KeyManager key) {
super(host, trust, key);
}

@Override
protected HttpClientBuilder getConfiguration(final Proxy proxy, final LoginCallback prompt) {
final HttpClientBuilder configuration = super.getConfiguration(proxy, prompt);
if(host.getProtocol().isOAuthConfigurable()) {
authorizationService = new OAuth2RequestInterceptor(configuration.build(), host)
.withFlowType(OAuth2AuthorizationService.FlowType.valueOf(host.getProtocol().getAuthorization()))
.withRedirectUri(CYBERDUCK_REDIRECT_URI);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(host, authorizationService, prompt));
}
return configuration;
}

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
if(host.getProtocol().isOAuthConfigurable()) {
authorizationService.authorize(host, prompt, cancel);
}
super.login(proxy, prompt, cancel);
}

@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
Expand Down
12 changes: 8 additions & 4 deletions webdav/src/main/java/ch/cyberduck/core/dav/DAVSession.java
Expand Up @@ -105,10 +105,14 @@ public DAVSession(final Host host, final X509TrustManager trust, final X509KeyMa

@Override
protected DAVClient connect(final Proxy proxy, final HostKeyCallback key, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
// Always inject new pool to builder on connect because the pool is shutdown on disconnect
final HttpClientBuilder pool = builder.build(proxy, this, prompt);
pool.setRedirectStrategy(new DAVRedirectStrategy(redirect));
return new DAVClient(new HostUrlProvider().withUsername(false).get(host), pool);
final HttpClientBuilder configuration = this.getConfiguration(proxy, prompt);
return new DAVClient(new HostUrlProvider().withUsername(false).get(host), configuration);
}

protected HttpClientBuilder getConfiguration(final Proxy proxy, final LoginCallback prompt) {
final HttpClientBuilder configuration = builder.build(proxy, this, prompt);
configuration.setRedirectStrategy(new DAVRedirectStrategy(redirect));
return configuration;
}

@Override
Expand Down

0 comments on commit 71a56aa

Please sign in to comment.