#704 Implement reloading via injector
- Create interfaces Reloadable and SettingsDependent to recognize reloadable classes - Iterate through instances in injector to reload
This commit is contained in:
@@ -3,6 +3,7 @@ package fr.xephi.authme.security;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.events.PasswordEncryptionEvent;
|
||||
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
@@ -15,7 +16,7 @@ import javax.inject.Inject;
|
||||
/**
|
||||
* Manager class for password-related operations.
|
||||
*/
|
||||
public class PasswordSecurity {
|
||||
public class PasswordSecurity implements Reloadable {
|
||||
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
@@ -36,6 +37,7 @@ public class PasswordSecurity {
|
||||
* Load or reload the configuration.
|
||||
*/
|
||||
@PostConstruct
|
||||
@Override
|
||||
public void reload() {
|
||||
this.algorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
|
||||
this.supportOldAlgorithm = settings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.security.crypts.description.HasSalt;
|
||||
import fr.xephi.authme.security.crypts.description.Recommendation;
|
||||
import fr.xephi.authme.security.crypts.description.SaltType;
|
||||
@@ -13,13 +14,13 @@ import javax.inject.Inject;
|
||||
|
||||
@Recommendation(Usage.RECOMMENDED) // provided the salt length is >= 8
|
||||
@HasSalt(value = SaltType.TEXT) // length depends on the bcryptLog2Rounds setting
|
||||
public class BCRYPT implements EncryptionMethod {
|
||||
public class BCRYPT implements EncryptionMethod, SettingsDependent {
|
||||
|
||||
private final int bCryptLog2Rounds;
|
||||
private int bCryptLog2Rounds;
|
||||
|
||||
@Inject
|
||||
public BCRYPT(NewSetting settings) {
|
||||
this.bCryptLog2Rounds = settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND);
|
||||
loadSettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,4 +53,9 @@ public class BCRYPT implements EncryptionMethod {
|
||||
public boolean hasSeparateSalt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSettings(NewSetting settings) {
|
||||
bCryptLog2Rounds = settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.security.crypts.description.HasSalt;
|
||||
import fr.xephi.authme.security.crypts.description.Recommendation;
|
||||
@@ -14,13 +15,13 @@ import static fr.xephi.authme.security.HashUtils.md5;
|
||||
|
||||
@Recommendation(Usage.ACCEPTABLE) // presuming that length is something sensible (>= 8)
|
||||
@HasSalt(value = SaltType.TEXT) // length defined by the doubleMd5SaltLength setting
|
||||
public class SALTED2MD5 extends SeparateSaltMethod {
|
||||
public class SALTED2MD5 extends SeparateSaltMethod implements SettingsDependent {
|
||||
|
||||
private final int saltLength;
|
||||
private int saltLength;
|
||||
|
||||
@Inject
|
||||
public SALTED2MD5(NewSetting settings) {
|
||||
saltLength = settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH);
|
||||
loadSettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,4 +34,9 @@ public class SALTED2MD5 extends SeparateSaltMethod {
|
||||
return RandomString.generateHex(saltLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSettings(NewSetting settings) {
|
||||
saltLength = settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import fr.xephi.authme.security.HashUtils;
|
||||
|
||||
public class SMF extends UsernameSaltMethod {
|
||||
|
||||
@Override
|
||||
public HashedPassword computeHash(String password, String name) {
|
||||
return new HashedPassword(HashUtils.sha1(name.toLowerCase() + password));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user