3030import org .apache .log4j .xml .DOMConfigurator ;
3131
3232import com .cloud .consoleproxy .util .Logger ;
33+ import com .google .gson .Gson ;
3334import com .sun .net .httpserver .HttpServer ;
3435
3536/**
@@ -171,9 +172,17 @@ public static ConsoleProxyServerFactory getHttpServerFactory() {
171172 }
172173 }
173174
174- public static boolean authenticateConsoleAccess (ConsoleProxyClientParam param ) {
175- if (standaloneStart )
176- return true ;
175+ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess (ConsoleProxyClientParam param , boolean reauthentication ) {
176+
177+ ConsoleProxyAuthenticationResult authResult = new ConsoleProxyAuthenticationResult ();
178+ authResult .setSuccess (true );
179+ authResult .setReauthentication (reauthentication );
180+ authResult .setHost (param .getClientHostAddress ());
181+ authResult .setPort (param .getClientHostPort ());
182+
183+ if (standaloneStart ) {
184+ return authResult ;
185+ }
177186
178187 if (authMethod != null ) {
179188 Object result ;
@@ -183,26 +192,29 @@ public static boolean authenticateConsoleAccess(ConsoleProxyClientParam param) {
183192 String .valueOf (param .getClientHostPort ()),
184193 param .getClientTag (),
185194 param .getClientHostPassword (),
186- param .getTicket ());
195+ param .getTicket (),
196+ new Boolean (reauthentication ));
187197 } catch (IllegalAccessException e ) {
188198 s_logger .error ("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + param .getClientTag (), e );
189- return false ;
199+ authResult .setSuccess (false );
200+ return authResult ;
190201 } catch (InvocationTargetException e ) {
191202 s_logger .error ("Unable to invoke authenticateConsoleAccess due to InvocationTargetException " + " for vm: " + param .getClientTag (), e );
192- return false ;
203+ authResult .setSuccess (false );
204+ return authResult ;
193205 }
194206
195- if (result != null && result instanceof Boolean ) {
196- return (( Boolean )result ). booleanValue ( );
207+ if (result != null && result instanceof String ) {
208+ authResult = new Gson (). fromJson (( String )result , ConsoleProxyAuthenticationResult . class );
197209 } else {
198210 s_logger .error ("Invalid authentication return object " + result + " for vm: " + param .getClientTag () + ", decline the access" );
199- return false ;
211+ authResult . setSuccess ( false ) ;
200212 }
201-
202213 } else {
203214 s_logger .warn ("Private channel towards management server is not setup. Switch to offline mode and allow access to vm: " + param .getClientTag ());
204- return true ;
205- }
215+ }
216+
217+ return authResult ;
206218 }
207219
208220 public static void reportLoadInfo (String gsonLoadInfo ) {
@@ -250,7 +262,7 @@ public static void startWithContext(Properties conf, Object context, byte[] ksBi
250262 ConsoleProxy .ksPassword = ksPassword ;
251263 try {
252264 Class <?> contextClazz = Class .forName ("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource" );
253- authMethod = contextClazz .getDeclaredMethod ("authenticateConsoleAccess" , String .class , String .class , String .class , String .class , String .class );
265+ authMethod = contextClazz .getDeclaredMethod ("authenticateConsoleAccess" , String .class , String .class , String .class , String .class , String .class , Boolean . class );
254266 reportMethod = contextClazz .getDeclaredMethod ("reportLoadInfo" , String .class );
255267 ensureRouteMethod = contextClazz .getDeclaredMethod ("ensureRoute" , String .class );
256268 } catch (SecurityException e ) {
@@ -454,14 +466,20 @@ public static ConsoleProxyClientStatsCollector getStatsCollector() {
454466 return new ConsoleProxyClientStatsCollector (connectionMap );
455467 }
456468
457- public static void authenticationExternally (ConsoleProxyClientParam param ) throws AuthenticationException {
458- if (!authenticateConsoleAccess (param )) {
469+ public static void authenticationExternally (ConsoleProxyClientParam param ) throws AuthenticationException {
470+ ConsoleProxyAuthenticationResult authResult = authenticateConsoleAccess (param , false );
471+
472+ if (authResult == null || !authResult .isSuccess ()) {
459473 s_logger .warn ("External authenticator failed authencation request for vm " + param .getClientTag () + " with sid " + param .getClientHostPassword ());
460474
461475 throw new AuthenticationException ("External authenticator failed request for vm " + param .getClientTag () + " with sid " + param .getClientHostPassword ());
462476 }
463477 }
464478
479+ public static ConsoleProxyAuthenticationResult reAuthenticationExternally (ConsoleProxyClientParam param ) {
480+ return authenticateConsoleAccess (param , true );
481+ }
482+
465483 public static String getEncryptorPassword () {
466484 return encryptorPassword ;
467485 }
0 commit comments