From 71d416e37911ab3fa0c2ef9631d47ecfc9409ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E9=9B=A8=E8=90=BD?= Date: Wed, 11 Nov 2026 17:41:44 +0800 Subject: [PATCH 1/2] fix: no recreate hashmap in getter. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秋雨落 --- .../icu/h2l/api/util/IPropertiesHolder.kt | 9 +++--- .../icu/h2l/api/util/PropertiesHolder.kt | 28 +++++++++++++++++++ .../FloodgateHyperZoneCredential.kt | 4 ++- .../service/OfflineHyperZoneCredential.kt | 4 ++- .../YggdrasilHyperZoneCredential.kt | 6 ++-- .../profile/UserBindingCodeServiceTest.kt | 4 ++- .../login/profile/UserUnbindServiceTest.kt | 4 ++- 7 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt diff --git a/api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt b/api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt index b238810f..589f1f04 100644 --- a/api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt +++ b/api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt @@ -22,11 +22,10 @@ package icu.h2l.api.util interface IPropertiesHolder { - val properties: HashMap - get() = HashMap() + val properties: MutableMap - fun getProperty(key: String): String { - return properties[key] as String + fun getProperty(key: String): String? { + return properties[key] } fun setProperty(key: String, value: String) { @@ -40,4 +39,4 @@ interface IPropertiesHolder { fun removeProperty(key: String) { properties.remove(key) } -} \ No newline at end of file +} diff --git a/api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt b/api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt new file mode 100644 index 00000000..61136f92 --- /dev/null +++ b/api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt @@ -0,0 +1,28 @@ +/* + * This file is part of HyperZoneLogin, licensed under the GNU Affero General Public License v3.0 or later. + * + * Copyright (C) ksqeib (庆灵) + * Copyright (C) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package icu.h2l.api.util + +import java.util.concurrent.ConcurrentHashMap + +class PropertiesHolder : IPropertiesHolder { + override val properties: MutableMap = ConcurrentHashMap() +} diff --git a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt index b2540494..af9bb386 100644 --- a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt +++ b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt @@ -22,6 +22,8 @@ package icu.h2l.login.auth.floodgate.credential import icu.h2l.api.profile.HyperZoneCredential +import icu.h2l.api.util.IPropertiesHolder +import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.auth.floodgate.db.FloodgateAuthRepository import java.util.* @@ -32,7 +34,7 @@ class FloodgateHyperZoneCredential( private val xuid: Long, private val suggestedProfileCreateUuid: UUID?, private val knownUserUUID: UUID? = null, -) : HyperZoneCredential { +) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = trustedUuid.toString() diff --git a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt index 90e7c398..fc6ec260 100644 --- a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt +++ b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt @@ -22,6 +22,8 @@ package icu.h2l.login.auth.offline.service import icu.h2l.api.profile.HyperZoneCredential +import icu.h2l.api.util.IPropertiesHolder +import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.auth.offline.db.OfflineAuthRepository import icu.h2l.login.auth.offline.util.ExtraUuidUtils import java.util.* @@ -34,7 +36,7 @@ class OfflineHyperZoneCredential( private val knownUserUUID: UUID? = null, private val pendingRegistrationId: UUID? = null, private val passProfileCreateUuid: Boolean = false, -) : HyperZoneCredential { +) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = pendingRegistrationId?.toString() ?: normalizedName diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt index e484c248..b33a34f1 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt @@ -22,6 +22,8 @@ package icu.h2l.login.auth.online.credential import icu.h2l.api.profile.HyperZoneCredential +import icu.h2l.api.util.IPropertiesHolder +import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.auth.online.db.EntryDatabaseHelper import java.util.* @@ -32,12 +34,12 @@ class YggdrasilHyperZoneCredential( private val authenticatedUUID: UUID, private val suggestedProfileCreateUuid: UUID?, private val knownUserUUID: UUID? = null, -) : HyperZoneCredential { +) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = "$entryId:$authenticatedUUID" init { - setProperty(YGGDRASIL_ENTRY_ID_PROPERTY, entryId.lowercase(Locale.getDefault())) + setProperty(YGGDRASIL_ENTRY_ID_PROPERTY, entryId) } override fun getRegistrationName(): String = authenticatedName diff --git a/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt b/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt index 8cc4d1ea..d2c64d22 100644 --- a/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt +++ b/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt @@ -28,6 +28,8 @@ import icu.h2l.api.player.ClientLoginIdentity import icu.h2l.api.player.HyperZonePlayer import icu.h2l.api.profile.HyperZoneCredential import icu.h2l.api.profile.HyperZoneUserService +import icu.h2l.api.util.IPropertiesHolder +import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.database.helper.BindingCodeStore import icu.h2l.login.manager.LoginManager import io.mockk.mockk @@ -262,7 +264,7 @@ class UserBindingCodeServiceTest { override fun getAttachedGameProfile() = error("not used") } - private class FakeCredential : HyperZoneCredential { + private class FakeCredential : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = "test" override val credentialId: String = "cred" diff --git a/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt b/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt index d8ba2a87..5088fd30 100644 --- a/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt +++ b/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt @@ -28,6 +28,8 @@ import icu.h2l.api.player.ClientLoginIdentity import icu.h2l.api.player.HyperZonePlayer import icu.h2l.api.profile.HyperZoneCredential import icu.h2l.api.profile.HyperZoneUserService +import icu.h2l.api.util.IPropertiesHolder +import icu.h2l.api.util.PropertiesHolder import icu.h2l.login.message.MessageService import io.mockk.every import io.mockk.mockk @@ -100,7 +102,7 @@ class UserUnbindServiceTest { private class FakeCredential( private val unsupported: Boolean = false, - ) : HyperZoneCredential { + ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = "test" override val credentialId: String = "credential" var unboundUserUUID: UUID? = null From d80a00e7ab8e860b9a144a673a2ca69a5931348a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E9=9B=A8=E8=90=BD?= Date: Thu, 12 Nov 2026 20:25:00 +0800 Subject: [PATCH 2/2] feat: add sourceId for identifying upstream credential source. --- .../main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt | 5 +++++ .../floodgate/credential/FloodgateHyperZoneCredential.kt | 1 + .../login/auth/offline/service/OfflineHyperZoneCredential.kt | 1 + .../auth/online/credential/YggdrasilHyperZoneCredential.kt | 1 + .../icu/h2l/login/profile/UserBindingCodeServiceTest.kt | 1 + .../kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt | 1 + 6 files changed, 10 insertions(+) diff --git a/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt b/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt index ab3ca7af..ef1c29f4 100644 --- a/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt +++ b/api/src/main/kotlin/icu/h2l/api/profile/HyperZoneCredential.kt @@ -44,6 +44,11 @@ interface HyperZoneCredential : IPropertiesHolder { */ val credentialId: String + /** + * 认证来源唯一标识,用于向外部消费者区分上游来源 + */ + val sourceId: String + /** * 读取该凭证当前已经绑定到的 User。 * diff --git a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt index af9bb386..6a2a9bcd 100644 --- a/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt +++ b/subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt @@ -37,6 +37,7 @@ class FloodgateHyperZoneCredential( ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = trustedUuid.toString() + override val sourceId: String = channelId override fun getRegistrationName(): String = trustedName diff --git a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt index fc6ec260..ad1eaf26 100644 --- a/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt +++ b/subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt @@ -39,6 +39,7 @@ class OfflineHyperZoneCredential( ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = pendingRegistrationId?.toString() ?: normalizedName + override val sourceId: String = channelId override fun getRegistrationName(): String = registrationName diff --git a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt index b33a34f1..ebec0cc7 100644 --- a/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt +++ b/subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt @@ -37,6 +37,7 @@ class YggdrasilHyperZoneCredential( ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = CHANNEL_ID override val credentialId: String = "$entryId:$authenticatedUUID" + override val sourceId: String = "$channelId:${entryId}" init { setProperty(YGGDRASIL_ENTRY_ID_PROPERTY, entryId) diff --git a/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt b/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt index d2c64d22..f219d88d 100644 --- a/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt +++ b/velocity/src/test/kotlin/icu/h2l/login/profile/UserBindingCodeServiceTest.kt @@ -267,6 +267,7 @@ class UserBindingCodeServiceTest { private class FakeCredential : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = "test" override val credentialId: String = "cred" + override val sourceId: String = channelId override fun getBoundUserUUID(): UUID? = null diff --git a/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt b/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt index 5088fd30..317c7ce4 100644 --- a/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt +++ b/velocity/src/test/kotlin/icu/h2l/login/profile/UserUnbindServiceTest.kt @@ -105,6 +105,7 @@ class UserUnbindServiceTest { ) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() { override val channelId: String = "test" override val credentialId: String = "credential" + override val sourceId: String = channelId var unboundUserUUID: UUID? = null override fun getBoundUserUUID(): UUID? = null