From 869f57cbf19bf3d726cd92e0e71919d359e55fb9 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Fri, 8 Nov 2019 11:10:28 +0800 Subject: [PATCH] avoiding crash when recorded AI server url is malformed --- .../AuthlibInjectorProvider.java | 31 ++++++++++++------- .../auth/yggdrasil/YggdrasilProvider.java | 12 ++++--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorProvider.java index ef99cd51b..f7cde548b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorProvider.java @@ -17,10 +17,11 @@ */ package org.jackhuang.hmcl.auth.authlibinjector; +import org.jackhuang.hmcl.auth.AuthenticationException; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilProvider; import org.jackhuang.hmcl.util.gson.UUIDTypeAdapter; -import org.jackhuang.hmcl.util.io.NetworkUtils; +import java.net.MalformedURLException; import java.net.URL; import java.util.UUID; @@ -33,32 +34,40 @@ public class AuthlibInjectorProvider implements YggdrasilProvider { } @Override - public URL getAuthenticationURL() { - return NetworkUtils.toURL(apiRoot + "authserver/authenticate"); + public URL getAuthenticationURL() throws AuthenticationException { + return toURL(apiRoot + "authserver/authenticate"); } @Override - public URL getRefreshmentURL() { - return NetworkUtils.toURL(apiRoot + "authserver/refresh"); + public URL getRefreshmentURL() throws AuthenticationException { + return toURL(apiRoot + "authserver/refresh"); } @Override - public URL getValidationURL() { - return NetworkUtils.toURL(apiRoot + "authserver/validate"); + public URL getValidationURL() throws AuthenticationException { + return toURL(apiRoot + "authserver/validate"); } @Override - public URL getInvalidationURL() { - return NetworkUtils.toURL(apiRoot + "authserver/invalidate"); + public URL getInvalidationURL() throws AuthenticationException { + return toURL(apiRoot + "authserver/invalidate"); } @Override - public URL getProfilePropertiesURL(UUID uuid) { - return NetworkUtils.toURL(apiRoot + "sessionserver/session/minecraft/profile/" + UUIDTypeAdapter.fromUUID(uuid)); + public URL getProfilePropertiesURL(UUID uuid) throws AuthenticationException { + return toURL(apiRoot + "sessionserver/session/minecraft/profile/" + UUIDTypeAdapter.fromUUID(uuid)); } @Override public String toString() { return apiRoot; } + + private URL toURL(String url) throws AuthenticationException { + try { + return new URL(url); + } catch (MalformedURLException e) { + throw new AuthenticationException(e); + } + } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilProvider.java index 2b3929f99..af1b2ef32 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilProvider.java @@ -17,6 +17,8 @@ */ package org.jackhuang.hmcl.auth.yggdrasil; +import org.jackhuang.hmcl.auth.AuthenticationException; + import java.net.URL; import java.util.UUID; @@ -25,14 +27,14 @@ import java.util.UUID; */ public interface YggdrasilProvider { - URL getAuthenticationURL(); + URL getAuthenticationURL() throws AuthenticationException; - URL getRefreshmentURL(); + URL getRefreshmentURL() throws AuthenticationException; - URL getValidationURL(); + URL getValidationURL() throws AuthenticationException; - URL getInvalidationURL(); + URL getInvalidationURL() throws AuthenticationException; - URL getProfilePropertiesURL(UUID uuid); + URL getProfilePropertiesURL(UUID uuid) throws AuthenticationException; }