GUACAMOLE-393: Add AuthenticationProvider shutdown hook.

This commit is contained in:
Michael Jumper
2017-05-29 21:21:48 -07:00
parent 45adf2fd93
commit 2c587e5f9f
9 changed files with 67 additions and 1 deletions

View File

@@ -107,4 +107,9 @@ public class CASAuthenticationProvider implements AuthenticationProvider {
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -102,4 +102,9 @@ public class DuoAuthenticationProvider implements AuthenticationProvider {
return context; return context;
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -107,4 +107,9 @@ public class HTTPHeaderAuthenticationProvider implements AuthenticationProvider
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -104,4 +104,9 @@ public abstract class InjectedAuthenticationProvider implements AuthenticationPr
authenticatedUser, credentials); authenticatedUser, credentials);
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -103,5 +103,10 @@ public class LDAPAuthenticationProvider implements AuthenticationProvider {
return context; return context;
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -168,4 +168,11 @@ public interface AuthenticationProvider {
AuthenticatedUser authenticatedUser, AuthenticatedUser authenticatedUser,
Credentials credentials) throws GuacamoleException; Credentials credentials) throws GuacamoleException;
/**
* Frees all resources associated with this AuthenticationProvider. This
* function will be automatically invoked when the Guacamole server is
* shutting down.
*/
void shutdown();
} }

View File

@@ -260,4 +260,9 @@ public abstract class SimpleAuthenticationProvider
} }
@Override
public void shutdown() {
// Do nothing
}
} }

View File

@@ -21,14 +21,17 @@ package org.apache.guacamole;
import org.apache.guacamole.tunnel.TunnelModule; import org.apache.guacamole.tunnel.TunnelModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Stage; import com.google.inject.Stage;
import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.servlet.GuiceServletContextListener;
import java.util.List;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import org.apache.guacamole.environment.Environment; import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.environment.LocalEnvironment; import org.apache.guacamole.environment.LocalEnvironment;
import org.apache.guacamole.extension.ExtensionModule; import org.apache.guacamole.extension.ExtensionModule;
import org.apache.guacamole.log.LogModule; import org.apache.guacamole.log.LogModule;
import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.rest.RESTServiceModule; import org.apache.guacamole.rest.RESTServiceModule;
import org.apache.guacamole.rest.auth.HashTokenSessionMap; import org.apache.guacamole.rest.auth.HashTokenSessionMap;
import org.apache.guacamole.rest.auth.TokenSessionMap; import org.apache.guacamole.rest.auth.TokenSessionMap;
@@ -56,6 +59,12 @@ public class GuacamoleServletContextListener extends GuiceServletContextListener
*/ */
private TokenSessionMap sessionMap; private TokenSessionMap sessionMap;
/**
* List of all authentication providers from all loaded extensions.
*/
@Inject
private List<AuthenticationProvider> authProviders;
@Override @Override
public void contextInitialized(ServletContextEvent servletContextEvent) { public void contextInitialized(ServletContextEvent servletContextEvent) {
@@ -75,13 +84,21 @@ public class GuacamoleServletContextListener extends GuiceServletContextListener
@Override @Override
protected Injector getInjector() { protected Injector getInjector() {
return Guice.createInjector(Stage.PRODUCTION,
// Create injector
Injector injector = Guice.createInjector(Stage.PRODUCTION,
new EnvironmentModule(environment), new EnvironmentModule(environment),
new LogModule(environment), new LogModule(environment),
new ExtensionModule(environment), new ExtensionModule(environment),
new RESTServiceModule(sessionMap), new RESTServiceModule(sessionMap),
new TunnelModule() new TunnelModule()
); );
// Inject any annotated members of this class
injector.injectMembers(this);
return injector;
} }
@Override @Override
@@ -93,6 +110,12 @@ public class GuacamoleServletContextListener extends GuiceServletContextListener
if (sessionMap != null) if (sessionMap != null)
sessionMap.shutdown(); sessionMap.shutdown();
// Unload all extensions
if (authProviders != null) {
for (AuthenticationProvider authProvider : authProviders)
authProvider.shutdown();
}
} }
} }

View File

@@ -209,4 +209,10 @@ public class AuthenticationProviderFacade implements AuthenticationProvider {
} }
@Override
public void shutdown() {
if (authProvider != null)
authProvider.shutdown();
}
} }