Display remote error message when RemoteAuthenticationException thrown
This commit is contained in:
@@ -36,14 +36,13 @@ import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
|||||||
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer;
|
||||||
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
|
import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
|
||||||
|
import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException;
|
||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||||
import org.jackhuang.hmcl.game.AccountHelper;
|
import org.jackhuang.hmcl.game.AccountHelper;
|
||||||
import org.jackhuang.hmcl.setting.Accounts;
|
import org.jackhuang.hmcl.setting.Accounts;
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.Settings;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
|
||||||
import org.jackhuang.hmcl.ui.animation.TransitionHandler;
|
|
||||||
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
||||||
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
import org.jackhuang.hmcl.ui.construct.IconedItem;
|
||||||
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
|
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
|
||||||
@@ -253,16 +252,22 @@ public class AddAccountPane extends StackPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String accountException(Exception exception) {
|
public static String accountException(Exception exception) {
|
||||||
if (exception instanceof InvalidCredentialsException) {
|
if (exception instanceof NoCharacterException) {
|
||||||
return Launcher.i18n("account.failed.invalid_credentials");
|
return Launcher.i18n("account.failed.no_character");
|
||||||
} else if (exception instanceof NoCharacterException) {
|
|
||||||
return Launcher.i18n("account.failed.no_charactor");
|
|
||||||
} else if (exception instanceof ServerDisconnectException) {
|
} else if (exception instanceof ServerDisconnectException) {
|
||||||
return Launcher.i18n("account.failed.connect_authentication_server");
|
return Launcher.i18n("account.failed.connect_authentication_server");
|
||||||
} else if (exception instanceof InvalidTokenException) {
|
} else if (exception instanceof RemoteAuthenticationException) {
|
||||||
return Launcher.i18n("account.failed.invalid_token");
|
RemoteAuthenticationException remoteException = (RemoteAuthenticationException) exception;
|
||||||
} else if (exception instanceof InvalidPasswordException) {
|
String remoteMessage = remoteException.getRemoteMessage();
|
||||||
return Launcher.i18n("account.failed.invalid_password");
|
if ("ForbiddenOperationException".equals(remoteException.getRemoteName()) && remoteMessage != null) {
|
||||||
|
if (remoteMessage.contains("Invalid credentials"))
|
||||||
|
return Launcher.i18n("account.failed.invalid_credentials");
|
||||||
|
else if (remoteMessage.contains("Invalid token"))
|
||||||
|
return Launcher.i18n("account.failed.invalid_token");
|
||||||
|
else if (remoteMessage.contains("Invalid username or password"))
|
||||||
|
return Launcher.i18n("account.failed.invalid_password");
|
||||||
|
}
|
||||||
|
return exception.getMessage();
|
||||||
} else {
|
} else {
|
||||||
return exception.getClass() + ": " + exception.getLocalizedMessage();
|
return exception.getClass() + ": " + exception.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ account.failed.connect_authentication_server=Cannot connect to the authenticatio
|
|||||||
account.failed.invalid_credentials=Incorrect password, or you are forbidden to login temporarily.
|
account.failed.invalid_credentials=Incorrect password, or you are forbidden to login temporarily.
|
||||||
account.failed.invalid_password=Invalid password
|
account.failed.invalid_password=Invalid password
|
||||||
account.failed.invalid_token=Please log out and re-input your password to login.
|
account.failed.invalid_token=Please log out and re-input your password to login.
|
||||||
account.failed.no_charactor=No character in this account.
|
account.failed.no_character=No character in this account.
|
||||||
account.failed.no_selected_server=No authentication server is selected.
|
account.failed.no_selected_server=No authentication server is selected.
|
||||||
account.failed.connect_injector_server=Cannot connect to the authentication server. Check your network and ensure the URL is correct.
|
account.failed.connect_injector_server=Cannot connect to the authentication server. Check your network and ensure the URL is correct.
|
||||||
account.injector.add=Add authentication server
|
account.injector.add=Add authentication server
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ account.failed.connect_authentication_server=无法连接认证服务器,可能
|
|||||||
account.failed.invalid_credentials=您的用户名或密码错误,或者登录次数过多被暂时禁止登录,请稍后再试
|
account.failed.invalid_credentials=您的用户名或密码错误,或者登录次数过多被暂时禁止登录,请稍后再试
|
||||||
account.failed.invalid_password=无效的密码
|
account.failed.invalid_password=无效的密码
|
||||||
account.failed.invalid_token=请尝试登出并重新输入密码登录
|
account.failed.invalid_token=请尝试登出并重新输入密码登录
|
||||||
account.failed.no_charactor=该帐号没有角色
|
account.failed.no_character=该帐号没有角色
|
||||||
account.failed.no_selected_server=未选择认证服务器
|
account.failed.no_selected_server=未选择认证服务器
|
||||||
account.failed.connect_injector_server=无法连接认证服务器,可能是网络故障或 URL 输入错误
|
account.failed.connect_injector_server=无法连接认证服务器,可能是网络故障或 URL 输入错误
|
||||||
account.injector.add=添加认证服务器
|
account.injector.add=添加认证服务器
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.auth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* throws if wrong password or logging fails for too many times.
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public final class InvalidCredentialsException extends AuthenticationException {
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.auth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* throws if wrong password.
|
|
||||||
*/
|
|
||||||
public class InvalidPasswordException extends AuthenticationException {
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* Copyright (C) 2018 huangyuhui <huanghongxun2008@126.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.auth;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public class InvalidTokenException extends AuthenticationException {
|
|
||||||
}
|
|
||||||
@@ -83,7 +83,7 @@ public class YggdrasilService {
|
|||||||
try {
|
try {
|
||||||
requireEmpty(request(provider.getValidationURL(), createRequestWithCredentials(accessToken, clientToken)));
|
requireEmpty(request(provider.getValidationURL(), createRequestWithCredentials(accessToken, clientToken)));
|
||||||
return true;
|
return true;
|
||||||
} catch (InvalidCredentialsException | InvalidTokenException e) {
|
} catch (RemoteAuthenticationException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,17 +145,6 @@ public class YggdrasilService {
|
|||||||
|
|
||||||
private static void handleErrorMessage(ErrorResponse response) throws AuthenticationException {
|
private static void handleErrorMessage(ErrorResponse response) throws AuthenticationException {
|
||||||
if (!StringUtils.isBlank(response.error)) {
|
if (!StringUtils.isBlank(response.error)) {
|
||||||
if (response.errorMessage != null && "ForbiddenOperationException".equals(response.error)) {
|
|
||||||
if (response.errorMessage.contains("Invalid credentials"))
|
|
||||||
throw new InvalidCredentialsException();
|
|
||||||
|
|
||||||
else if (response.errorMessage.contains("Invalid token"))
|
|
||||||
throw new InvalidTokenException();
|
|
||||||
|
|
||||||
else if (response.errorMessage.contains("Invalid username or password"))
|
|
||||||
throw new InvalidPasswordException();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RemoteAuthenticationException(response.error, response.errorMessage, response.cause);
|
throw new RemoteAuthenticationException(response.error, response.errorMessage, response.cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user