GUACAMOLE-393: Merge add extension logout/shutdown hooks

This commit is contained in:
Nick Couchman
2017-09-25 15:12:45 -04:00
18 changed files with 118 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

@@ -204,4 +204,9 @@ public class SharedUserContext implements UserContext {
return Collections.<Form>emptyList(); return Collections.<Form>emptyList();
} }
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

View File

@@ -191,4 +191,9 @@ public class ModeledUserContext extends RestrictedObject
return ModeledSharingProfile.ATTRIBUTES; return ModeledSharingProfile.ATTRIBUTES;
} }
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

View File

@@ -136,4 +136,9 @@ public abstract class RemoteAuthenticatedUser implements AuthenticatedUser {
return authenticationProvider; return authenticationProvider;
} }
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

View File

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

View File

@@ -229,4 +229,9 @@ public class UserContext implements org.apache.guacamole.net.auth.UserContext {
return Collections.<Form>emptyList(); return Collections.<Form>emptyList();
} }
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

View File

@@ -29,4 +29,9 @@ public abstract class AbstractAuthenticatedUser extends AbstractIdentifiable
// Prior functionality now resides within AbstractIdentifiable // Prior functionality now resides within AbstractIdentifiable
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

View File

@@ -49,4 +49,11 @@ public interface AuthenticatedUser extends Identifiable {
*/ */
Credentials getCredentials(); Credentials getCredentials();
/**
* Invalidates this authenticated user and their associated token such that
* they are no longer logged in. This function will be automatically
* invoked when the user logs out, or when their session expires.
*/
void invalidate();
} }

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

@@ -212,4 +212,11 @@ public interface UserContext {
*/ */
Collection<Form> getSharingProfileAttributes(); Collection<Form> getSharingProfileAttributes();
/**
* Invalidates this user context, releasing all associated resources. This
* function will be invoked when the user logs out, or when their session
* is automatically invalidated.
*/
void invalidate();
} }

View File

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

View File

@@ -234,4 +234,9 @@ public class SimpleUserContext implements UserContext {
return Collections.<Form>emptyList(); return Collections.<Form>emptyList();
} }
@Override
public void invalidate() {
// Nothing to invalidate
}
} }

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

@@ -252,6 +252,13 @@ public class GuacamoleSession {
} }
} }
// Invalidate all user contextx
for (UserContext userContext : userContexts)
userContext.invalidate();
// Invalidate the authenticated user object
authenticatedUser.invalidate();
} }
} }

View File

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