Skip to content

Commit ad50c4e

Browse files
authored
Merge pull request #17614 from iterate-ch/bugfix/GH-17437-savedtokens
Remove interceptors for STS and simplify token handling setup
2 parents 1160375 + 9c7e1cc commit ad50c4e

File tree

40 files changed

+242
-381
lines changed

40 files changed

+242
-381
lines changed

azure/src/main/java/ch/cyberduck/core/azure/AzureSession.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import ch.cyberduck.core.Credentials;
19+
import ch.cyberduck.core.DefaultIOExceptionMappingService;
1920
import ch.cyberduck.core.Host;
2021
import ch.cyberduck.core.HostKeyCallback;
2122
import ch.cyberduck.core.HostUrlProvider;
@@ -38,6 +39,7 @@
3839
import org.apache.logging.log4j.LogManager;
3940
import org.apache.logging.log4j.Logger;
4041

42+
import java.io.IOException;
4143
import java.util.Collections;
4244

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

144146
@Override
145-
protected void logout() {
146-
//
147+
public void disconnect() throws BackgroundException {
148+
try {
149+
if(client != null) {
150+
try {
151+
((ApacheHttpClient) client.getHttpPipeline().getHttpClient()).getHttpClient().close();
152+
}
153+
catch(IOException e) {
154+
throw new DefaultIOExceptionMappingService().map(e);
155+
}
156+
}
157+
}
158+
finally {
159+
super.disconnect();
160+
}
147161
}
148162

149163
@Override

azure/src/main/java/ch/cyberduck/core/azure/apache/ApacheHttpClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.lang3.StringUtils;
2121
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
2222
import org.apache.http.entity.ByteArrayEntity;
23+
import org.apache.http.impl.client.CloseableHttpClient;
2324
import org.apache.http.impl.client.HttpClientBuilder;
2425
import org.apache.http.protocol.HTTP;
2526
import reactor.core.publisher.Mono;
@@ -29,12 +30,16 @@
2930
import java.net.URL;
3031

3132
public class ApacheHttpClient implements HttpClient {
32-
private final org.apache.http.client.HttpClient httpClient;
33+
private final CloseableHttpClient httpClient;
3334

3435
public ApacheHttpClient(final HttpClientBuilder builder) {
3536
this.httpClient = builder.build();
3637
}
3738

39+
public CloseableHttpClient getHttpClient() {
40+
return httpClient;
41+
}
42+
3843
public Mono<HttpResponse> send(final HttpRequest azureRequest) {
3944
try {
4045
ApacheHttpRequest apacheRequest = new ApacheHttpRequest(azureRequest.getHttpMethod(), azureRequest.getUrl(),

backblaze/src/main/java/ch/cyberduck/core/b2/B2Session.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ protected B2ApiClient connect(final ProxyFinder proxy, final HostKeyCallback key
6868
}
6969

7070
@Override
71-
public void logout() throws BackgroundException {
71+
public void disconnect() throws BackgroundException {
7272
try {
73+
fileid.clear();
7374
client.close();
7475
}
7576
catch(IOException e) {
7677
throw new DefaultIOExceptionMappingService().map(e);
7778
}
7879
finally {
79-
fileid.clear();
80+
super.disconnect();
8081
}
8182
}
8283

box/src/main/java/ch/cyberduck/core/box/BoxSession.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
8787
}
8888

8989
@Override
90-
protected void logout() throws BackgroundException {
90+
public void disconnect() throws BackgroundException {
9191
try {
92+
fileid.clear();
9293
client.close();
9394
}
9495
catch(IOException e) {
9596
throw new DefaultIOExceptionMappingService().map(e);
9697
}
9798
finally {
98-
fileid.clear();
99+
super.disconnect();
99100
}
100101
}
101102

brick/src/main/java/ch/cyberduck/core/brick/BrickSession.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,18 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
111111
}
112112

113113
@Override
114-
protected void logout() throws BackgroundException {
114+
public void disconnect() throws BackgroundException {
115115
try {
116-
client.close();
116+
if(client != null) {
117+
client.close();
118+
}
117119
}
118120
catch(IOException e) {
119121
throw new DefaultIOExceptionMappingService().map(e);
120122
}
123+
finally {
124+
super.disconnect();
125+
}
121126
}
122127

123128
public Credentials pair(final Host bookmark, final ConnectionCallback alert, final LoginCallback prompt, final CancelCallback cancel,

core/src/main/java/ch/cyberduck/core/CopyCredentialsHolder.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

core/src/main/java/ch/cyberduck/core/Credentials.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public Credentials() {
8282
public Credentials(final Credentials copy) {
8383
this.user = copy.user;
8484
this.password = copy.password;
85-
this.tokens = copy.tokens;
86-
this.oauth = copy.oauth;
85+
this.tokens = TemporaryAccessTokens.EMPTY == copy.tokens ? TemporaryAccessTokens.EMPTY : new TemporaryAccessTokens(copy.tokens);
86+
this.oauth = OAuthTokens.EMPTY == copy.oauth ? OAuthTokens.EMPTY : new OAuthTokens(copy.oauth);
8787
this.properties.putAll(copy.properties);
8888
this.identity = copy.identity;
8989
this.identityPassphrase = copy.identityPassphrase;

core/src/main/java/ch/cyberduck/core/DefaultHostPasswordStore.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,36 @@ public OAuthTokens findOAuthTokens(final Host bookmark) {
163163
}
164164

165165
protected static Scheme getOAuthScheme(final Host bookmark) {
166-
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
167-
if(null == uri.getScheme()) {
168-
return bookmark.getProtocol().getScheme();
166+
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
167+
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
168+
if(null == uri.getScheme()) {
169+
return bookmark.getProtocol().getScheme();
170+
}
171+
return Scheme.valueOf(uri.getScheme());
169172
}
170-
return Scheme.valueOf(uri.getScheme());
173+
return null;
171174
}
172175

173176
protected static String getOAuthHostname(final Host bookmark) {
174-
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
175-
if(StringUtils.isNotBlank(uri.getHost())) {
176-
return uri.getHost();
177+
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
178+
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
179+
if(StringUtils.isNotBlank(uri.getHost())) {
180+
return uri.getHost();
181+
}
182+
return bookmark.getHostname();
177183
}
178-
return bookmark.getHostname();
184+
return null;
179185
}
180186

181187
protected static int getOAuthPort(final Host bookmark) {
182-
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
183-
if(-1 != uri.getPort()) {
184-
return uri.getPort();
188+
if(null != bookmark.getProtocol().getOAuthTokenUrl()) {
189+
final URI uri = URI.create(bookmark.getProtocol().getOAuthTokenUrl());
190+
if(-1 != uri.getPort()) {
191+
return uri.getPort();
192+
}
193+
return getOAuthScheme(bookmark).getPort();
185194
}
186-
return getOAuthScheme(bookmark).getPort();
195+
return -1;
187196
}
188197

189198
protected static Set<String> getOAuthPrefix(final Host bookmark) {

core/src/main/java/ch/cyberduck/core/KeychainLoginService.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void validate(final Host bookmark, final LoginCallback prompt, final Logi
8585
if(options.oauth) {
8686
final OAuthTokens tokens = keychain.findOAuthTokens(bookmark);
8787
if(tokens.validate()) {
88-
log.info("Fetched OAuth token from keychain for {}", bookmark);
88+
log.info("Fetched OAuth tokens {} from keychain for {}", tokens, bookmark);
8989
// No need to reinsert found token to the keychain.
9090
credentials.setOauth(tokens).setSaved(tokens.isExpired());
9191
}
@@ -213,11 +213,5 @@ public void save(final Host bookmark) {
213213
else {
214214
log.info("Skip writing credentials for bookmark {}", bookmark.getHostname());
215215
}
216-
// Nullify password and tokens
217-
log.debug("Reset credentials for {}", bookmark);
218-
switch(bookmark.getProtocol().getStatefulness()) {
219-
case stateless:
220-
credentials.reset();
221-
}
222216
}
223217
}

core/src/main/java/ch/cyberduck/core/Session.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ public void interrupt() throws BackgroundException {
200200
}
201201
}
202202

203-
protected abstract void logout() throws BackgroundException;
203+
protected void logout() throws BackgroundException {
204+
host.getCredentials().reset();
205+
}
204206

205207
/**
206208
* Close the connection to the remote host. Subsequent calls to #getClient() must return null.
207209
*/
208-
protected void disconnect() {
210+
protected void disconnect() throws BackgroundException {
209211
state = State.closed;
210212
listeners.clear();
211213
}

0 commit comments

Comments
 (0)