Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions azure/src/main/java/ch/cyberduck/core/azure/AzureSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import ch.cyberduck.core.Credentials;
import ch.cyberduck.core.DefaultIOExceptionMappingService;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.HostKeyCallback;
import ch.cyberduck.core.HostUrlProvider;
Expand All @@ -38,6 +39,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.Collections;

import com.azure.core.credential.AzureSasCredential;
Expand Down Expand Up @@ -142,8 +144,20 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
}

@Override
protected void logout() {
//
public void disconnect() throws BackgroundException {
try {
if(client != null) {
try {
((ApacheHttpClient) client.getHttpPipeline().getHttpClient()).getHttpClient().close();
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
}
}
finally {
super.disconnect();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HTTP;
import reactor.core.publisher.Mono;
Expand All @@ -29,12 +30,16 @@
import java.net.URL;

public class ApacheHttpClient implements HttpClient {
private final org.apache.http.client.HttpClient httpClient;
private final CloseableHttpClient httpClient;

public ApacheHttpClient(final HttpClientBuilder builder) {
this.httpClient = builder.build();
}

public CloseableHttpClient getHttpClient() {
return httpClient;
}

public Mono<HttpResponse> send(final HttpRequest azureRequest) {
try {
ApacheHttpRequest apacheRequest = new ApacheHttpRequest(azureRequest.getHttpMethod(), azureRequest.getUrl(),
Expand Down
5 changes: 3 additions & 2 deletions backblaze/src/main/java/ch/cyberduck/core/b2/B2Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ protected B2ApiClient connect(final ProxyFinder proxy, final HostKeyCallback key
}

@Override
public void logout() throws BackgroundException {
public void disconnect() throws BackgroundException {
try {
fileid.clear();
client.close();
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
finally {
fileid.clear();
super.disconnect();
}
}

Expand Down
5 changes: 3 additions & 2 deletions box/src/main/java/ch/cyberduck/core/box/BoxSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
}

@Override
protected void logout() throws BackgroundException {
public void disconnect() throws BackgroundException {
try {
fileid.clear();
client.close();
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
finally {
fileid.clear();
super.disconnect();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
}

@Override
protected void logout() throws BackgroundException {
public void disconnect() throws BackgroundException {
try {
client.close();
if(client != null) {
client.close();
}
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
finally {
super.disconnect();
}
}

public Credentials pair(final Host bookmark, final ConnectionCallback alert, final LoginCallback prompt, final CancelCallback cancel,
Expand Down
93 changes: 0 additions & 93 deletions core/src/main/java/ch/cyberduck/core/CopyCredentialsHolder.java

This file was deleted.

4 changes: 2 additions & 2 deletions core/src/main/java/ch/cyberduck/core/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Credentials() {
public Credentials(final Credentials copy) {
this.user = copy.user;
this.password = copy.password;
this.tokens = copy.tokens;
this.oauth = copy.oauth;
this.tokens = TemporaryAccessTokens.EMPTY == copy.tokens ? TemporaryAccessTokens.EMPTY : new TemporaryAccessTokens(copy.tokens);
this.oauth = OAuthTokens.EMPTY == copy.oauth ? OAuthTokens.EMPTY : new OAuthTokens(copy.oauth);
this.properties.putAll(copy.properties);
this.identity = copy.identity;
this.identityPassphrase = copy.identityPassphrase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,36 @@ public OAuthTokens findOAuthTokens(final Host bookmark) {
}

protected static Scheme getOAuthScheme(final Host bookmark) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(null == uri.getScheme()) {
return bookmark.getProtocol().getScheme();
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(null == uri.getScheme()) {
return bookmark.getProtocol().getScheme();
}
return Scheme.valueOf(uri.getScheme());
}
return Scheme.valueOf(uri.getScheme());
return null;
}

protected static String getOAuthHostname(final Host bookmark) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(StringUtils.isNotBlank(uri.getHost())) {
return uri.getHost();
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(StringUtils.isNotBlank(uri.getHost())) {
return uri.getHost();
}
return bookmark.getHostname();
}
return bookmark.getHostname();
return null;
}

protected static int getOAuthPort(final Host bookmark) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(-1 != uri.getPort()) {
return uri.getPort();
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
if(-1 != uri.getPort()) {
return uri.getPort();
}
return getOAuthScheme(bookmark).getPort();
}
return getOAuthScheme(bookmark).getPort();
return -1;
}

protected static Set<String> getOAuthPrefix(final Host bookmark) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void validate(final Host bookmark, final LoginCallback prompt, final Logi
if(options.oauth) {
final OAuthTokens tokens = keychain.findOAuthTokens(bookmark);
if(tokens.validate()) {
log.info("Fetched OAuth token from keychain for {}", bookmark);
log.info("Fetched OAuth tokens {} from keychain for {}", tokens, bookmark);
// No need to reinsert found token to the keychain.
credentials.setOauth(tokens).setSaved(tokens.isExpired());
}
Expand Down Expand Up @@ -213,11 +213,5 @@ public void save(final Host bookmark) {
else {
log.info("Skip writing credentials for bookmark {}", bookmark.getHostname());
}
// Nullify password and tokens
log.debug("Reset credentials for {}", bookmark);
switch(bookmark.getProtocol().getStatefulness()) {
case stateless:
credentials.reset();
}
}
}
6 changes: 4 additions & 2 deletions core/src/main/java/ch/cyberduck/core/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ public void interrupt() throws BackgroundException {
}
}

protected abstract void logout() throws BackgroundException;
protected void logout() throws BackgroundException {
host.getCredentials().reset();
}

/**
* Close the connection to the remote host. Subsequent calls to #getClient() must return null.
*/
protected void disconnect() {
protected void disconnect() throws BackgroundException {
state = State.closed;
listeners.clear();
}
Expand Down
5 changes: 0 additions & 5 deletions core/src/test/java/ch/cyberduck/core/NullSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
throw new LoginCanceledException();
}

@Override
protected void logout() {
//
}

@Override
public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws BackgroundException {
listener.chunk(folder, AttributedList.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,15 @@ protected void logout() throws BackgroundException {
}
finally {
super.logout();
versionid.clear();
}
}

@Override
public void disconnect() throws BackgroundException {
versionid.clear();
super.disconnect();
}

@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,15 @@ public DeepcloudApiClient getDeepcloudClient() {
}

@Override
protected void logout() {
client.getHttpClient().close();
public void disconnect() throws BackgroundException {
try {
if(client != null) {
client.getHttpClient().close();
}
}
finally {
super.disconnect();
}
}

@Override
Expand Down
15 changes: 11 additions & 4 deletions dracoon/src/main/java/ch/cyberduck/core/sds/SDSSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,17 @@ public int hashCode() {
}

@Override
protected void logout() {
scheduler.shutdown(false);
client.getHttpClient().close();
nodeid.clear();
public void disconnect() throws BackgroundException {
try {
scheduler.shutdown(false);
nodeid.clear();
if(client != null) {
client.getHttpClient().close();
}
}
finally {
super.disconnect();
}
}

@Override
Expand Down
Loading