GUACAMOLE-412: Refactor user events with respect to extension API changes since the decoupling of auth from storage, providing AuthenticatedUser instead of UserContext to represent the user involved.

This commit is contained in:
Michael Jumper
2017-10-27 13:03:17 -07:00
parent 51ccbed130
commit 223102c38c
6 changed files with 86 additions and 85 deletions

View File

@@ -224,24 +224,12 @@ public class AuthenticationService {
* @param authenticatedUser
* The user that was successfully authenticated.
*
* @param session
* The existing session for the user (if any).
*
* @throws GuacamoleException
* If thrown by a listener.
*/
private void fireAuthenticationSuccessEvent(
AuthenticatedUser authenticatedUser, GuacamoleSession session)
private void fireAuthenticationSuccessEvent(AuthenticatedUser authenticatedUser)
throws GuacamoleException {
UserContext userContext = null;
if (session != null) {
userContext = session.getUserContext(
authenticatedUser.getAuthenticationProvider().getIdentifier());
}
listenerService.handleEvent(new AuthenticationSuccessEvent(
userContext, authenticatedUser.getCredentials()));
listenerService.handleEvent(new AuthenticationSuccessEvent(authenticatedUser));
}
/**
@@ -286,13 +274,13 @@ public class AuthenticationService {
if (existingSession != null) {
AuthenticatedUser updatedUser = updateAuthenticatedUser(
existingSession.getAuthenticatedUser(), credentials);
fireAuthenticationSuccessEvent(updatedUser, existingSession);
fireAuthenticationSuccessEvent(updatedUser);
return updatedUser;
}
// Otherwise, attempt authentication as a new user
AuthenticatedUser authenticatedUser = AuthenticationService.this.authenticateUser(credentials);
fireAuthenticationSuccessEvent(authenticatedUser, null);
fireAuthenticationSuccessEvent(authenticatedUser);
if (logger.isInfoEnabled())
logger.info("User \"{}\" successfully authenticated from {}.",

View File

@@ -27,6 +27,7 @@ import org.apache.guacamole.GuacamoleSecurityException;
import org.apache.guacamole.GuacamoleSession;
import org.apache.guacamole.GuacamoleUnauthorizedException;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.Connection;
import org.apache.guacamole.net.auth.ConnectionGroup;
import org.apache.guacamole.net.auth.Credentials;
@@ -71,9 +72,9 @@ public class TunnelRequestService {
* Notifies bound listeners that a new tunnel has been connected.
* Listeners may veto a connected tunnel by throwing any GuacamoleException.
*
* @param userContext
* The UserContext associated with the user for whom the tunnel is
* being created.
* @param authenticatedUser
* The AuthenticatedUser associated with the user for whom the tunnel
* is being created.
*
* @param credentials
* Credentials that authenticate the user.
@@ -84,9 +85,10 @@ public class TunnelRequestService {
* @throws GuacamoleException
* If thrown by a listener or if any listener vetoes the connected tunnel.
*/
private void fireTunnelConnectEvent(UserContext userContext,
private void fireTunnelConnectEvent(AuthenticatedUser authenticatedUser,
Credentials credentials, GuacamoleTunnel tunnel) throws GuacamoleException {
listenerService.handleEvent(new TunnelConnectEvent(userContext, credentials, tunnel));
listenerService.handleEvent(new TunnelConnectEvent(authenticatedUser,
credentials, tunnel));
}
/**
@@ -94,9 +96,9 @@ public class TunnelRequestService {
* Listeners are allowed to veto a request to close a tunnel by throwing any
* GuacamoleException.
*
* @param userContext
* The UserContext associated with the user for whom the tunnel is
* being created.
* @param authenticatedUser
* The AuthenticatedUser associated with the user for whom the tunnel
* is being closed.
*
* @param credentials
* Credentials that authenticate the user.
@@ -107,10 +109,11 @@ public class TunnelRequestService {
* @throws GuacamoleException
* If thrown by a listener.
*/
private void fireTunnelClosedEvent(UserContext userContext,
private void fireTunnelClosedEvent(AuthenticatedUser authenticatedUser,
Credentials credentials, GuacamoleTunnel tunnel)
throws GuacamoleException {
listenerService.handleEvent(new TunnelCloseEvent(userContext, credentials, tunnel));
listenerService.handleEvent(new TunnelCloseEvent(authenticatedUser,
credentials, tunnel));
}
/**
@@ -299,9 +302,10 @@ public class TunnelRequestService {
@Override
public void close() throws GuacamoleException {
// notify listeners to allow close request to be vetoed
fireTunnelClosedEvent(context,
session.getAuthenticatedUser().getCredentials(), tunnel);
// Notify listeners to allow close request to be vetoed
AuthenticatedUser authenticatedUser = session.getAuthenticatedUser();
fireTunnelClosedEvent(authenticatedUser,
authenticatedUser.getCredentials(), tunnel);
long connectionEndTime = System.currentTimeMillis();
long duration = connectionEndTime - connectionStartTime;
@@ -389,7 +393,7 @@ public class TunnelRequestService {
GuacamoleTunnel tunnel = createConnectedTunnel(userContext, type, id, info);
// Notify listeners to allow connection to be vetoed
fireTunnelConnectEvent(userContext,
fireTunnelConnectEvent(session.getAuthenticatedUser(),
session.getAuthenticatedUser().getCredentials(), tunnel);
// Associate tunnel with session