1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-30 13:13:58 +01:00

Remove old replaced authentication classes

This commit is contained in:
Henry Le Grys 2021-02-08 21:46:33 +00:00
parent 194e977176
commit 3ddaea55dc
5 changed files with 64 additions and 297 deletions

View File

@ -12,8 +12,8 @@ import com.google.common.base.Strings;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.skcraft.launcher.auth.AccountList;
import com.skcraft.launcher.auth.LoginService; import com.skcraft.launcher.auth.LoginService;
import com.skcraft.launcher.auth.NewAccountList;
import com.skcraft.launcher.auth.UserType; import com.skcraft.launcher.auth.UserType;
import com.skcraft.launcher.auth.YggdrasilLoginService; import com.skcraft.launcher.auth.YggdrasilLoginService;
import com.skcraft.launcher.launch.LaunchSupervisor; import com.skcraft.launcher.launch.LaunchSupervisor;
@ -64,7 +64,7 @@ public final class Launcher {
@Getter private final Properties properties; @Getter private final Properties properties;
@Getter private final InstanceList instances; @Getter private final InstanceList instances;
@Getter private final Configuration config; @Getter private final Configuration config;
@Getter private final NewAccountList accounts; @Getter private final AccountList accounts;
@Getter private final AssetsRoot assets; @Getter private final AssetsRoot assets;
@Getter private final LaunchSupervisor launchSupervisor = new LaunchSupervisor(this); @Getter private final LaunchSupervisor launchSupervisor = new LaunchSupervisor(this);
@Getter private final UpdateManager updateManager = new UpdateManager(this); @Getter private final UpdateManager updateManager = new UpdateManager(this);
@ -97,7 +97,7 @@ public final class Launcher {
this.instances = new InstanceList(this); this.instances = new InstanceList(this);
this.assets = new AssetsRoot(new File(baseDir, "assets")); this.assets = new AssetsRoot(new File(baseDir, "assets"));
this.config = Persistence.load(new File(configDir, "config.json"), Configuration.class); this.config = Persistence.load(new File(configDir, "config.json"), Configuration.class);
this.accounts = Persistence.load(new File(configDir, "accounts.dat"), NewAccountList.class); this.accounts = Persistence.load(new File(configDir, "accounts.dat"), AccountList.class);
setDefaultConfig(); setDefaultConfig();

View File

@ -1,91 +0,0 @@
/*
* SK's Minecraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
* Please see LICENSE.txt for license information.
*/
package com.skcraft.launcher.auth;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.base.Strings;
import lombok.Data;
import lombok.NonNull;
import java.util.Date;
/**
* A user account that can be stored and loaded.
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account implements Comparable<Account> {
private String id;
private String password;
private Date lastUsed;
/**
* Create a new account.
*/
public Account() {
}
/**
* Create a new account with the given ID.
*
* @param id the ID
*/
public Account(String id) {
setId(id);
}
/**
* Set the account's stored password, that may be stored to disk.
*
* @param password the password
*/
public void setPassword(String password) {
if (password != null && password.isEmpty()) {
password = null;
}
this.password = Strings.emptyToNull(password);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Account account = (Account) o;
if (!id.equalsIgnoreCase(account.id)) return false;
return true;
}
@Override
public int hashCode() {
return id.toLowerCase().hashCode();
}
@Override
public int compareTo(@NonNull Account o) {
Date otherDate = o.getLastUsed();
if (otherDate == null && lastUsed == null) {
return 0;
} else if (otherDate == null) {
return -1;
} else if (lastUsed == null) {
return 1;
} else {
return -lastUsed.compareTo(otherDate);
}
}
@Override
public String toString() {
return getId();
}
}

View File

@ -1,134 +1,78 @@
/*
* SK's Minecraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
* Please see LICENSE.txt for license information.
*/
package com.skcraft.launcher.auth; package com.skcraft.launcher.auth;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.beust.jcommander.internal.Lists;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.skcraft.launcher.dialog.component.ListListenerReducer;
import com.skcraft.launcher.persistence.Scrambled; import com.skcraft.launcher.persistence.Scrambled;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang.RandomStringUtils;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList; import javax.swing.event.ListDataEvent;
import java.util.Collections; import javax.swing.event.ListDataListener;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* A list of accounts that can be stored to disk. * Persisted account list
*/ */
@Scrambled("ACCOUNT_LIST") @Scrambled("ACCOUNT_LIST_NOT_SECURITY!")
@Getter
@Setter
@ToString
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect( public class AccountList implements ListModel<SavedSession> {
getterVisibility = JsonAutoDetect.Visibility.NONE, private List<SavedSession> accounts = Lists.newArrayList();
setterVisibility = JsonAutoDetect.Visibility.NONE, private String clientId = RandomStringUtils.randomAlphanumeric(24);
fieldVisibility = JsonAutoDetect.Visibility.NONE)
public class AccountList extends AbstractListModel<Account> implements ComboBoxModel<Account> {
@JsonProperty @JsonIgnore private final ListListenerReducer listeners = new ListListenerReducer();
@Getter
private List<Account> accounts = new ArrayList<Account>();
private transient Account selected;
/** public synchronized void add(SavedSession session) {
* Add a new account. accounts.add(session);
*
* <p>If there is already an existing account with the same ID, then the
* new account will not be added.</p>
*
* @param account the account to add
*/
public synchronized void add(@NonNull Account account) {
if (!accounts.contains(account)) {
accounts.add(account);
Collections.sort(accounts);
fireContentsChanged(this, 0, accounts.size());
}
}
/** int index = accounts.size() - 1;
* Remove an account. listeners.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
* }
* @param account the account
*/
public synchronized void remove(@NonNull Account account) {
Iterator<Account> it = accounts.iterator();
while (it.hasNext()) {
Account other = it.next();
if (other.equals(account)) {
it.remove();
fireContentsChanged(this, 0, accounts.size() + 1);
break;
}
}
}
/** public synchronized void remove(SavedSession session) {
* Set the list of accounts. int index = accounts.indexOf(session);
*
* @param accounts the list of accounts
*/
public synchronized void setAccounts(@NonNull List<Account> accounts) {
this.accounts = accounts;
Collections.sort(accounts);
}
@Override if (index > -1) {
@JsonIgnore accounts.remove(index);
public synchronized int getSize() { listeners.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
return accounts.size(); }
} }
@Override public synchronized void update(SavedSession newSavedSession) {
public synchronized Account getElementAt(int index) { int index = accounts.indexOf(newSavedSession);
try {
return accounts.get(index);
} catch (IndexOutOfBoundsException e) {
return null;
}
}
@Override if (index > -1) {
public void setSelectedItem(Object item) { accounts.set(index, newSavedSession);
if (item == null) { listeners.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
selected = null; } else {
return; this.add(newSavedSession);
} }
}
if (item instanceof Account) { @Override
this.selected = (Account) item; public int getSize() {
} else { return accounts.size();
String id = String.valueOf(item).trim(); }
Account account = new Account(id);
for (Account test : accounts) {
if (test.equals(account)) {
account = test;
break;
}
}
selected = account;
}
if (selected.getId() == null || selected.getId().isEmpty()) { @Override
selected = null; public SavedSession getElementAt(int index) {
} return accounts.get(index);
} }
@Override @Override
@JsonIgnore public void addListDataListener(ListDataListener l) {
public Account getSelectedItem() { listeners.addListDataListener(l);
return selected; }
}
public synchronized void forgetPasswords() { @Override
for (Account account : accounts) { public void removeListDataListener(ListDataListener l) {
account.setPassword(null); listeners.removeListDataListener(l);
} }
}
} }

