mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-5: Establish distinction between the AuthenticationProvider storing a user's data and the AuthenticationProvider which authenticated the user.
This commit is contained in:
@@ -63,6 +63,10 @@ public interface AuthenticationProviderService {
|
|||||||
* user. A new placeholder account will be created for any user that does
|
* user. A new placeholder account will be created for any user that does
|
||||||
* not already exist within the database.
|
* not already exist within the database.
|
||||||
*
|
*
|
||||||
|
* @param authenticationProvider
|
||||||
|
* The AuthenticationProvider on behalf of which the UserContext is
|
||||||
|
* being produced.
|
||||||
|
*
|
||||||
* @param authenticatedUser
|
* @param authenticatedUser
|
||||||
* The credentials to use to produce the UserContext.
|
* The credentials to use to produce the UserContext.
|
||||||
*
|
*
|
||||||
@@ -74,7 +78,7 @@ public interface AuthenticationProviderService {
|
|||||||
* If an error occurs during authentication, or if the given
|
* If an error occurs during authentication, or if the given
|
||||||
* credentials are invalid or expired.
|
* credentials are invalid or expired.
|
||||||
*/
|
*/
|
||||||
public UserContext getUserContext(AuthenticatedUser authenticatedUser)
|
public UserContext getUserContext(AuthenticationProvider authenticationProvider,
|
||||||
throws GuacamoleException;
|
AuthenticatedUser authenticatedUser) throws GuacamoleException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,7 @@ public abstract class InjectedAuthenticationProvider implements AuthenticationPr
|
|||||||
@Override
|
@Override
|
||||||
public UserContext getUserContext(AuthenticatedUser authenticatedUser)
|
public UserContext getUserContext(AuthenticatedUser authenticatedUser)
|
||||||
throws GuacamoleException {
|
throws GuacamoleException {
|
||||||
return authProviderService.getUserContext(authenticatedUser);
|
return authProviderService.getUserContext(this, authenticatedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -67,11 +67,11 @@ public class JDBCAuthenticationProviderService implements AuthenticationProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.apache.guacamole.net.auth.UserContext getUserContext(
|
public UserContext getUserContext(AuthenticationProvider authenticationProvider,
|
||||||
AuthenticatedUser authenticatedUser) throws GuacamoleException {
|
AuthenticatedUser authenticatedUser) throws GuacamoleException {
|
||||||
|
|
||||||
// Retrieve user account for already-authenticated user
|
// Retrieve user account for already-authenticated user
|
||||||
ModeledUser user = userService.retrieveUser(authenticatedUser);
|
ModeledUser user = userService.retrieveUser(authenticationProvider, authenticatedUser);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@@ -67,6 +67,7 @@ public class SharedAuthenticationProviderService implements AuthenticationProvid
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public org.apache.guacamole.net.auth.UserContext getUserContext(
|
public org.apache.guacamole.net.auth.UserContext getUserContext(
|
||||||
|
AuthenticationProvider authenticationProvider,
|
||||||
AuthenticatedUser authenticatedUser) throws GuacamoleException {
|
AuthenticatedUser authenticatedUser) throws GuacamoleException {
|
||||||
|
|
||||||
// Produce sharing-specific user context if this is the user of a shared connection
|
// Produce sharing-specific user context if this is the user of a shared connection
|
||||||
|
@@ -33,10 +33,17 @@ import org.apache.guacamole.net.auth.Credentials;
|
|||||||
public class AuthenticatedUser extends RemoteAuthenticatedUser {
|
public class AuthenticatedUser extends RemoteAuthenticatedUser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user that authenticated.
|
* The ModeledUser object which is backed by the data associated with this
|
||||||
|
* user in the database.
|
||||||
*/
|
*/
|
||||||
private final ModeledUser user;
|
private final ModeledUser user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AuthenticationProvider that is associated with this user's
|
||||||
|
* corresponding ModeledUser.
|
||||||
|
*/
|
||||||
|
private final AuthenticationProvider modelAuthenticationProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The connections which have been committed for use by this user in the
|
* The connections which have been committed for use by this user in the
|
||||||
* context of a balancing connection group. Balancing connection groups
|
* context of a balancing connection group. Balancing connection groups
|
||||||
@@ -48,15 +55,42 @@ public class AuthenticatedUser extends RemoteAuthenticatedUser {
|
|||||||
private final Set<String> preferredConnections =
|
private final Set<String> preferredConnections =
|
||||||
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a copy of the given AuthenticatedUser which is associated with
|
||||||
|
* the data stored in the provided ModeledUser. The AuthenticatedUser need
|
||||||
|
* not have come from the same AuthenticationProvider which produced the
|
||||||
|
* given ModeledUser.
|
||||||
|
*
|
||||||
|
* @param authenticatedUser
|
||||||
|
* An existing AuthenticatedUser representing the user that
|
||||||
|
* authenticated.
|
||||||
|
*
|
||||||
|
* @param modelAuthenticationProvider
|
||||||
|
* The AuthenticationProvider that is associated with the given user's
|
||||||
|
* corresponding ModeledUser.
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* A ModeledUser object which is backed by the data associated with
|
||||||
|
* this user in the database.
|
||||||
|
*/
|
||||||
|
public AuthenticatedUser(org.apache.guacamole.net.auth.AuthenticatedUser authenticatedUser,
|
||||||
|
AuthenticationProvider modelAuthenticationProvider, ModeledUser user) {
|
||||||
|
super(authenticatedUser.getAuthenticationProvider(), authenticatedUser.getCredentials());
|
||||||
|
this.modelAuthenticationProvider = modelAuthenticationProvider;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new AuthenticatedUser associating the given user with their
|
* Creates a new AuthenticatedUser associating the given user with their
|
||||||
* corresponding credentials.
|
* corresponding credentials.
|
||||||
*
|
*
|
||||||
* @param authenticationProvider
|
* @param authenticationProvider
|
||||||
* The AuthenticationProvider that has authenticated the given user.
|
* The AuthenticationProvider that has authenticated the given user
|
||||||
|
* and which produced the given ModeledUser.
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
* The user this object should represent.
|
* A ModeledUser object which is backed by the data associated with
|
||||||
|
* this user in the database.
|
||||||
*
|
*
|
||||||
* @param credentials
|
* @param credentials
|
||||||
* The credentials given by the user when they authenticated.
|
* The credentials given by the user when they authenticated.
|
||||||
@@ -64,19 +98,36 @@ public class AuthenticatedUser extends RemoteAuthenticatedUser {
|
|||||||
public AuthenticatedUser(AuthenticationProvider authenticationProvider,
|
public AuthenticatedUser(AuthenticationProvider authenticationProvider,
|
||||||
ModeledUser user, Credentials credentials) {
|
ModeledUser user, Credentials credentials) {
|
||||||
super(authenticationProvider, credentials);
|
super(authenticationProvider, credentials);
|
||||||
|
this.modelAuthenticationProvider = authenticationProvider;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user that authenticated.
|
* Returns a ModeledUser object which is backed by the data associated with
|
||||||
|
* this user within the database.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* The user that authenticated.
|
* A ModeledUser object which is backed by the data associated with
|
||||||
|
* this user in the database.
|
||||||
*/
|
*/
|
||||||
public ModeledUser getUser() {
|
public ModeledUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the AuthenticationProvider which produced the ModeledUser
|
||||||
|
* retrievable via getUser(). This is not necessarily the same as the
|
||||||
|
* AuthenticationProvider which authenticated that user, which can be
|
||||||
|
* retrieved with getAuthenticationProvider().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The AuthenticationProvider which produced the ModeledUser
|
||||||
|
* retrievable via getUser().
|
||||||
|
*/
|
||||||
|
public AuthenticationProvider getModelAuthenticationProvider() {
|
||||||
|
return modelAuthenticationProvider;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the connection having the given identifier has been
|
* Returns whether the connection having the given identifier has been
|
||||||
* marked as preferred for this user's current Guacamole session. A
|
* marked as preferred for this user's current Guacamole session. A
|
||||||
|
@@ -121,7 +121,7 @@ public class UserContext extends RestrictedObject
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationProvider getAuthenticationProvider() {
|
public AuthenticationProvider getAuthenticationProvider() {
|
||||||
return getCurrentUser().getAuthenticationProvider();
|
return getCurrentUser().getModelAuthenticationProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -353,6 +353,10 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
* Retrieves the user corresponding to the given AuthenticatedUser from the
|
* Retrieves the user corresponding to the given AuthenticatedUser from the
|
||||||
* database.
|
* database.
|
||||||
*
|
*
|
||||||
|
* @param authenticationProvider
|
||||||
|
* The AuthenticationProvider on behalf of which the user is being
|
||||||
|
* retrieved.
|
||||||
|
*
|
||||||
* @param authenticatedUser
|
* @param authenticatedUser
|
||||||
* The AuthenticatedUser to retrieve the corresponding ModeledUser of.
|
* The AuthenticatedUser to retrieve the corresponding ModeledUser of.
|
||||||
*
|
*
|
||||||
@@ -360,7 +364,8 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
* The ModeledUser which corresponds to the given AuthenticatedUser, or
|
* The ModeledUser which corresponds to the given AuthenticatedUser, or
|
||||||
* null if no such user exists.
|
* null if no such user exists.
|
||||||
*/
|
*/
|
||||||
public ModeledUser retrieveUser(org.apache.guacamole.net.auth.AuthenticatedUser authenticatedUser) {
|
public ModeledUser retrieveUser(AuthenticationProvider authenticationProvider,
|
||||||
|
org.apache.guacamole.net.auth.AuthenticatedUser authenticatedUser) {
|
||||||
|
|
||||||
// If we already queried this user, return that rather than querying again
|
// If we already queried this user, return that rather than querying again
|
||||||
if (authenticatedUser instanceof AuthenticatedUser)
|
if (authenticatedUser instanceof AuthenticatedUser)
|
||||||
@@ -376,7 +381,8 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
|
|
||||||
// Create corresponding user object, set up cyclic reference
|
// Create corresponding user object, set up cyclic reference
|
||||||
ModeledUser user = getObjectInstance(null, userModel);
|
ModeledUser user = getObjectInstance(null, userModel);
|
||||||
user.setCurrentUser(new AuthenticatedUser(authenticatedUser.getAuthenticationProvider(), user, authenticatedUser.getCredentials()));
|
user.setCurrentUser(new AuthenticatedUser(authenticatedUser,
|
||||||
|
authenticationProvider, user));
|
||||||
|
|
||||||
// Return already-authenticated user
|
// Return already-authenticated user
|
||||||
return user;
|
return user;
|
||||||
|
Reference in New Issue
Block a user