Skip to content

Commit d76207a

Browse files
author
Kelven Yang
committed
Add support for Xen Secure-Console Intergration in console proxy
1 parent 12ec170 commit d76207a

10 files changed

Lines changed: 402 additions & 49 deletions

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxy.java‎

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -151,31 +151,36 @@ public static ConsoleProxyServerFactory getHttpServerFactory() {
151151
}
152152
}
153153

154-
public static boolean authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket) {
154+
public static boolean authenticateConsoleAccess(ConsoleProxyClientParam param) {
155155
if(standaloneStart)
156156
return true;
157157

158158
if(authMethod != null) {
159159
Object result;
160160
try {
161-
result = authMethod.invoke(ConsoleProxy.context, host, port, vmId, sid, ticket);
161+
result = authMethod.invoke(ConsoleProxy.context,
162+
param.getClientHostAddress(),
163+
String.valueOf(param.getClientHostPort()),
164+
param.getClientTag(),
165+
param.getClientHostPassword(),
166+
param.getTicket());
162167
} catch (IllegalAccessException e) {
163-
s_logger.error("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + vmId, e);
168+
s_logger.error("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + param.getClientTag(), e);
164169
return false;
165170
} catch (InvocationTargetException e) {
166-
s_logger.error("Unable to invoke authenticateConsoleAccess due to InvocationTargetException " + " for vm: " + vmId, e);
171+
s_logger.error("Unable to invoke authenticateConsoleAccess due to InvocationTargetException " + " for vm: " + param.getClientTag(), e);
167172
return false;
168173
}
169174

170175
if(result != null && result instanceof Boolean) {
171176
return ((Boolean)result).booleanValue();
172177
} else {
173-
s_logger.error("Invalid authentication return object " + result + " for vm: " + vmId + ", decline the access");
178+
s_logger.error("Invalid authentication return object " + result + " for vm: " + param.getClientTag() + ", decline the access");
174179
return false;
175180
}
176181

177182
} else {
178-
s_logger.warn("Private channel towards management server is not setup. Switch to offline mode and allow access to vm: " + vmId);
183+
s_logger.warn("Private channel towards management server is not setup. Switch to offline mode and allow access to vm: " + param.getClientTag());
179184
return true;
180185
}
181186
}
@@ -343,29 +348,29 @@ public static void main(String[] argv) {
343348
start(conf);
344349
}
345350

346-
public static ConsoleProxyClient getVncViewer(String host, int port, String sid, String tag, String ticket) throws Exception {
351+
public static ConsoleProxyClient getVncViewer(ConsoleProxyClientParam param) throws Exception {
347352
ConsoleProxyClient viewer = null;
348353

349-
boolean reportLoadChange = false;
354+
boolean reportLoadChange = false;
355+
String clientKey = param.getClientMapKey();
350356
synchronized (connectionMap) {
351-
viewer = connectionMap.get(host + ":" + port);
357+
viewer = connectionMap.get(clientKey);
352358
if (viewer == null) {
353359
viewer = new ConsoleProxyVncClient();
354-
viewer.initClient(host, port, sid, tag, ticket);
355-
connectionMap.put(host + ":" + port, viewer);
360+
viewer.initClient(param);
361+
connectionMap.put(clientKey, viewer);
356362
s_logger.info("Added viewer object " + viewer);
357363

358364
reportLoadChange = true;
359365
} else if (!viewer.isFrontEndAlive()) {
360-
s_logger.info("The rfb thread died, reinitializing the viewer " +
361-
viewer);
362-
viewer.initClient(host, port, sid, tag, ticket);
366+
s_logger.info("The rfb thread died, reinitializing the viewer " + viewer);
367+
viewer.initClient(param);
363368

364369
reportLoadChange = true;
365-
} else if (!sid.equals(viewer.getClientHostPassword())) {
370+
} else if (!param.getClientHostPassword().equals(viewer.getClientHostPassword())) {
366371
s_logger.warn("Bad sid detected(VNC port may be reused). sid in session: " + viewer.getClientHostPassword()
367-
+ ", sid in request: " + sid);
368-
viewer.initClient(host, port, sid, tag, ticket);
372+
+ ", sid in request: " + param.getClientHostPassword());
373+
viewer.initClient(param);
369374

370375
reportLoadChange = true;
371376
}
@@ -382,32 +387,32 @@ public static ConsoleProxyClient getVncViewer(String host, int port, String sid,
382387
return viewer;
383388
}
384389

385-
public static ConsoleProxyClient getAjaxVncViewer(String host, int port, String sid, String tag,
386-
String ticket, String ajaxSession) throws Exception {
390+
public static ConsoleProxyClient getAjaxVncViewer(ConsoleProxyClientParam param, String ajaxSession) throws Exception {
387391

388392
boolean reportLoadChange = false;
393+
String clientKey = param.getClientMapKey();
389394
synchronized (connectionMap) {
390-
ConsoleProxyClient viewer = connectionMap.get(host + ":" + port);
395+
ConsoleProxyClient viewer = connectionMap.get(clientKey);
391396
if (viewer == null) {
392397
viewer = new ConsoleProxyVncClient();
393-
viewer.initClient(host, port, sid, tag, ticket);
398+
viewer.initClient(param);
394399

395-
connectionMap.put(host + ":" + port, viewer);
400+
connectionMap.put(clientKey, viewer);
396401
s_logger.info("Added viewer object " + viewer);
397402
reportLoadChange = true;
398403
} else if (!viewer.isFrontEndAlive()) {
399404
s_logger.info("The rfb thread died, reinitializing the viewer " +
400405
viewer);
401-
viewer.initClient(host, port, sid, tag, ticket);
406+
viewer.initClient(param);
402407
reportLoadChange = true;
403-
} else if (!sid.equals(viewer.getClientHostPassword())) {
408+
} else if (!param.getClientHostPassword().equals(viewer.getClientHostPassword())) {
404409
s_logger.warn("Bad sid detected(VNC port may be reused). sid in session: "
405-
+ viewer.getClientHostPassword() + ", sid in request: " + sid);
406-
viewer.initClient(host, port, sid, tag, ticket);
410+
+ viewer.getClientHostPassword() + ", sid in request: " + param.getClientHostPassword());
411+
viewer.initClient(param);
407412
reportLoadChange = true;
408413
} else {
409414
if(ajaxSession == null || ajaxSession.isEmpty())
410-
authenticationExternally(host, String.valueOf(port), tag, sid, ticket);
415+
authenticationExternally(param);
411416
}
412417

413418
if(reportLoadChange) {
@@ -436,11 +441,11 @@ public static ConsoleProxyClientStatsCollector getStatsCollector() {
436441
return new ConsoleProxyClientStatsCollector(connectionMap);
437442
}
438443

439-
public static void authenticationExternally(String host, String port, String tag, String sid, String ticket) throws AuthenticationException {
440-
if(!authenticateConsoleAccess(host, port, tag, sid, ticket)) {
441-
s_logger.warn("External authenticator failed authencation request for vm " + tag + " with sid " + sid);
444+
public static void authenticationExternally(ConsoleProxyClientParam param) throws AuthenticationException {
445+
if(!authenticateConsoleAccess(param)) {
446+
s_logger.warn("External authenticator failed authencation request for vm " + param.getClientTag() + " with sid " + param.getClientHostPassword());
442447

443-
throw new AuthenticationException("External authenticator failed request for vm " + tag + " with sid " + sid);
448+
throw new AuthenticationException("External authenticator failed request for vm " + param.getClientTag() + " with sid " + param.getClientHostPassword());
444449
}
445450
}
446451

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
109109
}
110110

111111
ConsoleProxyClient viewer = null;
112-
try {
113-
viewer = ConsoleProxy.getAjaxVncViewer(host, port, sid, tag, ticket, ajaxSessionIdStr);
112+
try {
113+
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
114+
param.setClientHostAddress(host);
115+
param.setClientHostPort(port);
116+
param.setClientHostPassword(sid);
117+
param.setClientTag(tag);
118+
param.setTicket(ticket);
119+
120+
viewer = ConsoleProxy.getAjaxVncViewer(param, ajaxSessionIdStr);
114121
} catch(Exception e) {
115122

116123
s_logger.warn("Failed to create viewer due to " + e.getMessage(), e);

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
8484
s_logger.warn("Invalid numeric parameter in query string: " + keyStr);
8585
throw new IllegalArgumentException(e);
8686
}
87-
88-
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(host, port, sid, tag, ticket);
87+
88+
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
89+
param.setClientHostAddress(host);
90+
param.setClientHostPort(port);
91+
param.setClientHostPassword(sid);
92+
param.setClientTag(tag);
93+
param.setTicket(ticket);
94+
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
8995
byte[] img = viewer.getAjaxImageCache().getImage(key);
9096
if(img != null) {
9197
Headers hds = t.getResponseHeaders();

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClient.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public interface ConsoleProxyClient {
6161
//
6262
// Setup/house-keeping
6363
//
64-
void initClient(String clientHostAddress, int clientHostPort,
65-
String clientHostPassword, String clientTag, String ticket);
64+
void initClient(ConsoleProxyClientParam param);
6665
void closeClient();
6766
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public String getClientTag() {
124124
}
125125

126126
@Override
127-
public abstract void initClient(String clientHostAddress, int clientHostPort,
128-
String clientHostPassword, String clientTag, String ticket);
127+
public abstract void initClient(ConsoleProxyClientParam param);
129128

130129
@Override
131130
public abstract void closeClient();
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package com.cloud.consoleproxy;
14+
15+
/**
16+
*
17+
* @author Kelven Yang
18+
* Data object to store parameter info needed by client to connect to its host
19+
*/
20+
public class ConsoleProxyClientParam {
21+
22+
private String clientHostAddress;
23+
private int clientHostPort;
24+
private String clientHostPassword;
25+
private String clientTag;
26+
private String ticket;
27+
28+
public ConsoleProxyClientParam() {
29+
clientHostPort = 0;
30+
}
31+
32+
public String getClientHostAddress() {
33+
return clientHostAddress;
34+
}
35+
36+
public void setClientHostAddress(String clientHostAddress) {
37+
this.clientHostAddress = clientHostAddress;
38+
}
39+
40+
public int getClientHostPort() {
41+
return clientHostPort;
42+
}
43+
44+
public void setClientHostPort(int clientHostPort) {
45+
this.clientHostPort = clientHostPort;
46+
}
47+
48+
public String getClientHostPassword() {
49+
return clientHostPassword;
50+
}
51+
52+
public void setClientHostPassword(String clientHostPassword) {
53+
this.clientHostPassword = clientHostPassword;
54+
}
55+
56+
public String getClientTag() {
57+
return clientTag;
58+
}
59+
60+
public void setClientTag(String clientTag) {
61+
this.clientTag = clientTag;
62+
}
63+
64+
public String getTicket() {
65+
return ticket;
66+
}
67+
68+
public void setTicket(String ticket) {
69+
this.ticket = ticket;
70+
}
71+
72+
public String getClientMapKey() {
73+
return clientHostAddress + ":" + clientHostPort;
74+
}
75+
}

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyThumbnailHandler.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
120120
} catch (NumberFormatException e) {
121121
throw new IllegalArgumentException(e);
122122
}
123-
124-
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(host, port, sid, tag, ticket);
123+
124+
ConsoleProxyClientParam param = new ConsoleProxyClientParam();
125+
param.setClientHostAddress(host);
126+
param.setClientHostPort(port);
127+
param.setClientHostPassword(sid);
128+
param.setClientTag(tag);
129+
param.setTicket(ticket);
130+
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
125131

126132
if (!viewer.isHostConnected()) {
127133
// use generated image instead of static

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,20 @@ public boolean isFrontEndAlive() {
5252
}
5353

5454
@Override
55-
public void initClient(final String clientHostAddress, final int clientHostPort,
56-
final String clientHostPassword, final String clientTag, final String ticket) {
57-
this.host = clientHostAddress;
58-
this.port = clientHostPort;
59-
this.passwordParam = clientHostPassword;
60-
this.tag = clientTag;
61-
this.ticket = ticket;
55+
public void initClient(ConsoleProxyClientParam param) {
56+
this.host = param.getClientHostAddress();
57+
this.port = param.getClientHostPort();
58+
this.passwordParam = param.getClientHostPassword();
59+
this.tag = param.getClientTag();
60+
this.ticket = param.getTicket();
6261

6362
client = new VncClient(this);
6463
worker = new Thread(new Runnable() {
6564
public void run() {
6665
long startTick = System.currentTimeMillis();
6766
while(System.currentTimeMillis() - startTick < 7000) {
6867
try {
69-
client.connectTo(clientHostAddress, clientHostPort, clientHostPassword);
68+
client.connectTo(host, port, passwordParam);
7069
} catch (UnknownHostException e) {
7170
s_logger.error("Unexpected exception: ", e);
7271
} catch (IOException e) {

0 commit comments

Comments
 (0)