View File

@ -1,78 +0,0 @@
package com.skcraft.launcher.auth;
import com.beust.jcommander.internal.Lists;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.skcraft.launcher.dialog.component.ListListenerReducer;
import com.skcraft.launcher.persistence.Scrambled;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang.RandomStringUtils;
import javax.swing.*;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.util.List;
/**
* Persisted account list
*/
@Scrambled("ACCOUNT_LIST_NOT_SECURITY!")
@Getter
@Setter
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class NewAccountList implements ListModel<SavedSession> {
private List<SavedSession> accounts = Lists.newArrayList();
private String clientId = RandomStringUtils.randomAlphanumeric(24);
@JsonIgnore private final ListListenerReducer listeners = new ListListenerReducer();
public synchronized void add(SavedSession session) {
accounts.add(session);
int index = accounts.size() - 1;
listeners.intervalAdded(new ListDataEvent(this, ListDataEvent.INTERVAL_ADDED, index, index));
}
public synchronized void remove(SavedSession session) {
int index = accounts.indexOf(session);
if (index > -1) {
accounts.remove(index);
listeners.intervalRemoved(new ListDataEvent(this, ListDataEvent.INTERVAL_REMOVED, index, index));
}
}
public synchronized void update(SavedSession newSavedSession) {
int index = accounts.indexOf(newSavedSession);
if (index > -1) {
accounts.set(index, newSavedSession);
listeners.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
} else {
this.add(newSavedSession);
}
}
@Override
public int getSize() {
return accounts.size();
}
@Override
public SavedSession getElementAt(int index) {
return accounts.get(index);
}
@Override
public void addListDataListener(ListDataListener l) {
listeners.addListDataListener(l);
}
@Override
public void removeListDataListener(ListDataListener l) {
listeners.removeListDataListener(l);
}
}

