1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +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.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.skcraft.launcher.auth.AccountList;
import com.skcraft.launcher.auth.LoginService;
import com.skcraft.launcher.auth.NewAccountList;
import com.skcraft.launcher.auth.UserType;
import com.skcraft.launcher.auth.YggdrasilLoginService;
import com.skcraft.launcher.launch.LaunchSupervisor;
@ -64,7 +64,7 @@ public final class Launcher {
@Getter private final Properties properties;
@Getter private final InstanceList instances;
@Getter private final Configuration config;
@Getter private final NewAccountList accounts;
@Getter private final AccountList accounts;
@Getter private final AssetsRoot assets;
@Getter private final LaunchSupervisor launchSupervisor = new LaunchSupervisor(this);
@Getter private final UpdateManager updateManager = new UpdateManager(this);
@ -97,7 +97,7 @@ public final class Launcher {
this.instances = new InstanceList(this);
this.assets = new AssetsRoot(new File(baseDir, "assets"));
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();

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;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.beust.jcommander.internal.Lists;
import com.fasterxml.jackson.annotation.JsonIgnore;
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 lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang.RandomStringUtils;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.util.List;
/**
* A list of accounts that can be stored to disk.
* Persisted account list
*/
@Scrambled("ACCOUNT_LIST")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(
getterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE,
fieldVisibility = JsonAutoDetect.Visibility.NONE)
public class AccountList extends AbstractListModel<Account> implements ComboBoxModel<Account> {
@JsonProperty
@Scrambled("ACCOUNT_LIST_NOT_SECURITY!")
@Getter
private List<Account> accounts = new ArrayList<Account>();
private transient Account selected;
@Setter
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class AccountList implements ListModel<SavedSession> {
private List<SavedSession> accounts = Lists.newArrayList();
private String clientId = RandomStringUtils.randomAlphanumeric(24);
/**
* Add a new account.
*
* <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());
@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));
}
}
/**
* Remove an account.
*
* @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 update(SavedSession newSavedSession) {
int index = accounts.indexOf(newSavedSession);
/**
* Set the list of accounts.
*
* @param accounts the list of accounts
*/
public synchronized void setAccounts(@NonNull List<Account> accounts) {
this.accounts = accounts;
Collections.sort(accounts);
if (index > -1) {
accounts.set(index, newSavedSession);
listeners.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, index, index));
} else {
this.add(newSavedSession);
}
}
@Override
@JsonIgnore
public synchronized int getSize() {
public int getSize() {
return accounts.size();
}
@Override
public synchronized Account getElementAt(int index) {
try {
public SavedSession getElementAt(int index) {
return accounts.get(index);
} catch (IndexOutOfBoundsException e) {
return null;
}
}
@Override
public void setSelectedItem(Object item) {
if (item == null) {
selected = null;
return;
}
if (item instanceof Account) {
this.selected = (Account) item;
} else {
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()) {
selected = null;
}
public void addListDataListener(ListDataListener l) {
listeners.addListDataListener(l);
}
@Override
@JsonIgnore
public Account getSelectedItem() {
return selected;
}
public synchronized void forgetPasswords() {
for (Account account : accounts) {
account.setPassword(null);
}
public void removeListDataListener(ListDataListener l) {
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.launcher.Configuration;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.auth.Account;
import com.skcraft.launcher.auth.AuthenticationException;
import com.skcraft.launcher.auth.Session;
import com.skcraft.launcher.auth.YggdrasilLoginService;
@ -22,13 +21,13 @@ import com.skcraft.launcher.util.SharedLocale;
import com.skcraft.launcher.util.SwingExecutor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.Callable;
/**
@ -112,18 +111,15 @@ public class LoginDialog extends JDialog {
if (password == null || password.isEmpty()) {
SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noPasswordError"), SharedLocale.tr("login.noPasswordTitle"));
} else {
Account account = new Account(usernameText.getText());
account.setLastUsed(new Date());
attemptLogin(account, password);
attemptLogin(usernameText.getText(), password);
}
} else {
SwingHelper.showErrorDialog(this, SharedLocale.tr("login.noLoginError"), SharedLocale.tr("login.noLoginTitle"));
}
}
private void attemptLogin(Account account, String password) {
LoginCallable callable = new LoginCallable(account, password);
private void attemptLogin(String username, String password) {
LoginCallable callable = new LoginCallable(username, password);
ObservableFuture<Session> future = new ObservableFuture<Session>(
launcher.getExecutor().submit(callable), callable);
@ -153,19 +149,15 @@ public class LoginDialog extends JDialog {
return dialog.getSession();
}
@RequiredArgsConstructor
private class LoginCallable implements Callable<Session>, ProgressObservable {
private final Account account;
private final String username;
private final String password;
private LoginCallable(Account account, String password) {
this.account = account;
this.password = password;
}
@Override
public Session call() throws AuthenticationException, IOException, InterruptedException {
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
// owns the game, so we need to check that