解决session在重启后,内存中不存在的问题
This commit is contained in:
@@ -79,7 +79,7 @@ public class RouteAction extends Action {
|
||||
|
||||
MemorySessionStore.Session session = sessionsStore.sessionForClientAndUser(uid, cid);
|
||||
if (session == null) {
|
||||
ErrorCode errorCode = sessionsStore.createNewSession(uid, cid, true);
|
||||
ErrorCode errorCode = sessionsStore.createNewSession(uid, cid, true, true);
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
sendResponse(response, errorCode, null, base64Response);
|
||||
return true;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RouteHandler extends IMHandler<WFCMessage.RouteRequest> {
|
||||
ClientSession clientSession = m_sessionsStore.sessionForClient(clientID);
|
||||
boolean isSessionAlreadyStored = clientSession != null;
|
||||
if (!isSessionAlreadyStored) {
|
||||
m_sessionsStore.createNewSession(fromUser, clientID, true);
|
||||
m_sessionsStore.createNewSession(fromUser, clientID, true, true);
|
||||
} else {
|
||||
m_sessionsStore.updateExistSession(fromUser, clientID, request, true);
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode createNewSession(String username, String clientID, boolean cleanSession) {
|
||||
public ErrorCode createNewSession(String username, String clientID, boolean cleanSession, boolean createWhenNoExist) {
|
||||
LOG.debug("createNewSession for client <{}>", clientID);
|
||||
|
||||
Session session = sessions.get(clientID);
|
||||
@@ -296,6 +296,10 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
session = databaseStore.getSession(username, clientID, clientSession);
|
||||
|
||||
if (session == null) {
|
||||
if (!createWhenNoExist) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
session = databaseStore.createSession(username, clientID, clientSession);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public interface ISessionsStore {
|
||||
|
||||
Session createUserSession(String username, String clientID);
|
||||
|
||||
ErrorCode createNewSession(String username, String clientID, boolean cleanSession);
|
||||
ErrorCode createNewSession(String username, String clientID, boolean cleanSession, boolean createNoExist);
|
||||
|
||||
ClientSession updateExistSession(String username, String clientID, WFCMessage.RouteRequest endpoint, boolean cleanSession);
|
||||
|
||||
|
||||
@@ -251,11 +251,16 @@ public class ProtocolProcessor {
|
||||
pwd = msg.payload().password();
|
||||
|
||||
MemorySessionStore.Session session = m_sessionsStore.getSession(clientId);
|
||||
if (session == null) {
|
||||
m_sessionsStore.createNewSession(msg.payload().userName(), clientId, true, false);
|
||||
session = m_sessionsStore.getSession(clientId);
|
||||
}
|
||||
|
||||
if (session != null && session.getUsername().equals(msg.payload().userName())) {
|
||||
pwd = AES.AESDecrypt(pwd, session.getSecret(), true);
|
||||
} else {
|
||||
LOG.error("Password decrypt failed of client {}", clientId);
|
||||
failedCredentials(channel);
|
||||
failedNoSession(channel);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -365,6 +370,11 @@ public class ProtocolProcessor {
|
||||
LOG.info("Client {} failed to connect with bad username or password.", session);
|
||||
}
|
||||
|
||||
private void failedNoSession(Channel session) {
|
||||
session.writeAndFlush(connAck(CONNECTION_REFUSED_SESSION_NOT_EXIST));
|
||||
LOG.info("Client {} failed to connect with bad username or password.", session);
|
||||
}
|
||||
|
||||
private void setIdleTime(ChannelPipeline pipeline, int idleTime) {
|
||||
if (pipeline.names().contains("idleStateHandler")) {
|
||||
pipeline.remove("idleStateHandler");
|
||||
|
||||
Reference in New Issue
Block a user