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 {
|
public interface MageServer {
|
||||||
|
|
||||||
// connection methods
|
// 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;
|
boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException;
|
||||||
// Not used
|
// Not used
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class Connection {
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
private String username;
|
private String username;
|
||||||
|
private String password;
|
||||||
private String adminPassword;
|
private String adminPassword;
|
||||||
private ProxyType proxyType;
|
private ProxyType proxyType;
|
||||||
private String proxyHost;
|
private String proxyHost;
|
||||||
|
@ -164,6 +165,14 @@ public class Connection {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAdminPassword() {
|
public String getAdminPassword() {
|
||||||
return adminPassword;
|
return adminPassword;
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class SessionImpl implements Session {
|
||||||
boolean registerResult;
|
boolean registerResult;
|
||||||
if (connection.getAdminPassword() == null) {
|
if (connection.getAdminPassword() == null) {
|
||||||
// for backward compatibility. don't remove twice call - first one does nothing but for version checking
|
// 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) {
|
if (registerResult) {
|
||||||
server.setUserData(connection.getUsername(), sessionId, connection.getUserData());
|
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 Logger logger = Logger.getLogger(MageServerImpl.class);
|
||||||
private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
|
private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
|
||||||
|
|
||||||
private final String password;
|
private final String adminPassword;
|
||||||
private final boolean testMode;
|
private final boolean testMode;
|
||||||
|
|
||||||
public MageServerImpl(String password, boolean testMode) {
|
public MageServerImpl(String adminPassword, boolean testMode) {
|
||||||
this.password = password;
|
this.adminPassword = adminPassword;
|
||||||
this.testMode = testMode;
|
this.testMode = testMode;
|
||||||
ServerMessagesUtil.getInstance().getMessages();
|
ServerMessagesUtil.getInstance().getMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
try {
|
||||||
if (version.compareTo(Main.getVersion()) != 0) {
|
if (version.compareTo(Main.getVersion()) != 0) {
|
||||||
logger.info("MageVersionException: userName=" + userName + ", version=" + version);
|
logger.info("MageVersionException: userName=" + userName + ", version=" + version);
|
||||||
LogServiceImpl.instance.log(LogKeys.KEY_WRONG_VERSION, userName, version.toString(), Main.getVersion().toString(), sessionId);
|
LogServiceImpl.instance.log(LogKeys.KEY_WRONG_VERSION, userName, version.toString(), Main.getVersion().toString(), sessionId);
|
||||||
throw new MageVersionException(version, Main.getVersion());
|
throw new MageVersionException(version, Main.getVersion());
|
||||||
}
|
}
|
||||||
return SessionManager.getInstance().registerUser(sessionId, userName);
|
return SessionManager.getInstance().registerUser(sessionId, userName, password);
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
if (ex instanceof MageVersionException) {
|
if (ex instanceof MageVersionException) {
|
||||||
throw (MageVersionException) ex;
|
throw (MageVersionException) ex;
|
||||||
|
@ -134,12 +134,12 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registerAdmin(String password, String sessionId, MageVersion version) throws MageException {
|
public boolean registerAdmin(String adminPassword, String sessionId, MageVersion version) throws MageException {
|
||||||
try {
|
try {
|
||||||
if (version.compareTo(Main.getVersion()) != 0) {
|
if (version.compareTo(Main.getVersion()) != 0) {
|
||||||
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
|
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");
|
throw new MageException("Wrong password");
|
||||||
}
|
}
|
||||||
return SessionManager.getInstance().registerAdmin(sessionId);
|
return SessionManager.getInstance().registerAdmin(sessionId);
|
||||||
|
|
|
@ -74,8 +74,8 @@ public class Session {
|
||||||
this.lock = new ReentrantLock();
|
this.lock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String registerUser(String userName) throws MageException {
|
public String registerUser(String userName, String password) throws MageException {
|
||||||
String returnMessage = registerUserHandling(userName);
|
String returnMessage = registerUserHandling(userName, password);
|
||||||
if (returnMessage != null) {
|
if (returnMessage != null) {
|
||||||
sendErrorMessageToClient(returnMessage);
|
sendErrorMessageToClient(returnMessage);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class Session {
|
||||||
return lock.isLocked();
|
return lock.isLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String registerUserHandling(String userName) throws MageException {
|
public String registerUserHandling(String userName, String password) throws MageException {
|
||||||
this.isAdmin = false;
|
this.isAdmin = false;
|
||||||
if (userName.equals("Admin")) {
|
if (userName.equals("Admin")) {
|
||||||
return "User name Admin already in use";
|
return "User name Admin already in use";
|
||||||
|
@ -102,6 +102,7 @@ public class Session {
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
return "User name '" + userName + "' includes not allowed characters: use a-z, A-Z and 0-9";
|
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);
|
User user = UserManager.getInstance().createUser(userName, host);
|
||||||
boolean reconnect = false;
|
boolean reconnect = false;
|
||||||
if (user == null) { // user already exists
|
if (user == null) { // user already exists
|
||||||
|
|
|
@ -70,10 +70,10 @@ public class SessionManager {
|
||||||
sessions.put(sessionId, session);
|
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);
|
Session session = sessions.get(sessionId);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
String returnMessage = session.registerUser(userName);
|
String returnMessage = session.registerUser(userName, password);
|
||||||
if (returnMessage == null) {
|
if (returnMessage == null) {
|
||||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);
|
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue