Change password task to async process
- Perform async change password task just like other async processes: via Management - Remove legacy setting - Remove now unused service getter (#736)
This commit is contained in:
@@ -736,15 +736,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Service getters (deprecated)
|
||||
// Use @Inject fields instead
|
||||
// -------------
|
||||
/**
|
||||
* @return Plugin's messages.
|
||||
* @deprecated should be used in API classes only (temporarily)
|
||||
*/
|
||||
@Deprecated
|
||||
public Messages getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NewSetting
|
||||
* @deprecated should be used in API classes only (temporarily)
|
||||
|
||||
+3
-12
@@ -1,13 +1,10 @@
|
||||
package fr.xephi.authme.command.executable.changepassword;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.task.ChangePasswordTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import fr.xephi.authme.util.ValidationService.ValidationResult;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -26,15 +23,11 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
|
||||
@Inject
|
||||
// TODO ljacqu 20160531: Remove this once change password task runs as a process (via Management)
|
||||
private PasswordSecurity passwordSecurity;
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments) {
|
||||
@@ -54,9 +47,7 @@ public class ChangePasswordCommand extends PlayerCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
AuthMe plugin = AuthMe.getInstance();
|
||||
// TODO ljacqu 20160117: Call async task via Management
|
||||
bukkitService.runTaskAsynchronously(
|
||||
new ChangePasswordTask(plugin, player, oldPassword, newPassword, passwordSecurity));
|
||||
management.performPasswordChange(player, oldPassword, newPassword);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.process.changepassword.AsyncChangePassword;
|
||||
import fr.xephi.authme.process.email.AsyncAddEmail;
|
||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||
import fr.xephi.authme.process.join.AsynchronousJoin;
|
||||
@@ -36,9 +37,12 @@ public class Management {
|
||||
private AsynchronousLogin asynchronousLogin;
|
||||
@Inject
|
||||
private AsynchronousUnregister asynchronousUnregister;
|
||||
@Inject
|
||||
private AsyncChangePassword asyncChangePassword;
|
||||
|
||||
Management() { }
|
||||
|
||||
|
||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
@@ -111,6 +115,15 @@ public class Management {
|
||||
});
|
||||
}
|
||||
|
||||
public void performPasswordChange(final Player player, final String oldPassword, final String newPassword) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
asyncChangePassword.changePassword(player, oldPassword, newPassword);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void runTask(Runnable runnable) {
|
||||
bukkitService.runTaskAsynchronously(runnable);
|
||||
}
|
||||
|
||||
+37
-29
@@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.task;
|
||||
package fr.xephi.authme.process.changepassword;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -6,52 +6,60 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.process.ProcessService;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ChangePasswordTask implements Runnable {
|
||||
import javax.inject.Inject;
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final Player player;
|
||||
private final String oldPassword;
|
||||
private final String newPassword;
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
public class AsyncChangePassword implements AsynchronousProcess {
|
||||
|
||||
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword,
|
||||
PasswordSecurity passwordSecurity) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.oldPassword = oldPassword;
|
||||
this.newPassword = newPassword;
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
}
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Messages m = plugin.getMessages();
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private ProcessService processService;
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
AsyncChangePassword() { }
|
||||
|
||||
|
||||
public void changePassword(final Player player, String oldPassword, String newPassword) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
PlayerAuth auth = playerCache.getAuth(name);
|
||||
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
|
||||
auth.setPassword(hashedPassword);
|
||||
|
||||
if (!plugin.getDataSource().updatePassword(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
if (!dataSource.updatePassword(auth)) {
|
||||
processService.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
playerCache.updatePlayer(auth);
|
||||
processService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
ConsoleLogger.info(player.getName() + " changed his password");
|
||||
if (Settings.bungee) {
|
||||
if (processService.getProperty(HooksSettings.BUNGEECORD)) {
|
||||
final String hash = hashedPassword.getHash();
|
||||
final String salt = hashedPassword.getSalt();
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
|
||||
bukkitService.scheduleSyncDelayedTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
@@ -64,7 +72,7 @@ public class ChangePasswordTask implements Runnable {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
m.send(player, MessageKey.WRONG_PASSWORD);
|
||||
processService.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package fr.xephi.authme.settings;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
@@ -26,7 +25,6 @@ public final class Settings {
|
||||
public static boolean protectInventoryBeforeLogInEnabled;
|
||||
public static boolean isStopEnabled;
|
||||
public static boolean reloadSupport;
|
||||
public static boolean bungee;
|
||||
public static boolean forceRegLogin;
|
||||
public static boolean noTeleport;
|
||||
public static boolean isRemoveSpeedEnabled;
|
||||
@@ -65,7 +63,6 @@ public final class Settings {
|
||||
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
bungee = load(HooksSettings.BUNGEECORD);
|
||||
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
|
||||
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
|
||||
noTeleport = load(RestrictionSettings.NO_TELEPORT);
|
||||
|
||||
Reference in New Issue
Block a user