mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Transfer password.
This commit is contained in:
parent
33330e9345
commit
d0ea7d9c37
6 changed files with 24 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue