@@ -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
0 commit comments