From 3f039d641acc3248c818fffd1d7cfcd87f2e2698 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Fri, 20 May 2016 19:42:30 +0200 Subject: [PATCH] #707 Convert sync processes into services --- .../authme/process/AsynchronousProcess.java | 10 ++ .../fr/xephi/authme/process/NewProcess.java | 7 - .../java/fr/xephi/authme/process/Process.java | 8 - .../xephi/authme/process/ProcessService.java | 15 -- .../authme/process/SyncProcessManager.java | 86 +++++++++++ .../authme/process/SynchronousProcess.java | 10 ++ .../authme/process/email/AsyncAddEmail.java | 4 +- .../process/email/AsyncChangeEmail.java | 4 +- .../authme/process/join/AsynchronousJoin.java | 7 +- .../process/login/AsynchronousLogin.java | 29 ++-- .../process/login/ProcessSyncPlayerLogin.java | 143 ++++++++---------- .../process/logout/AsynchronousLogout.java | 25 +-- .../ProcessSynchronousPlayerLogout.java | 57 ++++--- .../authme/process/quit/AsynchronousQuit.java | 14 +- .../quit/ProcessSyncronousPlayerQuit.java | 34 +---- .../process/register/AsyncRegister.java | 24 +-- .../register/ProcessSyncEmailRegister.java | 39 +++-- .../register/ProcessSyncPasswordRegister.java | 41 +++-- .../unregister/AsynchronousUnregister.java | 4 +- .../authme/process/ProcessServiceTest.java | 20 --- 20 files changed, 303 insertions(+), 278 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/process/AsynchronousProcess.java delete mode 100644 src/main/java/fr/xephi/authme/process/NewProcess.java delete mode 100644 src/main/java/fr/xephi/authme/process/Process.java create mode 100644 src/main/java/fr/xephi/authme/process/SyncProcessManager.java create mode 100644 src/main/java/fr/xephi/authme/process/SynchronousProcess.java diff --git a/src/main/java/fr/xephi/authme/process/AsynchronousProcess.java b/src/main/java/fr/xephi/authme/process/AsynchronousProcess.java new file mode 100644 index 000000000..80c063130 --- /dev/null +++ b/src/main/java/fr/xephi/authme/process/AsynchronousProcess.java @@ -0,0 +1,10 @@ +package fr.xephi.authme.process; + +/** + * Marker interface for asynchronous AuthMe processes. + *

