Skip to content

Commit

Permalink
Merge pull request #16677 from iterate-ch/bugfix/SDS-1537
Browse files Browse the repository at this point in the history
Conditionally save credentials in keychain after retry.
  • Loading branch information
dkocher authored Dec 17, 2024
2 parents d64c92a + daeb7d7 commit cd8817c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.cyberduck.core.DefaultIOExceptionMappingService;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.HostUrlProvider;
import ch.cyberduck.core.LoginOptions;
import ch.cyberduck.core.PasswordCallback;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.ConnectionCanceledException;
Expand Down Expand Up @@ -134,6 +135,7 @@ public JsonObject handleEntity(final HttpEntity entity) throws IOException {
}
if(json.has("password")) {
credentials.setPassword(json.getAsJsonPrimitive("password").getAsString());
credentials.setSaved(new LoginOptions().save);
}
else {
throw new LoginFailureException(String.format("Invalid response for pairing key %s", token));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public boolean retryRequest(final HttpResponse response, final int executionCoun
LocaleFactory.localizedString("You've been logged out", "Brick"),
LocaleFactory.localizedString("Please complete the login process in your browser.", "Brick")
);
store.save(session.getHost());
if(credentials.isSaved()) {
store.save(session.getHost());
}
apiKey = credentials.getPassword();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import ch.cyberduck.core.BookmarkNameProvider;
import ch.cyberduck.core.Credentials;
import ch.cyberduck.core.DefaultIOExceptionMappingService;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.HostPasswordStore;
Expand Down Expand Up @@ -151,10 +152,12 @@ public CteraTokens validate() throws BackgroundException {
*/
public CteraTokens save(final CteraTokens tokens) throws LocalAccessDeniedException {
log.debug("Save new tokens {} for {}", tokens, host);
host.getCredentials()
.withToken(String.format("%s:%s", tokens.getDeviceId(), tokens.getSharedSecret()))
final Credentials credentials = host.getCredentials();
credentials.withToken(String.format("%s:%s", tokens.getDeviceId(), tokens.getSharedSecret()))
.withSaved(new LoginOptions().save);
store.save(host);
if(credentials.isSaved()) {
store.save(host);
}
return tokens;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public Credentials validate() throws BackgroundException {
public OAuthTokens save(final OAuthTokens tokens) throws LocalAccessDeniedException {
log.debug("Save new tokens {} for {}", tokens, host);
credentials.withOauth(tokens).withSaved(new LoginOptions().save);
store.save(host);
if(credentials.isSaved()) {
store.save(host);
}
return tokens;
}

Expand Down

0 comments on commit cd8817c

Please sign in to comment.