Transfer password.

This commit is contained in:
Me Car 2016-01-05 02:40:05 +09:00
parent 33330e9345
commit d0ea7d9c37
6 changed files with 24 additions and 14 deletions

View file

@ -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);

View file

@ -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

View file

@ -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);