From d0ea7d9c378eb323b1372e83ce752c2c9065f385 Mon Sep 17 00:00:00 2001 From: Me Car Date: Tue, 5 Jan 2016 02:40:05 +0900 Subject: [PATCH] Transfer password. --- Mage.Common/src/mage/interfaces/MageServer.java | 2 +- Mage.Common/src/mage/remote/Connection.java | 9 +++++++++ Mage.Common/src/mage/remote/SessionImpl.java | 2 +- .../src/main/java/mage/server/MageServerImpl.java | 14 +++++++------- Mage.Server/src/main/java/mage/server/Session.java | 7 ++++--- .../src/main/java/mage/server/SessionManager.java | 4 ++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index 4d30942a1e..75baad0e6a 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -56,7 +56,7 @@ import mage.view.UserView; public interface MageServer { // connection methods - boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException; + boolean registerClient(String userName, String password, String sessionId, MageVersion version) throws MageException; boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException; // Not used diff --git a/Mage.Common/src/mage/remote/Connection.java b/Mage.Common/src/mage/remote/Connection.java index ddb78d413c..4b68eb2560 100644 --- a/Mage.Common/src/mage/remote/Connection.java +++ b/Mage.Common/src/mage/remote/Connection.java @@ -44,6 +44,7 @@ public class Connection { private String host; private int port; private String username; + private String password; private String adminPassword; private ProxyType proxyType; private String proxyHost; @@ -164,6 +165,14 @@ public class Connection { this.username = username; } + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + public String getAdminPassword() { return adminPassword; } diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index 5045023cea..a75ab5ab49 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -280,7 +280,7 @@ public class SessionImpl implements Session { boolean registerResult; if (connection.getAdminPassword() == null) { // for backward compatibility. don't remove twice call - first one does nothing but for version checking - registerResult = server.registerClient(connection.getUsername(), sessionId, client.getVersion()); + registerResult = server.registerClient(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion()); if (registerResult) { server.setUserData(connection.getUsername(), sessionId, connection.getUserData()); } diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index 46c6ce0aad..2405d45f6b 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -96,24 +96,24 @@ public class MageServerImpl implements MageServer { private static final Logger logger = Logger.getLogger(MageServerImpl.class); private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor(); - private final String password; + private final String adminPassword; private final boolean testMode; - public MageServerImpl(String password, boolean testMode) { - this.password = password; + public MageServerImpl(String adminPassword, boolean testMode) { + this.adminPassword = adminPassword; this.testMode = testMode; ServerMessagesUtil.getInstance().getMessages(); } @Override - public boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException { + public boolean registerClient(String userName, String password, String sessionId, MageVersion version) throws MageException { try { if (version.compareTo(Main.getVersion()) != 0) { logger.info("MageVersionException: userName=" + userName + ", version=" + version); LogServiceImpl.instance.log(LogKeys.KEY_WRONG_VERSION, userName, version.toString(), Main.getVersion().toString(), sessionId); throw new MageVersionException(version, Main.getVersion()); } - return SessionManager.getInstance().registerUser(sessionId, userName); + return SessionManager.getInstance().registerUser(sessionId, userName, password); } catch (MageException ex) { if (ex instanceof MageVersionException) { throw (MageVersionException) ex; @@ -134,12 +134,12 @@ public class MageServerImpl implements MageServer { } @Override - public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException { + public boolean registerAdmin(String adminPassword, String sessionId, MageVersion version) throws MageException { try { if (version.compareTo(Main.getVersion()) != 0) { throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion()); } - if (!password.equals(this.password)) { + if (!adminPassword.equals(this.adminPassword)) { throw new MageException("Wrong password"); } return SessionManager.getInstance().registerAdmin(sessionId); diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 9a03b6e0e0..9e49fcd24b 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -74,8 +74,8 @@ public class Session { this.lock = new ReentrantLock(); } - public String registerUser(String userName) throws MageException { - String returnMessage = registerUserHandling(userName); + public String registerUser(String userName, String password) throws MageException { + String returnMessage = registerUserHandling(userName, password); if (returnMessage != null) { sendErrorMessageToClient(returnMessage); } @@ -86,7 +86,7 @@ public class Session { return lock.isLocked(); } - public String registerUserHandling(String userName) throws MageException { + public String registerUserHandling(String userName, String password) throws MageException { this.isAdmin = false; if (userName.equals("Admin")) { return "User name Admin already in use"; @@ -102,6 +102,7 @@ public class Session { if (m.find()) { return "User name '" + userName + "' includes not allowed characters: use a-z, A-Z and 0-9"; } + // TODO: Do an authentication with userName and password. User user = UserManager.getInstance().createUser(userName, host); boolean reconnect = false; if (user == null) { // user already exists diff --git a/Mage.Server/src/main/java/mage/server/SessionManager.java b/Mage.Server/src/main/java/mage/server/SessionManager.java index d7a6db388e..bdfbce5a7d 100644 --- a/Mage.Server/src/main/java/mage/server/SessionManager.java +++ b/Mage.Server/src/main/java/mage/server/SessionManager.java @@ -70,10 +70,10 @@ public class SessionManager { sessions.put(sessionId, session); } - public boolean registerUser(String sessionId, String userName) throws MageException { + public boolean registerUser(String sessionId, String userName, String password) throws MageException { Session session = sessions.get(sessionId); if (session != null) { - String returnMessage = session.registerUser(userName); + String returnMessage = session.registerUser(userName, password); if (returnMessage == null) { LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);