View File

@ -12,7 +12,6 @@ import com.skcraft.concurrency.ObservableFuture;
import com.skcraft.concurrency.ProgressObservable; import com.skcraft.concurrency.ProgressObservable;
import com.skcraft.launcher.Configuration; import com.skcraft.launcher.Configuration;
import com.skcraft.launcher.Launcher; import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.auth.Account;
import com.skcraft.launcher.auth.AuthenticationException; import com.skcraft.launcher.auth.AuthenticationException;
import com.skcraft.launcher.auth.Session; import com.skcraft.launcher.auth.Session;
import com.skcraft.launcher.auth.YggdrasilLoginService; import com.skcraft.launcher.auth.YggdrasilLoginService;
@ -22,13 +21,13 @@ import com.skcraft.launcher.util.SharedLocale;
import com.skcraft.launcher.util.SwingExecutor; import com.skcraft.launcher.util.SwingExecutor;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
@ -112,18 +111,15 @@ public class LoginDialog extends JDialog {
if (password == null || password.isEmpty()) { if (password == null || password.isEmpty()) {
SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noPasswordError"), SharedLocale.tr("login.noPasswordTitle")); SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noPasswordError"), SharedLocale.tr("login.noPasswordTitle"));
} else { } else {
Account account = new Account(usernameText.getText()); attemptLogin(usernameText.getText(), password);
account.setLastUsed(new Date());
attemptLogin(account, password);
} }
} else { } else {
SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noLoginError"), SharedLocale.tr("login.noLoginTitle")); SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noLoginError"), SharedLocale.tr("login.noLoginTitle"));
} }
} }
private void attemptLogin(Account account, String password) { private void attemptLogin(String username, String password) {
LoginCallable callable = new LoginCallable(account, password); LoginCallable callable = new LoginCallable(username, password);
ObservableFuture<Session> future = new ObservableFuture<Session>( ObservableFuture<Session> future = new ObservableFuture<Session>(
launcher.getExecutor().submit(callable), callable); launcher.getExecutor().submit(callable), callable);
@ -153,19 +149,15 @@ public class LoginDialog extends JDialog {
return dialog.getSession(); return dialog.getSession();
} }
private class LoginCallable implements Callable<Session>,ProgressObservable { @RequiredArgsConstructor
private final Account account; private class LoginCallable implements Callable<Session>, ProgressObservable {
private final String username;
private final String password; private final String password;
private LoginCallable(Account account, String password) {
this.account = account;
this.password = password;
}
@Override @Override
public Session call() throws AuthenticationException, IOException, InterruptedException { public Session call() throws AuthenticationException, IOException, InterruptedException {
YggdrasilLoginService service = launcher.getYggdrasil(); YggdrasilLoginService service = launcher.getYggdrasil();
Session identity = service.login(launcher.getProperties().getProperty("agentName"), account.getId(), password); Session identity = service.login(launcher.getProperties().getProperty("agentName"), username, password);
// The presence of the identity (profile in Mojang terms) corresponds to whether the account // The presence of the identity (profile in Mojang terms) corresponds to whether the account
// owns the game, so we need to check that // owns the game, so we need to check that