+ * These processes handle intensive (I/O or otherwise) actions and are + * therefore scheduled to run asynchronously. + */ +public interface AsynchronousProcess { +} diff --git a/src/main/java/fr/xephi/authme/process/NewProcess.java b/src/main/java/fr/xephi/authme/process/NewProcess.java deleted file mode 100644 index 524f2c773..000000000 --- a/src/main/java/fr/xephi/authme/process/NewProcess.java +++ /dev/null @@ -1,7 +0,0 @@ -package fr.xephi.authme.process; - -/** - * Marker interface for AuthMe processes. - */ -public interface NewProcess { -} diff --git a/src/main/java/fr/xephi/authme/process/Process.java b/src/main/java/fr/xephi/authme/process/Process.java deleted file mode 100644 index d6efd2b2b..000000000 --- a/src/main/java/fr/xephi/authme/process/Process.java +++ /dev/null @@ -1,8 +0,0 @@ -package fr.xephi.authme.process; - -/** - * Common interface for AuthMe processes. - */ -public interface Process extends Runnable { - -} diff --git a/src/main/java/fr/xephi/authme/process/ProcessService.java b/src/main/java/fr/xephi/authme/process/ProcessService.java index e8f0a73ba..3dede7474 100644 --- a/src/main/java/fr/xephi/authme/process/ProcessService.java +++ b/src/main/java/fr/xephi/authme/process/ProcessService.java @@ -3,8 +3,6 @@ package fr.xephi.authme.process; import fr.xephi.authme.AuthMe; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; -import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.domain.Property; import fr.xephi.authme.util.BukkitService; @@ -29,8 +27,6 @@ public class ProcessService { @Inject private AuthMe authMe; @Inject - private PasswordSecurity passwordSecurity; - @Inject private ValidationService validationService; @Inject private BukkitService bukkitService; @@ -145,17 +141,6 @@ public class ProcessService { return authMe; } - /** - * Compute the hash for the given password. - * - * @param password the password to hash - * @param username the user to hash for - * @return the resulting hash - */ - public HashedPassword computeHash(String password, String username) { - return passwordSecurity.computeHash(password, username); - } - /** * Verifies whether a password is valid according to the plugin settings. * diff --git a/src/main/java/fr/xephi/authme/process/SyncProcessManager.java b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java new file mode 100644 index 000000000..221e1e8c7 --- /dev/null +++ b/src/main/java/fr/xephi/authme/process/SyncProcessManager.java @@ -0,0 +1,86 @@ +package fr.xephi.authme.process; + +import fr.xephi.authme.process.login.ProcessSyncPlayerLogin; +import fr.xephi.authme.process.logout.ProcessSynchronousPlayerLogout; +import fr.xephi.authme.process.quit.ProcessSyncronousPlayerQuit; +import fr.xephi.authme.process.register.ProcessSyncEmailRegister; +import fr.xephi.authme.process.register.ProcessSyncPasswordRegister; +import fr.xephi.authme.util.BukkitService; +import org.bukkit.entity.Player; + +import javax.inject.Inject; + +/** + * Manager for scheduling synchronous processes internally from the asynchronous processes. + * These synchronous processes are a continuation of the associated async processes; they only + * contain certain tasks which may only be run synchronously (most interactions with Bukkit). + * These synchronous tasks should never be called aside from the asynchronous processes. + * + * @see Management + */ +public class SyncProcessManager { + + @Inject + private BukkitService bukkitService; + + @Inject + private ProcessSyncEmailRegister processSyncEmailRegister; + @Inject + private ProcessSyncPasswordRegister processSyncPasswordRegister; + @Inject + private ProcessSyncPlayerLogin processSyncPlayerLogin; + @Inject + private ProcessSynchronousPlayerLogout processSynchronousPlayerLogout; + @Inject + private ProcessSyncronousPlayerQuit processSyncronousPlayerQuit; + + + public void processSyncEmailRegister(final Player player) { + runTask(new Runnable() { + @Override + public void run() { + processSyncEmailRegister.processEmailRegister(player); + } + }); + } + + public void processSyncPasswordRegister(final Player player) { + runTask(new Runnable() { + @Override + public void run() { + processSyncPasswordRegister.processPasswordRegister(player); + } + }); + } + + public void processSyncPlayerLogout(final Player player) { + runTask(new Runnable() { + @Override + public void run() { + processSynchronousPlayerLogout.processSyncLogout(player); + } + }); + } + + public void processSyncPlayerLogin(final Player player) { + runTask(new Runnable() { + @Override + public void run() { + processSyncPlayerLogin.processPlayerLogin(player); + } + }); + } + + public void processSyncPlayerQuit(final Player player, final boolean isOp, final boolean needToChange) { + runTask(new Runnable() { + @Override + public void run() { + processSyncronousPlayerQuit.processSyncQuit(player, isOp, needToChange); + } + }); + } + + private void runTask(Runnable runnable) { + bukkitService.scheduleSyncDelayedTask(runnable); + } +} diff --git a/src/main/java/fr/xephi/authme/process/SynchronousProcess.java b/src/main/java/fr/xephi/authme/process/SynchronousProcess.java new file mode 100644 index 000000000..6c23a0f81 --- /dev/null +++ b/src/main/java/fr/xephi/authme/process/SynchronousProcess.java @@ -0,0 +1,10 @@ +package fr.xephi.authme.process; + +/** + * Marker interface for synchronous processes. + *

+ * Such processes are scheduled by {@link AsynchronousProcess asynchronous tasks} to perform tasks + * which are required to be executed synchronously (e.g. interactions with the Bukkit API). + */ +public interface SynchronousProcess { +} diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java index f4f1ed87f..d7aa31279 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncAddEmail.java @@ -5,7 +5,7 @@ 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.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; import org.bukkit.entity.Player; @@ -15,7 +15,7 @@ import javax.inject.Inject; /** * Async task to add an email to an account. */ -public class AsyncAddEmail implements NewProcess { +public class AsyncAddEmail implements AsynchronousProcess { @Inject private ProcessService service; diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index 2f4e90b5b..3ca6a2462 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -4,7 +4,7 @@ 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.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.properties.RegistrationSettings; import org.bukkit.entity.Player; @@ -14,7 +14,7 @@ import javax.inject.Inject; /** * Async task for changing the email. */ -public class AsyncChangeEmail implements NewProcess { +public class AsyncChangeEmail implements AsynchronousProcess { @Inject private ProcessService service; diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index f35044758..6689172ea 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -14,7 +14,7 @@ import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.SpawnLoader; @@ -40,9 +40,8 @@ import javax.inject.Inject; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; -/** - */ -public class AsynchronousJoin implements NewProcess { + +public class AsynchronousJoin implements AsynchronousProcess { @Inject private AuthMe plugin; diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 1bbc6bafc..74de3b15d 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -13,8 +13,9 @@ import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.security.RandomString; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; @@ -34,7 +35,7 @@ import java.util.List; /** */ -public class AsynchronousLogin implements NewProcess { +public class AsynchronousLogin implements AsynchronousProcess { @Inject private AuthMe plugin; @@ -54,6 +55,10 @@ public class AsynchronousLogin implements NewProcess { @Inject private LimboCache limboCache; + @Inject + private SyncProcessManager syncProcessManager; + + AsynchronousLogin() { } private boolean needsCaptcha(Player player) { @@ -187,16 +192,16 @@ public class AsynchronousLogin implements NewProcess { // task, we schedule it in the end // so that we can be sure, and have not to care if it might be // processed in other order. - ProcessSyncPlayerLogin syncPlayerLogin = new ProcessSyncPlayerLogin(player, plugin, database, service); - if (syncPlayerLogin.getLimbo() != null) { - if (syncPlayerLogin.getLimbo().getTimeoutTask() != null) { - syncPlayerLogin.getLimbo().getTimeoutTask().cancel(); + LimboPlayer limboPlayer = limboCache.getLimboPlayer(name); + if (limboPlayer != null) { + if (limboPlayer.getTimeoutTask() != null) { + limboPlayer.getTimeoutTask().cancel(); } - if (syncPlayerLogin.getLimbo().getMessageTask() != null) { - syncPlayerLogin.getLimbo().getMessageTask().cancel(); + if (limboPlayer.getMessageTask() != null) { + limboPlayer.getMessageTask().cancel(); } } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncPlayerLogin); + syncProcessManager.processSyncPlayerLogin(player); } else if (player.isOnline()) { if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) { ConsoleLogger.info(player.getName() + " used the wrong password"); @@ -233,12 +238,12 @@ public class AsynchronousLogin implements NewProcess { ConsoleLogger.info(message); for (Player onlinePlayer : service.getOnlinePlayers()) { - if ((onlinePlayer.getName().equalsIgnoreCase(onlinePlayer.getName()) - && permissionsManager.hasPermission(onlinePlayer, PlayerPermission.SEE_OWN_ACCOUNTS))) { + if (onlinePlayer.getName().equalsIgnoreCase(player.getName()) + && permissionsManager.hasPermission(onlinePlayer, PlayerPermission.SEE_OWN_ACCOUNTS)) { onlinePlayer.sendMessage("You own " + auths.size() + " accounts:"); onlinePlayer.sendMessage(message); } else if (permissionsManager.hasPermission(onlinePlayer, AdminPermission.SEE_OTHER_ACCOUNTS)) { - onlinePlayer.sendMessage("The user " + onlinePlayer.getName() + " has " + auths.size() + " accounts:"); + onlinePlayer.sendMessage("The user " + player.getName() + " has " + auths.size() + " accounts:"); onlinePlayer.sendMessage(message); } } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java index 9f5de6bd9..e40226d6e 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncPlayerLogin.java @@ -4,7 +4,6 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; @@ -13,8 +12,8 @@ import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.listener.AuthMePlayerListener; -import fr.xephi.authme.process.Process; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -29,125 +28,106 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffectType; +import javax.inject.Inject; + import static fr.xephi.authme.settings.properties.PluginSettings.KEEP_COLLISIONS_DISABLED; import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN; -public class ProcessSyncPlayerLogin implements Process { +public class ProcessSyncPlayerLogin implements SynchronousProcess { - private final LimboPlayer limbo; - private final Player player; - private final String name; - private final PlayerAuth auth; - private final AuthMe plugin; - private final PluginManager pm; - private final JsonCache playerCache; - private final ProcessService service; + @Inject + private AuthMe plugin; + + @Inject + private ProcessService service; + + @Inject + private LimboCache limboCache; + + @Inject + private DataSource dataSource; + + @Inject + // TODO ljacqu 20160520: Need to check whether we want to inject PluginManager, or some intermediate service + private PluginManager pluginManager; private final boolean restoreCollisions = MethodUtils .getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null; - /** - * Constructor for ProcessSyncPlayerLogin. - * - * @param player Player - * @param plugin AuthMe - * @param database DataSource - * @param service The process service - */ - public ProcessSyncPlayerLogin(Player player, AuthMe plugin, DataSource database, ProcessService service) { - this.plugin = plugin; - this.pm = plugin.getServer().getPluginManager(); - this.player = player; - this.name = player.getName().toLowerCase(); - this.limbo = LimboCache.getInstance().getLimboPlayer(name); - this.auth = database.getAuth(name); - this.playerCache = new JsonCache(); - this.service = service; - } + ProcessSyncPlayerLogin() { } - public LimboPlayer getLimbo() { - return limbo; - } - private void restoreOpState() { - player.setOp(limbo.isOperator()); - } - - private void packQuitLocation() { + private void packQuitLocation(Player player, PlayerAuth auth) { Utils.packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player); } - private void teleportBackFromSpawn() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc()); - pm.callEvent(tpEvent); + private void teleportBackFromSpawn(Player player, LimboPlayer limboPlayer) { + AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limboPlayer.getLoc()); + pluginManager.callEvent(tpEvent); if (!tpEvent.isCancelled() && tpEvent.getTo() != null) { player.teleport(tpEvent.getTo()); } } - private void teleportToSpawn() { + private void teleportToSpawn(Player player) { Location spawnL = plugin.getSpawnLocation(player); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true); - pm.callEvent(tpEvent); + pluginManager.callEvent(tpEvent); if (!tpEvent.isCancelled() && tpEvent.getTo() != null) { player.teleport(tpEvent.getTo()); } } - private void restoreSpeedEffects() { - if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && service.getProperty(RestrictionSettings.REMOVE_SPEED)) { + private void restoreSpeedEffects(Player player) { + if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) + && service.getProperty(RestrictionSettings.REMOVE_SPEED)) { player.setWalkSpeed(0.2F); player.setFlySpeed(0.1F); } } - private void restoreInventory() { + private void restoreInventory(Player player) { RestoreInventoryEvent event = new RestoreInventoryEvent(player); - pm.callEvent(event); + pluginManager.callEvent(event); if (!event.isCancelled() && plugin.inventoryProtector != null) { plugin.inventoryProtector.sendInventoryPacket(player); } } - private void forceCommands() { + private void forceCommands(Player player) { for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS)) { player.performCommand(command.replace("%p", player.getName())); } for (String command : service.getProperty(RegistrationSettings.FORCE_COMMANDS_AS_CONSOLE)) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); + Bukkit.getServer().dispatchCommand( + Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName())); } } - private void sendBungeeMessage() { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("Forward"); - out.writeUTF("ALL"); - out.writeUTF("AuthMe"); - out.writeUTF("login;" + name); - player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); - } - - @Override - public void run() { + public void processPlayerLogin(Player player) { + final String name = player.getName().toLowerCase(); // Limbo contains the State of the Player before /login + final LimboPlayer limbo = limboCache.getLimboPlayer(name); + final PlayerAuth auth = dataSource.getAuth(name); + if (limbo != null) { // Restore Op state and Permission Group - restoreOpState(); + restoreOpState(player, limbo); Utils.setGroup(player, GroupType.LOGGEDIN); if (!Settings.noTeleport) { if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { - packQuitLocation(); + packQuitLocation(player, auth); } else { - teleportBackFromSpawn(); + teleportBackFromSpawn(player, limbo); } } else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { - teleportToSpawn(); + teleportToSpawn(player); } else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { - packQuitLocation(); + packQuitLocation(player, auth); } else { - teleportBackFromSpawn(); + teleportBackFromSpawn(player, limbo); } } @@ -156,18 +136,15 @@ public class ProcessSyncPlayerLogin implements Process { } if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) { - restoreInventory(); + restoreInventory(player); } if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) { plugin.tablistHider.sendTablist(player); } - // Cleanup no longer used temporary data - LimboCache.getInstance().deleteLimboPlayer(name); - if (playerCache.doesCacheExist(player)) { - playerCache.removeCache(player); - } + // Clean up no longer used temporary data + limboCache.deleteLimboPlayer(name); } // We can now display the join message (if delayed) @@ -183,7 +160,7 @@ public class ProcessSyncPlayerLogin implements Process { AuthMePlayerListener.joinMessage.remove(name); } - restoreSpeedEffects(); + restoreSpeedEffects(player); if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { player.removePotionEffect(PotionEffectType.BLINDNESS); } @@ -192,7 +169,7 @@ public class ProcessSyncPlayerLogin implements Process { Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player)); player.saveData(); if (service.getProperty(HooksSettings.BUNGEECORD)) { - sendBungeeMessage(); + sendBungeeMessage(player); } // Login is done, display welcome message if (service.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) { @@ -208,12 +185,16 @@ public class ProcessSyncPlayerLogin implements Process { } // Login is now finished; we can force all commands - forceCommands(); + forceCommands(player); - sendTo(); + sendTo(player); } - private void sendTo() { + private void restoreOpState(Player player, LimboPlayer limboPlayer) { + player.setOp(limboPlayer.isOperator()); + } + + private void sendTo(Player player) { if (!service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); @@ -221,4 +202,14 @@ public class ProcessSyncPlayerLogin implements Process { player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } } + + private void sendBungeeMessage(Player player) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Forward"); + out.writeUTF("ALL"); + out.writeUTF("AuthMe"); + out.writeUTF("login;" + player.getName()); + player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); + } + } diff --git a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java index 2ea02d474..840ebfc9c 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -6,15 +6,16 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils.GroupType; import org.bukkit.entity.Player; import javax.inject.Inject; -public class AsynchronousLogout implements NewProcess { +public class AsynchronousLogout implements AsynchronousProcess { @Inject private AuthMe plugin; @@ -31,21 +32,23 @@ public class AsynchronousLogout implements NewProcess { @Inject private LimboCache limboCache; + @Inject + private SyncProcessManager syncProcessManager; + AsynchronousLogout() { } - public void logout(Player player) { + public void logout(final Player player) { final String name = player.getName().toLowerCase(); if (!playerCache.isAuthenticated(name)) { service.send(player, MessageKey.NOT_LOGGED_IN); return; } - final Player p = player; - PlayerAuth auth = PlayerCache.getInstance().getAuth(name); + PlayerAuth auth = playerCache.getAuth(name); database.updateSession(auth); - auth.setQuitLocX(p.getLocation().getX()); - auth.setQuitLocY(p.getLocation().getY()); - auth.setQuitLocZ(p.getLocation().getZ()); - auth.setWorld(p.getWorld().getName()); + auth.setQuitLocX(player.getLocation().getX()); + auth.setQuitLocY(player.getLocation().getY()); + auth.setQuitLocZ(player.getLocation().getZ()); + auth.setWorld(player.getWorld().getName()); database.updateQuitLoc(auth); playerCache.removePlayer(name); @@ -53,7 +56,7 @@ public class AsynchronousLogout implements NewProcess { service.scheduleSyncDelayedTask(new Runnable() { @Override public void run() { - Utils.teleportToSpawn(p); + Utils.teleportToSpawn(player); } }); if (limboCache.hasLimboPlayer(name)) { @@ -61,6 +64,6 @@ public class AsynchronousLogout implements NewProcess { } limboCache.addLimboPlayer(player); Utils.setGroup(player, GroupType.NOTLOGGEDIN); - service.scheduleSyncDelayedTask(new ProcessSynchronousPlayerLogout(p, plugin, service)); + syncProcessManager.processSyncPlayerLogout(player); } } diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java index d6d66b901..7f781be24 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSynchronousPlayerLogout.java @@ -7,8 +7,8 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.events.LogoutEvent; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.process.Process; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -20,47 +20,42 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitTask; -/** - */ -public class ProcessSynchronousPlayerLogout implements Process { +import javax.inject.Inject; - private final Player player; - private final AuthMe plugin; - private final String name; - private final ProcessService service; +import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; - /** - * Constructor for ProcessSynchronousPlayerLogout. - * - * @param player Player - * @param plugin AuthMe - * @param service The process service - */ - public ProcessSynchronousPlayerLogout(Player player, AuthMe plugin, ProcessService service) { - this.player = player; - this.plugin = plugin; - this.name = player.getName().toLowerCase(); - this.service = service; - } - protected void sendBungeeMessage() { +public class ProcessSynchronousPlayerLogout implements SynchronousProcess { + + @Inject + private AuthMe plugin; + + @Inject + private ProcessService service; + + @Inject + private LimboCache limboCache; + + ProcessSynchronousPlayerLogout() { } + + private void sendBungeeMessage(Player player) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Forward"); out.writeUTF("ALL"); out.writeUTF("AuthMe"); - out.writeUTF("logout;" + name); + out.writeUTF("logout;" + player.getName()); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } - protected void restoreSpeedEffect() { + private void restoreSpeedEffect(Player player) { if (Settings.isRemoveSpeedEnabled) { player.setWalkSpeed(0.0F); player.setFlySpeed(0.0F); } } - @Override - public void run() { + public void processSyncLogout(Player player) { + final String name = player.getName().toLowerCase(); if (plugin.sessions.containsKey(name)) { plugin.sessions.get(name).cancel(); plugin.sessions.remove(name); @@ -68,15 +63,15 @@ public class ProcessSynchronousPlayerLogout implements Process { if (Settings.protectInventoryBeforeLogInEnabled) { plugin.inventoryProtector.sendBlankInventoryPacket(player); } - int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * 20; + int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL); if (timeOut != 0) { BukkitTask id = service.runTaskLater(new TimeoutTask(plugin, name, player), timeOut); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTask(id); + limboCache.getLimboPlayer(name).setTimeoutTask(id); } BukkitTask msgT = service.runTask(new MessageTask(service.getBukkitService(), plugin.getMessages(), name, MessageKey.LOGIN_MESSAGE, interval)); - LimboCache.getInstance().getLimboPlayer(name).setMessageTask(msgT); + limboCache.getLimboPlayer(name).setMessageTask(msgT); if (player.isInsideVehicle() && player.getVehicle() != null) { player.getVehicle().eject(); } @@ -84,11 +79,11 @@ public class ProcessSynchronousPlayerLogout implements Process { player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2)); } player.setOp(false); - restoreSpeedEffect(); + restoreSpeedEffect(player); // Player is now logout... Time to fire event ! Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player)); if (Settings.bungee) { - sendBungeeMessage(); + sendBungeeMessage(player); } service.send(player, MessageKey.LOGOUT_SUCCESS); ConsoleLogger.info(player.getName() + " logged out"); diff --git a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java index 110faa336..d31f305c9 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsynchronousQuit.java @@ -7,8 +7,9 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.datasource.CacheDataSource; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.StringUtils; @@ -19,7 +20,9 @@ import org.bukkit.scheduler.BukkitTask; import javax.inject.Inject; -public class AsynchronousQuit implements NewProcess { +import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; + +public class AsynchronousQuit implements AsynchronousProcess { @Inject private AuthMe plugin; @@ -36,6 +39,9 @@ public class AsynchronousQuit implements NewProcess { @Inject private LimboCache limboCache; + @Inject + private SyncProcessManager syncProcessManager; + AsynchronousQuit() { } @@ -86,7 +92,7 @@ public class AsynchronousQuit implements NewProcess { postLogout(name); } - }, Settings.getSessionTimeout * 20 * 60); + }, Settings.getSessionTimeout * TICKS_PER_MINUTE); plugin.sessions.put(name, task); } else { @@ -100,7 +106,7 @@ public class AsynchronousQuit implements NewProcess { } if (plugin.isEnabled()) { - service.scheduleSyncDelayedTask(new ProcessSyncronousPlayerQuit(plugin, player, isOp, needToChange)); + syncProcessManager.processSyncPlayerQuit(player, isOp, needToChange); } // remove player from cache if (database instanceof CacheDataSource) { diff --git a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java index bf7ab9676..c1382c2c3 100644 --- a/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/ProcessSyncronousPlayerQuit.java @@ -1,40 +1,12 @@ package fr.xephi.authme.process.quit; -import fr.xephi.authme.AuthMe; +import fr.xephi.authme.process.SynchronousProcess; import org.bukkit.entity.Player; -/** - */ -public class ProcessSyncronousPlayerQuit implements Runnable { - protected final AuthMe plugin; - protected final Player player; - protected final boolean isOp; - protected final boolean needToChange; +public class ProcessSyncronousPlayerQuit implements SynchronousProcess { - /** - * Constructor for ProcessSyncronousPlayerQuit. - * - * @param plugin AuthMe - * @param player Player - * @param isOp boolean - * @param needToChange boolean - */ - public ProcessSyncronousPlayerQuit(AuthMe plugin, Player player - , boolean isOp, boolean needToChange) { - this.plugin = plugin; - this.player = player; - this.isOp = isOp; - this.needToChange = needToChange; - } - - /** - * Method run. - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { + public void processSyncQuit(Player player, boolean isOp, boolean needToChange) { if (needToChange) { player.setOp(isOp); } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 6ab889807..fbc6c86dd 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -6,9 +6,11 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.permission.PlayerStatePermission; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SyncProcessManager; import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.TwoFactor; import fr.xephi.authme.settings.Settings; @@ -24,7 +26,7 @@ import org.bukkit.entity.Player; import javax.inject.Inject; import java.util.List; -public class AsyncRegister implements NewProcess { +public class AsyncRegister implements AsynchronousProcess { @Inject private AuthMe plugin; @@ -35,9 +37,15 @@ public class AsyncRegister implements NewProcess { @Inject private PlayerCache playerCache; + @Inject + private PasswordSecurity passwordSecurity; + @Inject private ProcessService service; + @Inject + private SyncProcessManager syncProcessManager; + AsyncRegister() { } private boolean preRegisterCheck(Player player, String password) { @@ -104,7 +112,7 @@ public class AsyncRegister implements NewProcess { } } - final HashedPassword hashedPassword = service.computeHash(password, name); + final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); final String ip = Utils.getPlayerIp(player); PlayerAuth auth = PlayerAuth.builder() .name(name) @@ -122,15 +130,13 @@ public class AsyncRegister implements NewProcess { database.updateEmail(auth); database.updateSession(auth); plugin.mail.main(auth, password); - ProcessSyncEmailRegister sync = new ProcessSyncEmailRegister(player, service); - service.scheduleSyncDelayedTask(sync); - + syncProcessManager.processSyncEmailRegister(player); } private void passwordRegister(Player player, String password, boolean autoLogin) { final String name = player.getName().toLowerCase(); final String ip = Utils.getPlayerIp(player); - final HashedPassword hashedPassword = service.computeHash(password, name); + final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name); PlayerAuth auth = PlayerAuth.builder() .name(name) .realName(player.getName()) @@ -150,9 +156,7 @@ public class AsyncRegister implements NewProcess { // TODO: check this... plugin.getManagement().performLogin(player, "dontneed", true); } - - ProcessSyncPasswordRegister sync = new ProcessSyncPasswordRegister(player, plugin, service); - service.scheduleSyncDelayedTask(sync); + syncProcessManager.processSyncPasswordRegister(player); //give the user the secret code to setup their app code generation if (service.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) { diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index 461857aa3..894004711 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -4,8 +4,8 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.process.Process; import fr.xephi.authme.process.ProcessService; +import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; @@ -16,34 +16,29 @@ import fr.xephi.authme.util.Utils; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; -/** - */ -public class ProcessSyncEmailRegister implements Process { +import javax.inject.Inject; - private final Player player; - private final String name; - private final ProcessService service; +import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; - /** - * Constructor for ProcessSyncEmailRegister. - * - * @param player The player to process an email registration for - * @param service The process service - */ - public ProcessSyncEmailRegister(Player player, ProcessService service) { - this.player = player; - this.name = player.getName().toLowerCase(); - this.service = service; - } - @Override - public void run() { - LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); +public class ProcessSyncEmailRegister implements SynchronousProcess { + + @Inject + private ProcessService service; + + @Inject + private LimboCache limboCache; + + public ProcessSyncEmailRegister() { } + + public void processEmailRegister(Player player) { + final String name = player.getName().toLowerCase(); + LimboPlayer limbo = limboCache.getLimboPlayer(name); if (!Settings.getRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.REGISTERED); } service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); - int time = service.getProperty(RestrictionSettings.TIMEOUT) * 20; + int time = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL); if (limbo != null) { diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java index b9505143e..b46807a2d 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncPasswordRegister.java @@ -9,7 +9,7 @@ import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.process.Process; +import fr.xephi.authme.process.SynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.EmailSettings; @@ -25,35 +25,33 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitTask; +import javax.inject.Inject; + import static fr.xephi.authme.settings.properties.RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN; import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; /** */ -public class ProcessSyncPasswordRegister implements Process { +public class ProcessSyncPasswordRegister implements SynchronousProcess { - private final Player player; - private final String name; - private final AuthMe plugin; - private final ProcessService service; + @Inject + private AuthMe plugin; - public ProcessSyncPasswordRegister(Player player, AuthMe plugin, ProcessService service) { - this.player = player; - this.name = player.getName().toLowerCase(); - this.plugin = plugin; - this.service = service; - } + @Inject + private ProcessService service; - private void sendBungeeMessage() { + ProcessSyncPasswordRegister() { } + + private void sendBungeeMessage(Player player) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Forward"); out.writeUTF("ALL"); out.writeUTF("AuthMe"); - out.writeUTF("register;" + name); + out.writeUTF("register;" + player.getName()); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } - private void forceCommands() { + private void forceCommands(Player player) { for (String command : service.getProperty(RegistrationSettings.FORCE_REGISTER_COMMANDS)) { player.performCommand(command.replace("%p", player.getName())); } @@ -69,6 +67,7 @@ public class ProcessSyncPasswordRegister implements Process { * @param player the player */ private void requestLogin(Player player) { + final String name = player.getName().toLowerCase(); Utils.teleportToSpawn(player); LimboCache cache = LimboCache.getInstance(); cache.updateLimboPlayer(player); @@ -87,8 +86,8 @@ public class ProcessSyncPasswordRegister implements Process { } } - @Override - public void run() { + public void processPasswordRegister(Player player) { + final String name = player.getName().toLowerCase(); LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); if (limbo != null) { if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) { @@ -137,7 +136,7 @@ public class ProcessSyncPasswordRegister implements Process { } // Register is now finished; we can force all commands - forceCommands(); + forceCommands(player); // Request login after registration if (service.getProperty(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER)) { @@ -146,13 +145,13 @@ public class ProcessSyncPasswordRegister implements Process { } if (service.getProperty(HooksSettings.BUNGEECORD)) { - sendBungeeMessage(); + sendBungeeMessage(player); } - sendTo(); + sendTo(player); } - private void sendTo() { + private void sendTo(Player player) { if (!service.getProperty(HooksSettings.BUNGEECORD_SERVER).isEmpty()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 022899637..bf3dbb305 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -8,7 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.process.NewProcess; +import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.Settings; @@ -27,7 +27,7 @@ import javax.inject.Inject; import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND; -public class AsynchronousUnregister implements NewProcess { +public class AsynchronousUnregister implements AsynchronousProcess { @Inject private AuthMe plugin; diff --git a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java index 7bedb9142..f35babb5c 100644 --- a/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java +++ b/src/test/java/fr/xephi/authme/process/ProcessServiceTest.java @@ -5,8 +5,6 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.hooks.PluginHooks; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; -import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.properties.SecuritySettings; @@ -40,8 +38,6 @@ public class ProcessServiceTest { @Mock private Messages messages; @Mock - private PasswordSecurity passwordSecurity; - @Mock private AuthMe authMe; @Mock private DataSource dataSource; @@ -140,22 +136,6 @@ public class ProcessServiceTest { assertThat(result, equalTo(authMe)); } - @Test - public void shouldComputeHash() { - // given - String password = "test123"; - String username = "Username"; - HashedPassword hashedPassword = new HashedPassword("hashedResult", "salt12342"); - given(passwordSecurity.computeHash(password, username)).willReturn(hashedPassword); - - // when - HashedPassword result = processService.computeHash(password, username); - - // then - assertThat(result, equalTo(hashedPassword)); - verify(passwordSecurity).computeHash(password, username); - } - @Test public void shouldValidatePassword() { // given