mirror of https://github.com/apache/cloudstack.git
novnc: Accept new novnc client and disconnect old session (#4531)
* novnc: Reject new novnc client if novnc viewer object is still alive * #4531 novnc: Accept new novnc client and disconnect old session
This commit is contained in:
parent
0a401eb92d
commit
cdc3b08759
|
|
@ -551,11 +551,23 @@ public class ConsoleProxy {
|
|||
!param.getClientHostPassword().equals(viewer.getClientHostPassword()))
|
||||
throw new AuthenticationException("Cannot use the existing viewer " + viewer + ": bad sid");
|
||||
|
||||
if (!viewer.isFrontEndAlive()) {
|
||||
try {
|
||||
authenticationExternally(param);
|
||||
viewer.initClient(param);
|
||||
reportLoadChange = true;
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Authencation failed for param: " + param);
|
||||
return null;
|
||||
}
|
||||
s_logger.info("Initializing new novnc client and disconnecting existing session");
|
||||
try {
|
||||
((ConsoleProxyNoVncClient)viewer).getSession().disconnect();
|
||||
} catch (IOException e) {
|
||||
s_logger.error("Exception while disconnect session of novnc viewer object: " + viewer, e);
|
||||
}
|
||||
removeViewer(viewer);
|
||||
viewer = new ConsoleProxyNoVncClient(session);
|
||||
viewer.initClient(param);
|
||||
connectionMap.put(clientKey, viewer);
|
||||
reportLoadChange = true;
|
||||
}
|
||||
|
||||
if (reportLoadChange) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
|||
@WebSocket
|
||||
public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
|
||||
|
||||
private ConsoleProxyNoVncClient viewer;
|
||||
private ConsoleProxyNoVncClient viewer = null;
|
||||
private static final Logger s_logger = Logger.getLogger(ConsoleProxyNoVNCHandler.class);
|
||||
|
||||
public ConsoleProxyNoVNCHandler() {
|
||||
|
|
@ -130,12 +130,18 @@ public class ConsoleProxyNoVNCHandler extends WebSocketHandler {
|
|||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to create viewer due to " + e.getMessage(), e);
|
||||
return;
|
||||
} finally {
|
||||
if (viewer == null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnWebSocketClose
|
||||
public void onClose(Session session, int statusCode, String reason) throws IOException, InterruptedException {
|
||||
ConsoleProxy.removeViewer(viewer);
|
||||
if (viewer != null) {
|
||||
ConsoleProxy.removeViewer(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
@OnWebSocketFrame
|
||||
|
|
|
|||
|
|
@ -235,4 +235,8 @@ public class ConsoleProxyNoVncClient implements ConsoleProxyClient {
|
|||
return "";
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue