Fix something

This commit is contained in:
MC~蛟龙 2024-07-11 19:40:43 +08:00
parent dc08714a0b
commit 4c80eb6c4c
10 changed files with 37 additions and 38 deletions

View File

@ -1,5 +1,6 @@
[versions] [versions]
guava = "33.2.1-jre" guava = "33.2.1-jre"
apache-commons-email = "1.6.0"
configme = "1.3.1" configme = "1.3.1"
jalu-injector = "1.0" jalu-injector = "1.0"
adventure-api = "4.17.0" adventure-api = "4.17.0"
@ -7,6 +8,7 @@ adventure-platform = "4.3.2"
[libraries] [libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" } 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" } configme = { module = "ch.jalu:configme", version.ref = "configme" }
jalu-injector = { module = "ch.jalu:injector", version.ref = "jalu-injector" } jalu-injector = { module = "ch.jalu:injector", version.ref = "jalu-injector" }
adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure-api" } adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure-api" }

View File

@ -16,6 +16,9 @@ dependencies {
compileOnly("ru.tehkode:PermissionsEx:1.23.5-SNAPSHOT") compileOnly("ru.tehkode:PermissionsEx:1.23.5-SNAPSHOT")
// Hooks - End // Hooks - End
// TODO It's necessary?
compileOnly(libs.apache.commons.email)
} }
tasks.shadowJar { tasks.shadowJar {

View File

@ -122,4 +122,5 @@ class TestEmailSender implements DebugSection {
+ server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine."; + server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
return sendMailSsl.sendEmail(message, htmlEmail); return sendMailSsl.sendEmail(message, htmlEmail);
} }
} }

View File

@ -49,9 +49,8 @@ public class PasswordSecurity implements Reloadable {
/** /**
* Compute the hash of the configured algorithm for the given password and username. * 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 * @param playerName The player's name
*
* @return The password hash * @return The password hash
*/ */
public HashedPassword computeHash(String password, String playerName) { 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. * 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 * @param playerName The player to check for
*
* @return True if the password is correct, false otherwise * @return True if the password is correct, false otherwise
*/ */
public boolean comparePassword(String password, String playerName) { 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. * 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 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 * @return True if the password matches, false otherwise
*/ */
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) { public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
String playerLowerCase = playerName.toLowerCase(Locale.ROOT); String playerLowerCase = playerName.toLowerCase(Locale.ROOT);
return methodMatches(encryptionMethod, password, hashedPassword, playerLowerCase) 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 password The clear-text password to check
* @param hashedPassword The encrypted password to test the clear-text password against * @param hashedPassword The encrypted password to test the clear-text password against
* @param playerName The name of the player * @param playerName The name of the player
*
* @return True if there was a password match with a configured legacy encryption method, false otherwise * @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) { 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 * 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. * the method can be called safely with the given data.
* *
* @param method The encryption method to use * @param method The encryption method to use
* @param password The password to check * @param password The password to check
* @param hashedPassword The hash to check against * @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 * @return True if the password matched, false otherwise
*/ */
private static boolean methodMatches(EncryptionMethod method, String password, private static boolean methodMatches(EncryptionMethod method, String password,
HashedPassword hashedPassword, String playerName) { HashedPassword hashedPassword, String playerName) {
return method != null && (!method.hasSeparateSalt() || hashedPassword.getSalt() != null) 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, * {@link PasswordEncryptionEvent}. The encryption method from the event is then returned,
* which may have been changed by an external listener. * 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 * @return The encryption method
*/ */
private EncryptionMethod initializeEncryptionMethodWithEvent(HashAlgorithm algorithm) { private EncryptionMethod initializeEncryptionMethodWithEvent(HashAlgorithm algorithm) {
@ -146,7 +140,6 @@ public class PasswordSecurity implements Reloadable {
* Initialize the encryption method associated with the given hash algorithm. * Initialize the encryption method associated with the given hash algorithm.
* *
* @param algorithm The algorithm to retrieve the encryption method for * @param algorithm The algorithm to retrieve the encryption method for
*
* @return The associated encryption method, or null if CUSTOM / deprecated * @return The associated encryption method, or null if CUSTOM / deprecated
*/ */
private EncryptionMethod initializeEncryptionMethod(HashAlgorithm algorithm) { private EncryptionMethod initializeEncryptionMethod(HashAlgorithm algorithm) {

View File

@ -7,7 +7,7 @@ dependencies {
compileOnly(libs.configme) compileOnly(libs.configme)
compileOnly(libs.jalu.injector) compileOnly(libs.jalu.injector)
// Java Email Library // Java Email Library
implementation("org.apache.commons:commons-email:1.6.0") implementation(libs.apache.commons.email)
} }
tasks.shadowJar { tasks.shadowJar {

View File

@ -38,8 +38,8 @@ public class OAuth2SaslClientFactory implements SaslClientFactory {
String authorizationId, String protocol, String serverName, String authorizationId, String protocol, String serverName,
Map<String, ?> props, CallbackHandler callbackHandler) { Map<String, ?> props, CallbackHandler callbackHandler) {
boolean matchedMechanism = false; boolean matchedMechanism = false;
for (int i = 0; i < mechanisms.length; ++i) { for (String mechanism : mechanisms) {
if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) { if ("XOAUTH2".equalsIgnoreCase(mechanism)) {
matchedMechanism = true; matchedMechanism = true;
break; break;
} }

View File

@ -10,65 +10,65 @@ public final class EmailSettings implements SettingsHolder {
@Comment("Email SMTP server host") @Comment("Email SMTP server host")
public static final Property<String> SMTP_HOST = public static final Property<String> SMTP_HOST =
PropertyInitializer.newProperty("Email.mailSMTP", "smtp.163.com"); newProperty("Email.mailSMTP", "smtp.163.com");
@Comment("Email SMTP server port") @Comment("Email SMTP server port")
public static final Property<Integer> SMTP_PORT = public static final Property<Integer> SMTP_PORT =
PropertyInitializer.newProperty("Email.mailPort", 465); newProperty("Email.mailPort", 465);
@Comment("Only affects port 25: enable TLS/STARTTLS?") @Comment("Only affects port 25: enable TLS/STARTTLS?")
public static final Property<Boolean> PORT25_USE_TLS = public static final Property<Boolean> PORT25_USE_TLS =
PropertyInitializer.newProperty("Email.useTls", true); newProperty("Email.useTls", true);
@Comment("Email account which sends the mails") @Comment("Email account which sends the mails")
public static final Property<String> MAIL_ACCOUNT = public static final Property<String> MAIL_ACCOUNT =
PropertyInitializer.newProperty("Email.mailAccount", ""); newProperty("Email.mailAccount", "");
@Comment("Email account password") @Comment("Email account password")
public static final Property<String> MAIL_PASSWORD = public static final Property<String> MAIL_PASSWORD =
PropertyInitializer.newProperty("Email.mailPassword", ""); newProperty("Email.mailPassword", "");
@Comment("Email address, fill when mailAccount is not the email address of the account") @Comment("Email address, fill when mailAccount is not the email address of the account")
public static final Property<String> MAIL_ADDRESS = public static final Property<String> MAIL_ADDRESS =
PropertyInitializer.newProperty("Email.mailAddress", ""); newProperty("Email.mailAddress", "");
@Comment("Custom sender name, replacing the mailAccount name in the email") @Comment("Custom sender name, replacing the mailAccount name in the email")
public static final Property<String> MAIL_SENDER_NAME = public static final Property<String> MAIL_SENDER_NAME =
PropertyInitializer.newProperty("Email.mailSenderName", ""); newProperty("Email.mailSenderName", "");
@Comment("Recovery password length") @Comment("Recovery password length")
public static final Property<Integer> RECOVERY_PASSWORD_LENGTH = public static final Property<Integer> RECOVERY_PASSWORD_LENGTH =
PropertyInitializer.newProperty("Email.RecoveryPasswordLength", 12); newProperty("Email.RecoveryPasswordLength", 12);
@Comment("Mail Subject") @Comment("Mail Subject")
public static final Property<String> RECOVERY_MAIL_SUBJECT = public static final Property<String> RECOVERY_MAIL_SUBJECT =
PropertyInitializer.newProperty("Email.mailSubject", "Your new AuthMe password"); newProperty("Email.mailSubject", "Your new AuthMe password");
@Comment("Like maxRegPerIP but with email") @Comment("Like maxRegPerIP but with email")
public static final Property<Integer> MAX_REG_PER_EMAIL = public static final Property<Integer> MAX_REG_PER_EMAIL =
PropertyInitializer.newProperty("Email.maxRegPerEmail", 1); newProperty("Email.maxRegPerEmail", 1);
@Comment("Recall players to add an email?") @Comment("Recall players to add an email?")
public static final Property<Boolean> RECALL_PLAYERS = public static final Property<Boolean> RECALL_PLAYERS =
PropertyInitializer.newProperty("Email.recallPlayers", false); newProperty("Email.recallPlayers", false);
@Comment("Delay in minute for the recall scheduler") @Comment("Delay in minute for the recall scheduler")
public static final Property<Integer> DELAY_RECALL = public static final Property<Integer> DELAY_RECALL =
PropertyInitializer.newProperty("Email.delayRecall", 5); newProperty("Email.delayRecall", 5);
@Comment("Send the new password drawn in an image?") @Comment("Send the new password drawn in an image?")
public static final Property<Boolean> PASSWORD_AS_IMAGE = public static final Property<Boolean> PASSWORD_AS_IMAGE =
PropertyInitializer.newProperty("Email.generateImage", false); newProperty("Email.generateImage", false);
@Comment("The OAuth2 token") @Comment("The OAuth2 token")
public static final Property<String> OAUTH2_TOKEN = public static final Property<String> OAUTH2_TOKEN =
PropertyInitializer.newProperty("Email.emailOauth2Token", ""); newProperty("Email.emailOauth2Token", "");
@Comment("Email notifications when the server shuts down") @Comment("Email notifications when the server shuts down")
public static final Property<Boolean> SHUTDOWN_MAIL = public static final Property<Boolean> SHUTDOWN_MAIL =
PropertyInitializer.newProperty("Email.shutDownEmail", false); newProperty("Email.shutDownEmail", false);
@Comment("Email notification address when the server is shut down") @Comment("Email notification address when the server is shut down")
public static final Property<String> SHUTDOWN_MAIL_ADDRESS = public static final Property<String> SHUTDOWN_MAIL_ADDRESS =
PropertyInitializer.newProperty("Email.shutDownEmailAddress", "your@mail.com"); newProperty("Email.shutDownEmailAddress", "your@mail.com");
private EmailSettings() { private EmailSettings() {
} }

View File

@ -1,8 +1,8 @@
package fr.xephi.authme.util; package fr.xephi.authme.util;
import com.google.common.io.Files; import com.google.common.io.Files;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.logger.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.logger.ConsoleLoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;