mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 13:26:53 -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 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.Logging.LOG;
|
||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||
@ -700,7 +699,6 @@ public final class LauncherHelper {
|
||||
|
||||
private final HMCLGameRepository repository;
|
||||
private final Version version;
|
||||
private final Map<String, String> forbiddenTokens;
|
||||
private final LaunchOptions launchOptions;
|
||||
private ManagedProcess process;
|
||||
private boolean lwjgl;
|
||||
@ -717,13 +715,6 @@ public final class LauncherHelper {
|
||||
this.launchingLatch = launchingLatch;
|
||||
this.detectWindow = detectWindow;
|
||||
|
||||
if (authInfo == null)
|
||||
forbiddenTokens = Collections.emptyMap();
|
||||
else
|
||||
forbiddenTokens = mapOf(
|
||||
pair(authInfo.getAccessToken(), "<access token>")
|
||||
);
|
||||
|
||||
logs = new LinkedList<>();
|
||||
}
|
||||
|
||||
@ -732,8 +723,6 @@ public final class LauncherHelper {
|
||||
this.process = process;
|
||||
|
||||
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);
|
||||
|
||||
@ -785,10 +774,7 @@ public final class LauncherHelper {
|
||||
|
||||
@Override
|
||||
public synchronized void onLog(String log, Log4jLevel level) {
|
||||
String newLog = log;
|
||||
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet())
|
||||
newLog = newLog.replace(entry.getKey(), entry.getValue());
|
||||
String filteredLog = newLog;
|
||||
String filteredLog = Logging.filterForbiddenToken(log);
|
||||
|
||||
if (level.lessOrEqual(Log4jLevel.ERROR))
|
||||
System.err.println(filteredLog);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.auth.microsoft;
|
||||
|
||||
import org.jackhuang.hmcl.auth.AuthInfo;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
||||
|
||||
import java.util.Map;
|
||||
@ -43,6 +44,8 @@ public class MicrosoftSession {
|
||||
this.refreshToken = refreshToken;
|
||||
this.user = user;
|
||||
this.profile = profile;
|
||||
|
||||
if (accessToken != null) Logging.registerAccessToken(accessToken);
|
||||
}
|
||||
|
||||
public String getTokenType() {
|
||||
|
@ -20,6 +20,7 @@ package org.jackhuang.hmcl.auth.yggdrasil;
|
||||
import com.google.gson.Gson;
|
||||
import org.jackhuang.hmcl.auth.AuthInfo;
|
||||
import org.jackhuang.hmcl.util.Immutable;
|
||||
import org.jackhuang.hmcl.util.Logging;
|
||||
import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -46,6 +47,8 @@ public class YggdrasilSession {
|
||||
this.selectedProfile = selectedProfile;
|
||||
this.availableProfiles = availableProfiles;
|
||||
this.userProperties = userProperties;
|
||||
|
||||
if (accessToken != null) Logging.registerAccessToken(accessToken);
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
|
@ -47,6 +47,10 @@ public final class Logging {
|
||||
forbiddenTokens.put(token, replacement);
|
||||
}
|
||||
|
||||
public static void registerAccessToken(String accessToken) {
|
||||
registerForbiddenToken(accessToken, "<access token>");
|
||||
}
|
||||
|
||||
public static String filterForbiddenToken(String message) {
|
||||
for (Map.Entry<String, String> entry : forbiddenTokens.entrySet()) {
|
||||
message = message.replace(entry.getKey(), entry.getValue());
|
||||
|
Loading…
x
Reference in New Issue
Block a user