Skip to content

Commit 5f95f77

Browse files
committed
change for one-time ticket as password
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent e46f5cc commit 5f95f77

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

core/src/main/java/com/cloud/agent/api/GetExternalConsoleAnswer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ public class GetExternalConsoleAnswer extends Answer {
2525
@LogLevel(LogLevel.Log4jLevel.Off)
2626
private String password;
2727
private String protocol;
28+
private boolean passwordOneTimeUseOnly;
2829

2930
public GetExternalConsoleAnswer(Command command, String details) {
3031
super(command, false, details);
3132
}
3233

33-
public GetExternalConsoleAnswer(Command command, String url, String host, Integer port, String password, String protocol) {
34+
public GetExternalConsoleAnswer(Command command, String url, String host, Integer port, String password,
35+
boolean passwordOneTimeUseOnly, String protocol) {
3436
super(command, true, "");
3537
this.url = url;
3638
this.host = host;
3739
this.port = port;
3840
this.password = password;
41+
this.passwordOneTimeUseOnly = passwordOneTimeUseOnly;
3942
this.protocol = protocol;
4043
}
4144

@@ -58,4 +61,8 @@ public String getPassword() {
5861
public String getProtocol() {
5962
return protocol;
6063
}
64+
65+
public boolean isPasswordOneTimeUseOnly() {
66+
return passwordOneTimeUseOnly;
67+
}
6168
}

extensions/Proxmox/proxmox.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,15 @@ get_node_host() {
356356
--arg host "$host" \
357357
--arg port "$port" \
358358
--arg password "$ticket" \
359+
--argjson passwordonetimeuseonly true \
359360
'{
360361
status: "success",
361362
message: "Console retrieved",
362363
console: {
363364
host: $host,
364365
port: $port,
365366
password: $password,
367+
passwordonetimeuseonly: $passwordonetimeuseonly,
366368
protocol: "vnc"
367369
}
368370
}'

plugins/hypervisors/external/src/main/java/org/apache/cloudstack/hypervisor/external/provisioner/ExternalPathPayloadProvisioner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,15 @@ public GetExternalConsoleAnswer getInstanceConsole(String hostName, String exten
510510
String host = consoleObj.has("host") ? consoleObj.get("host").getAsString() : null;
511511
Integer port = consoleObj.has("port") ? Integer.valueOf(consoleObj.get("port").getAsString()) : null;
512512
String password = consoleObj.has("password") ? consoleObj.get("password").getAsString() : null;
513+
boolean passwordOneTimeUseOnly = consoleObj.has("passwordonetimeuseonly") &&
514+
consoleObj.get("passwordonetimeuseonly").getAsBoolean();
513515
String protocol = consoleObj.has("protocol") ? consoleObj.get("protocol").getAsString() : null;
514516
if (url == null && ObjectUtils.anyNull(host, port)) {
515517
logger.error("Missing required fields in external console output: {}",
516518
getSanitizedJsonStringForLog(output));
517519
return new GetExternalConsoleAnswer(cmd, "Missing required fields in output");
518520
}
519-
return new GetExternalConsoleAnswer(cmd, url, host, port, password, protocol);
521+
return new GetExternalConsoleAnswer(cmd, url, host, port, password, passwordOneTimeUseOnly, protocol);
520522
} catch (RuntimeException e) {
521523
logger.error("Failed to parse output for getInstanceConsole: {}", e.getMessage(), e);
522524
return new GetExternalConsoleAnswer(cmd, "Failed to parse output");

server/src/main/java/com/cloud/servlet/ConsoleProxyClientParam.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class ConsoleProxyClientParam {
3434
private String username;
3535
private String password;
3636

37+
private boolean sessionRequiresNewViewer = false;
38+
3739
/**
3840
* IP that has generated the console endpoint
3941
*/
@@ -218,4 +220,8 @@ public String getClientIp() {
218220
public void setClientIp(String clientIp) {
219221
this.clientIp = clientIp;
220222
}
223+
224+
public void setSessionRequiresNewViewer(boolean sessionRequiresNewViewer) {
225+
this.sessionRequiresNewViewer = sessionRequiresNewViewer;
226+
}
221227
}

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ protected ConsoleConnectionDetails getConsoleConnectionDetailsForExternalVm(Cons
449449
}
450450
if (StringUtils.isNotBlank(getExternalConsoleAnswer.getPassword())) {
451451
details.setSid(getExternalConsoleAnswer.getPassword());
452+
details.setSessionRequiresNewViewer(getExternalConsoleAnswer.isPasswordOneTimeUseOnly());
452453
}
453454
return details;
454455
}
@@ -600,6 +601,7 @@ protected ConsoleProxyClientParam generateConsoleProxyClientParam(ConsoleConnect
600601
param.setTicket(ticket);
601602
param.setSessionUuid(sessionUuid);
602603
param.setSourceIP(addr);
604+
param.setSessionRequiresNewViewer(details.isSessionRequiresNewViewer());
603605

604606
if (StringUtils.isNotBlank(extraSecurityToken)) {
605607
param.setExtraSecurityToken(extraSecurityToken);
@@ -761,6 +763,7 @@ public enum Mode {
761763
private String tunnelSession = null;
762764
private boolean usingRDP;
763765
private String directUrl;
766+
private boolean sessionRequiresNewViewer = false;
764767

765768
ConsoleConnectionDetails(String sid, String locale, String tag, String displayName) {
766769
this.sid = sid;
@@ -850,5 +853,13 @@ public String getDirectUrl() {
850853
public void setDirectUrl(String directUrl) {
851854
this.directUrl = directUrl;
852855
}
856+
857+
public boolean isSessionRequiresNewViewer() {
858+
return sessionRequiresNewViewer;
859+
}
860+
861+
public void setSessionRequiresNewViewer(boolean sessionRequiresNewViewer) {
862+
this.sessionRequiresNewViewer = sessionRequiresNewViewer;
863+
}
853864
}
854865
}

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyClientParam.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.consoleproxy;
1818

19+
import org.apache.commons.lang3.StringUtils;
20+
1921
/**
2022
*
2123
* Data object to store parameter info needed by client to connect to its host
@@ -39,6 +41,8 @@ public class ConsoleProxyClientParam {
3941
private String password;
4042
private String websocketUrl;
4143

44+
private boolean sessionRequiresNewViewer;
45+
4246
/**
4347
* IP that has generated the console endpoint
4448
*/
@@ -143,8 +147,12 @@ public void setLocale(String locale) {
143147
}
144148

145149
public String getClientMapKey() {
146-
if (clientTag != null && !clientTag.isEmpty())
150+
if (sessionRequiresNewViewer && StringUtils.isNotBlank(sessionUuid)) {
151+
return sessionUuid;
152+
}
153+
if (StringUtils.isNotBlank(clientTag)) {
147154
return clientTag;
155+
}
148156

149157
return clientHostAddress + ":" + clientHostPort;
150158
}
@@ -220,4 +228,8 @@ public String getClientIp() {
220228
public void setClientIp(String clientIp) {
221229
this.clientIp = clientIp;
222230
}
231+
232+
public boolean isSessionRequiresNewViewer() {
233+
return sessionRequiresNewViewer;
234+
}
223235
}

0 commit comments

Comments
 (0)