mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-13 13:56:55 -04:00
Register forbiddenTokens in MicrosoftSession and YggdrasilSession
This commit is contained in:
parent
151e7e04eb
commit
4d4864819a
@ -69,7 +69,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||||
import static org.jackhuang.hmcl.util.Lang.mapOf;
|
|
||||||
import static org.jackhuang.hmcl.util.Lang.resolveException;
|
import static org.jackhuang.hmcl.util.Lang.resolveException;
|
||||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||||
@ -700,7 +699,6 @@ public final class LauncherHelper {
|
|||||||
|
|
||||||
private final HMCLGameRepository repository;
|
private final HMCLGameRepository repository;
|
||||||
private final Version version;
|
private final Version version;
|
||||||
private final Map<String, String> forbiddenTokens;
|
|
||||||
private final LaunchOptions launchOptions;
|
private final LaunchOptions launchOptions;
|
||||||
private ManagedProcess process;
|
private ManagedProcess process;
|
||||||
private boolean lwjgl;
|
private boolean lwjgl;
|
||||||
@ -717,13 +715,6 @@ public final class LauncherHelper {
|
|||||||
this.launchingLatch = launchingLatch;
|
this.launchingLatch = launchingLatch;
|
||||||
this.detectWindow = detectWindow;
|
this.detectWindow = detectWindow;
|
||||||
|
|
||||||
if (authInfo == null)
|
|
||||||
forbiddenTokens = Collections.emptyMap();
|
|
||||||
else
|
|
||||||
forbiddenTokens = mapOf(
|
|
||||||
pair(authInfo.getAccessToken(), "<access token>")
|
|
||||||
);
|
|
||||||
|
|
||||||
logs = new LinkedList<>();
|
logs = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,8 +723,6 @@ public final class LauncherHelper {
|
|||||||
this.process = process;
|
this.process = process;
|
||||||
|
|
||||||
String command = new CommandBuilder().addAll(process.getCommands()).toString();
|
String command = new CommandBuilder().addAll(process.getCommands()).toString();
|
||||||
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet())
|
|
||||||
command = command.replace(entry.getKey(), entry.getValue());
|
|
||||||
|
|
||||||
LOG.info("Launched process: " + command);
|
LOG.info("Launched process: " + command);
|
||||||
|
|
||||||
@ -785,10 +774,7 @@ public final class LauncherHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onLog(String log, Log4jLevel level) {
|
public synchronized void onLog(String log, Log4jLevel level) {
|
||||||
String newLog = log;
|
String filteredLog = Logging.filterForbiddenToken(log);
|
||||||
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet())
|
|
||||||
newLog = newLog.replace(entry.getKey(), entry.getValue());
|
|
||||||
String filteredLog = newLog;
|
|
||||||
|
|
||||||
if (level.lessOrEqual(Log4jLevel.ERROR))
|
if (level.lessOrEqual(Log4jLevel.ERROR))
|
||||||
System.err.println(filteredLog);
|
System.err.println(filteredLog);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.jackhuang.hmcl.auth.microsoft;
|
package org.jackhuang.hmcl.auth.microsoft;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.auth.AuthInfo;
|
import org.jackhuang.hmcl.auth.AuthInfo;
|
||||||
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -43,6 +44,8 @@ public class MicrosoftSession {
|
|||||||
this.refreshToken = refreshToken;
|
this.refreshToken = refreshToken;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
|
||||||
|
if (accessToken != null) Logging.registerAccessToken(accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTokenType() {
|
public String getTokenType() {
|
||||||
|
@ -20,6 +20,7 @@ package org.jackhuang.hmcl.auth.yggdrasil;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.jackhuang.hmcl.auth.AuthInfo;
|
import org.jackhuang.hmcl.auth.AuthInfo;
|
||||||
import org.jackhuang.hmcl.util.Immutable;
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ public class YggdrasilSession {
|
|||||||
this.selectedProfile = selectedProfile;
|
this.selectedProfile = selectedProfile;
|
||||||
this.availableProfiles = availableProfiles;
|
this.availableProfiles = availableProfiles;
|
||||||
this.userProperties = userProperties;
|
this.userProperties = userProperties;
|
||||||
|
|
||||||
|
if (accessToken != null) Logging.registerAccessToken(accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientToken() {
|
public String getClientToken() {
|
||||||
|
@ -47,6 +47,10 @@ public final class Logging {
|
|||||||
forbiddenTokens.put(token, replacement);
|
forbiddenTokens.put(token, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerAccessToken(String accessToken) {
|
||||||
|
registerForbiddenToken(accessToken, "<access token>");
|
||||||
|
}
|
||||||
|
|
||||||
public static String filterForbiddenToken(String message) {
|
public static String filterForbiddenToken(String message) {
|
||||||
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet()) {
|
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet()) {
|
||||||
message = message.replace(entry.getKey(), entry.getValue());
|
message = message.replace(entry.getKey(), entry.getValue());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user