Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ interface HyperZoneCredential : IPropertiesHolder {
*/
val credentialId: String

/**
* 认证来源唯一标识,用于向外部消费者区分上游来源
*/
val sourceId: String

/**
* 读取该凭证当前已经绑定到的 User。
*
Expand Down
9 changes: 4 additions & 5 deletions api/src/main/kotlin/icu/h2l/api/util/IPropertiesHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
package icu.h2l.api.util

interface IPropertiesHolder {
val properties: HashMap<String, String>
get() = HashMap()
val properties: MutableMap<String, String>

fun getProperty(key: String): String {
return properties[key] as String
fun getProperty(key: String): String? {
return properties[key]
}

fun setProperty(key: String, value: String) {
Expand All @@ -40,4 +39,4 @@ interface IPropertiesHolder {
fun removeProperty(key: String) {
properties.remove(key)
}
}
}
28 changes: 28 additions & 0 deletions api/src/main/kotlin/icu/h2l/api/util/PropertiesHolder.kt
Original file line number Diff line number Diff line change
@@ -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 (庆灵) <ksqeib@qq.com>
* 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 <https://www.gnu.org/licenses/>.
*
*/

package icu.h2l.api.util

import java.util.concurrent.ConcurrentHashMap

class PropertiesHolder : IPropertiesHolder {
override val properties: MutableMap<String, String> = ConcurrentHashMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -32,9 +34,10 @@ class FloodgateHyperZoneCredential(
private val xuid: Long,
private val suggestedProfileCreateUuid: UUID?,
private val knownUserUUID: UUID? = null,
) : HyperZoneCredential {
) : HyperZoneCredential, IPropertiesHolder by PropertiesHolder() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Rename drops credential properties

When custom properties are set on a pending Offline or Floodgate credential before it is renamed, withNewName creates a replacement credential with a fresh PropertiesHolder and does not copy the original properties, so the rename flow replaces the credential and downstream consumers see its metadata missing.

Have both credential withNewName implementations preserve the original properties when creating the renamed credential.

Also at subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt:39.

Prompt for AI agents
In `subplugin/auth-floodgate/src/main/kotlin/icu/h2l/login/auth/floodgate/credential/FloodgateHyperZoneCredential.kt` at line 37:

**Rename drops credential properties**

When custom properties are set on a pending Offline or Floodgate credential before it is renamed, `withNewName` creates a replacement credential with a fresh `PropertiesHolder` and does not copy the original properties, so the rename flow replaces the credential and downstream consumers see its metadata missing.

Have both credential `withNewName` implementations preserve the original properties when creating the renamed credential.

Also at `subplugin/auth-offline/src/main/kotlin/icu/h2l/login/auth/offline/service/OfflineHyperZoneCredential.kt:39`.

override val channelId: String = CHANNEL_ID
override val credentialId: String = trustedUuid.toString()
override val sourceId: String = channelId

override fun getRegistrationName(): String = trustedName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -34,9 +36,10 @@ 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
override val sourceId: String = channelId

override fun getRegistrationName(): String = registrationName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -32,12 +34,13 @@ 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"
override val sourceId: String = "$channelId:${entryId}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Equivalent entries get different identifiers

When the configured Yggdrasil entry ID contains uppercase letters or differs in casing from another reference, sourceId and the yggdrasil-entry-id property preserve the configured casing, while EntryTableManager normalizes IDs to lowercase; consumers matching canonical IDs treat the same upstream entry as a different source.

Normalize entryId to lowercase using the same canonicalization as EntryTableManager before constructing sourceId and setting YGGDRASIL_ENTRY_ID_PROPERTY.

Also at subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt:43.

Prompt for AI agents
In `subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt` at line 40:

**Equivalent entries get different identifiers**

When the configured Yggdrasil entry ID contains uppercase letters or differs in casing from another reference, `sourceId` and the `yggdrasil-entry-id` property preserve the configured casing, while `EntryTableManager` normalizes IDs to lowercase; consumers matching canonical IDs treat the same upstream entry as a different source.

Normalize `entryId` to lowercase using the same canonicalization as `EntryTableManager` before constructing `sourceId` and setting `YGGDRASIL_ENTRY_ID_PROPERTY`.

Also at `subplugin/auth-yggd/src/main/kotlin/icu/h2l/login/auth/online/credential/YggdrasilHyperZoneCredential.kt:43`.


init {
setProperty(YGGDRASIL_ENTRY_ID_PROPERTY, entryId.lowercase(Locale.getDefault()))
setProperty(YGGDRASIL_ENTRY_ID_PROPERTY, entryId)
}

override fun getRegistrationName(): String = authenticatedName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -262,9 +264,10 @@ 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"
override val sourceId: String = channelId

override fun getBoundUserUUID(): UUID? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,9 +102,10 @@ 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"
override val sourceId: String = channelId
var unboundUserUUID: UUID? = null

override fun getBoundUserUUID(): UUID? = null
Expand Down
Loading