From 4c80eb6c4c67c0ec0cc2f70bb89a69b298a6042f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?MC=7E=E8=9B=9F=E9=BE=99?= <1610105206@qq.com> Date: Thu, 11 Jul 2024 19:40:43 +0800 Subject: [PATCH] Fix something --- gradle/libs.versions.toml | 2 ++ plugin/platform-bukkit/build.gradle.kts | 3 ++ .../authme/debug/TestEmailSender.java | 1 + .../authme/security/PasswordSecurity.java | 27 ++++++---------- .../security/totp/GenerateTotpService.java | 0 .../security/totp/TotpAuthenticator.java | 0 project/module-mail/build.gradle.kts | 2 +- .../authme/mail/OAuth2SaslClientFactory.java | 4 +-- .../settings/properties/EmailSettings.java | 32 +++++++++---------- .../java/fr/xephi/authme/util/FileUtils.java | 4 +-- 10 files changed, 37 insertions(+), 38 deletions(-) rename {project/module-security => plugin/platform-bukkit}/src/main/java/fr/xephi/authme/security/PasswordSecurity.java (90%) rename {project/module-security => plugin/platform-bukkit}/src/main/java/fr/xephi/authme/security/totp/GenerateTotpService.java (100%) rename {project/module-security => plugin/platform-bukkit}/src/main/java/fr/xephi/authme/security/totp/TotpAuthenticator.java (100%) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8cbdd56b..90444728 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] guava = "33.2.1-jre" +apache-commons-email = "1.6.0" configme = "1.3.1" jalu-injector = "1.0" adventure-api = "4.17.0" @@ -7,6 +8,7 @@ adventure-platform = "4.3.2" [libraries] guava = { module = "com.google.guava:guava", version.ref = "guava" } +apache-commons-email = { module = "org.apache.commons:commons-email", version.ref = "apache-commons-email" } configme = { module = "ch.jalu:configme", version.ref = "configme" } jalu-injector = { module = "ch.jalu:injector", version.ref = "jalu-injector" } adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure-api" } diff --git a/plugin/platform-bukkit/build.gradle.kts b/plugin/platform-bukkit/build.gradle.kts index 5fd80077..0f352e32 100644 --- a/plugin/platform-bukkit/build.gradle.kts +++ b/plugin/platform-bukkit/build.gradle.kts @@ -16,6 +16,9 @@ dependencies { compileOnly("ru.tehkode:PermissionsEx:1.23.5-SNAPSHOT") // Hooks - End + // TODO It's necessary? + compileOnly(libs.apache.commons.email) + } tasks.shadowJar { diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/command/executable/authme/debug/TestEmailSender.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/command/executable/authme/debug/TestEmailSender.java index 1cce419f..c45722c8 100644 --- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/command/executable/authme/debug/TestEmailSender.java +++ b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/command/executable/authme/debug/TestEmailSender.java @@ -122,4 +122,5 @@ class TestEmailSender implements DebugSection { + server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine."; return sendMailSsl.sendEmail(message, htmlEmail); } + } diff --git a/project/module-security/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/PasswordSecurity.java similarity index 90% rename from project/module-security/src/main/java/fr/xephi/authme/security/PasswordSecurity.java rename to plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/PasswordSecurity.java index 012fd3e5..13851c26 100644 --- a/project/module-security/src/main/java/fr/xephi/authme/security/PasswordSecurity.java +++ b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/PasswordSecurity.java @@ -49,9 +49,8 @@ public class PasswordSecurity implements Reloadable { /** * Compute the hash of the configured algorithm for the given password and username. * - * @param password The password to hash + * @param password The password to hash * @param playerName The player's name - * * @return The password hash */ public HashedPassword computeHash(String password, String playerName) { @@ -62,9 +61,8 @@ public class PasswordSecurity implements Reloadable { /** * Check if the given password matches the player's stored password. * - * @param password The password to check + * @param password The password to check * @param playerName The player to check for - * * @return True if the password is correct, false otherwise */ public boolean comparePassword(String password, String playerName) { @@ -75,16 +73,15 @@ public class PasswordSecurity implements Reloadable { /** * Check if the given password matches the given hashed password. * - * @param password The password to check + * @param password The password to check * @param hashedPassword The hashed password to check against - * @param playerName The player to check for - * + * @param playerName The player to check for * @return True if the password matches, false otherwise */ public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) { String playerLowerCase = playerName.toLowerCase(Locale.ROOT); return methodMatches(encryptionMethod, password, hashedPassword, playerLowerCase) - || compareWithLegacyHashes(password, hashedPassword, playerLowerCase); + || compareWithLegacyHashes(password, hashedPassword, playerLowerCase); } /** @@ -95,7 +92,6 @@ public class PasswordSecurity implements Reloadable { * @param password The clear-text password to check * @param hashedPassword The encrypted password to test the clear-text password against * @param playerName The name of the player - * * @return True if there was a password match with a configured legacy encryption method, false otherwise */ private boolean compareWithLegacyHashes(String password, HashedPassword hashedPassword, String playerName) { @@ -113,17 +109,16 @@ public class PasswordSecurity implements Reloadable { * Verify with the given encryption method whether the password matches the hash after checking that * the method can be called safely with the given data. * - * @param method The encryption method to use - * @param password The password to check + * @param method The encryption method to use + * @param password The password to check * @param hashedPassword The hash to check against - * @param playerName The name of the player - * + * @param playerName The name of the player * @return True if the password matched, false otherwise */ private static boolean methodMatches(EncryptionMethod method, String password, HashedPassword hashedPassword, String playerName) { return method != null && (!method.hasSeparateSalt() || hashedPassword.getSalt() != null) - && method.comparePassword(password, hashedPassword, playerName); + && method.comparePassword(password, hashedPassword, playerName); } /** @@ -131,8 +126,7 @@ public class PasswordSecurity implements Reloadable { * {@link PasswordEncryptionEvent}. The encryption method from the event is then returned, * which may have been changed by an external listener. * - * @param algorithm The algorithm to retrieve the encryption method for - * + * @param algorithm The algorithm to retrieve the encryption method for * @return The encryption method */ private EncryptionMethod initializeEncryptionMethodWithEvent(HashAlgorithm algorithm) { @@ -146,7 +140,6 @@ public class PasswordSecurity implements Reloadable { * Initialize the encryption method associated with the given hash algorithm. * * @param algorithm The algorithm to retrieve the encryption method for - * * @return The associated encryption method, or null if CUSTOM / deprecated */ private EncryptionMethod initializeEncryptionMethod(HashAlgorithm algorithm) { diff --git a/project/module-security/src/main/java/fr/xephi/authme/security/totp/GenerateTotpService.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/totp/GenerateTotpService.java similarity index 100% rename from project/module-security/src/main/java/fr/xephi/authme/security/totp/GenerateTotpService.java rename to plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/totp/GenerateTotpService.java diff --git a/project/module-security/src/main/java/fr/xephi/authme/security/totp/TotpAuthenticator.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/totp/TotpAuthenticator.java similarity index 100% rename from project/module-security/src/main/java/fr/xephi/authme/security/totp/TotpAuthenticator.java rename to plugin/platform-bukkit/src/main/java/fr/xephi/authme/security/totp/TotpAuthenticator.java diff --git a/project/module-mail/build.gradle.kts b/project/module-mail/build.gradle.kts index 24f1d6a9..19927eb8 100644 --- a/project/module-mail/build.gradle.kts +++ b/project/module-mail/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { compileOnly(libs.configme) compileOnly(libs.jalu.injector) // Java Email Library - implementation("org.apache.commons:commons-email:1.6.0") + implementation(libs.apache.commons.email) } tasks.shadowJar { diff --git a/project/module-mail/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java b/project/module-mail/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java index ae63dffe..2fce02f8 100644 --- a/project/module-mail/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java +++ b/project/module-mail/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java @@ -38,8 +38,8 @@ public class OAuth2SaslClientFactory implements SaslClientFactory { String authorizationId, String protocol, String serverName, Map props, CallbackHandler callbackHandler) { boolean matchedMechanism = false; - for (int i = 0; i < mechanisms.length; ++i) { - if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) { + for (String mechanism : mechanisms) { + if ("XOAUTH2".equalsIgnoreCase(mechanism)) { matchedMechanism = true; break; } diff --git a/project/module-mail/src/main/java/fr/xephi/authme/settings/properties/EmailSettings.java b/project/module-mail/src/main/java/fr/xephi/authme/settings/properties/EmailSettings.java index 4af0c40d..82a0d861 100644 --- a/project/module-mail/src/main/java/fr/xephi/authme/settings/properties/EmailSettings.java +++ b/project/module-mail/src/main/java/fr/xephi/authme/settings/properties/EmailSettings.java @@ -10,65 +10,65 @@ public final class EmailSettings implements SettingsHolder { @Comment("Email SMTP server host") public static final Property SMTP_HOST = - PropertyInitializer.newProperty("Email.mailSMTP", "smtp.163.com"); + newProperty("Email.mailSMTP", "smtp.163.com"); @Comment("Email SMTP server port") public static final Property SMTP_PORT = - PropertyInitializer.newProperty("Email.mailPort", 465); + newProperty("Email.mailPort", 465); @Comment("Only affects port 25: enable TLS/STARTTLS?") public static final Property PORT25_USE_TLS = - PropertyInitializer.newProperty("Email.useTls", true); + newProperty("Email.useTls", true); @Comment("Email account which sends the mails") public static final Property MAIL_ACCOUNT = - PropertyInitializer.newProperty("Email.mailAccount", ""); + newProperty("Email.mailAccount", ""); @Comment("Email account password") public static final Property MAIL_PASSWORD = - PropertyInitializer.newProperty("Email.mailPassword", ""); + newProperty("Email.mailPassword", ""); @Comment("Email address, fill when mailAccount is not the email address of the account") public static final Property MAIL_ADDRESS = - PropertyInitializer.newProperty("Email.mailAddress", ""); + newProperty("Email.mailAddress", ""); @Comment("Custom sender name, replacing the mailAccount name in the email") public static final Property MAIL_SENDER_NAME = - PropertyInitializer.newProperty("Email.mailSenderName", ""); + newProperty("Email.mailSenderName", ""); @Comment("Recovery password length") public static final Property RECOVERY_PASSWORD_LENGTH = - PropertyInitializer.newProperty("Email.RecoveryPasswordLength", 12); + newProperty("Email.RecoveryPasswordLength", 12); @Comment("Mail Subject") public static final Property RECOVERY_MAIL_SUBJECT = - PropertyInitializer.newProperty("Email.mailSubject", "Your new AuthMe password"); + newProperty("Email.mailSubject", "Your new AuthMe password"); @Comment("Like maxRegPerIP but with email") public static final Property MAX_REG_PER_EMAIL = - PropertyInitializer.newProperty("Email.maxRegPerEmail", 1); + newProperty("Email.maxRegPerEmail", 1); @Comment("Recall players to add an email?") public static final Property RECALL_PLAYERS = - PropertyInitializer.newProperty("Email.recallPlayers", false); + newProperty("Email.recallPlayers", false); @Comment("Delay in minute for the recall scheduler") public static final Property DELAY_RECALL = - PropertyInitializer.newProperty("Email.delayRecall", 5); + newProperty("Email.delayRecall", 5); @Comment("Send the new password drawn in an image?") public static final Property PASSWORD_AS_IMAGE = - PropertyInitializer.newProperty("Email.generateImage", false); + newProperty("Email.generateImage", false); @Comment("The OAuth2 token") public static final Property OAUTH2_TOKEN = - PropertyInitializer.newProperty("Email.emailOauth2Token", ""); + newProperty("Email.emailOauth2Token", ""); @Comment("Email notifications when the server shuts down") public static final Property SHUTDOWN_MAIL = - PropertyInitializer.newProperty("Email.shutDownEmail", false); + newProperty("Email.shutDownEmail", false); @Comment("Email notification address when the server is shut down") public static final Property SHUTDOWN_MAIL_ADDRESS = - PropertyInitializer.newProperty("Email.shutDownEmailAddress", "your@mail.com"); + newProperty("Email.shutDownEmailAddress", "your@mail.com"); private EmailSettings() { } diff --git a/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java b/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java index 86be894a..c111c013 100644 --- a/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java +++ b/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java @@ -1,8 +1,8 @@ package fr.xephi.authme.util; import com.google.common.io.Files; -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.output.ConsoleLoggerFactory; +import fr.xephi.authme.logger.ConsoleLogger; +import fr.xephi.authme.logger.ConsoleLoggerFactory; import java.io.File; import java.io.IOException;