Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 88f8f0d

Browse files
author
Irene
committed
Migrate password to oauth, update core version
Migrate password each time that a new account is set
1 parent 47c681d commit 88f8f0d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/backend/Settings.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fi.helsinki.cs.tmc.cli.io.EnvironmentUtil;
44
import fi.helsinki.cs.tmc.cli.io.WorkDir;
55

6+
import fi.helsinki.cs.tmc.core.communication.oauth2.Oauth;
67
import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
78
import fi.helsinki.cs.tmc.core.domain.Course;
89

@@ -11,12 +12,17 @@
1112
import fi.helsinki.cs.tmc.core.domain.Organization;
1213
import fi.helsinki.cs.tmc.spyware.SpywareSettings;
1314
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
15+
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
16+
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
1419

1520
import java.nio.file.Path;
1621
import java.util.Locale;
1722

1823
public class Settings implements TmcSettings, SpywareSettings {
1924

25+
private static final Logger logger = LoggerFactory.getLogger(Settings.class);
2026
private WorkDir workDir;
2127
private Account account;
2228

@@ -36,6 +42,16 @@ public void setAccount(Account account) {
3642
if (account == null) {
3743
account = new Account();
3844
}
45+
try {
46+
Optional<String> password = account.getPassword();
47+
if(password.isPresent()) {
48+
Oauth.getInstance().fetchNewToken(password.get());
49+
account.setPassword(Optional.absent());
50+
SettingsIo.saveCurrentSettingsToAccountList(this);
51+
}
52+
} catch (OAuthProblemException | OAuthSystemException var1) {
53+
logger.warn("Settings migration failed.");
54+
}
3955
this.account = account;
4056
}
4157

0 commit comments

Comments
 (0)