mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-284: Move enforcement of account restrictions into AuthenticationProviderService.
This commit is contained in:
@@ -21,9 +21,11 @@ package org.apache.guacamole.auth.jdbc;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
import org.apache.guacamole.GuacamoleClientException;
|
||||||
import org.apache.guacamole.GuacamoleException;
|
import org.apache.guacamole.GuacamoleException;
|
||||||
import org.apache.guacamole.auth.jdbc.security.PasswordPolicyService;
|
import org.apache.guacamole.auth.jdbc.security.PasswordPolicyService;
|
||||||
import org.apache.guacamole.auth.jdbc.sharing.user.SharedAuthenticatedUser;
|
import org.apache.guacamole.auth.jdbc.sharing.user.SharedAuthenticatedUser;
|
||||||
|
import org.apache.guacamole.auth.jdbc.user.ModeledAuthenticatedUser;
|
||||||
import org.apache.guacamole.auth.jdbc.user.ModeledUser;
|
import org.apache.guacamole.auth.jdbc.user.ModeledUser;
|
||||||
import org.apache.guacamole.auth.jdbc.user.ModeledUserContext;
|
import org.apache.guacamole.auth.jdbc.user.ModeledUserContext;
|
||||||
import org.apache.guacamole.auth.jdbc.user.UserModel;
|
import org.apache.guacamole.auth.jdbc.user.UserModel;
|
||||||
@@ -104,13 +106,24 @@ public class JDBCAuthenticationProviderService implements AuthenticationProvider
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Veto authentication result if account is required but unavailable
|
// Apply account restrictions if this extension authenticated the user
|
||||||
// due to account restrictions
|
// OR if an account from this extension is explicitly required
|
||||||
UserModel userModel = user.getModel();
|
UserModel userModel = user.getModel();
|
||||||
if (environment.isUserRequired()
|
if (authenticatedUser instanceof ModeledAuthenticatedUser || environment.isUserRequired()) {
|
||||||
&& (userModel.isDisabled() || !user.isAccountValid() || !user.isAccountAccessible())) {
|
|
||||||
|
// If user is disabled, pretend user does not exist
|
||||||
|
if (userModel.isDisabled())
|
||||||
throw new GuacamoleInvalidCredentialsException("Invalid login",
|
throw new GuacamoleInvalidCredentialsException("Invalid login",
|
||||||
CredentialsInfo.USERNAME_PASSWORD);
|
CredentialsInfo.USERNAME_PASSWORD);
|
||||||
|
|
||||||
|
// Verify user account is still valid as of today
|
||||||
|
if (!user.isAccountValid())
|
||||||
|
throw new GuacamoleClientException("LOGIN.ERROR_NOT_VALID");
|
||||||
|
|
||||||
|
// Verify user account is allowed to be used at the current time
|
||||||
|
if (!user.isAccountAccessible())
|
||||||
|
throw new GuacamoleClientException("LOGIN.ERROR_NOT_ACCESSIBLE");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update password if password is expired
|
// Update password if password is expired
|
||||||
|
@@ -312,9 +312,10 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the user corresponding to the given credentials from the
|
* Retrieves the user corresponding to the given credentials from the
|
||||||
* database. If the user account is expired, and the credentials contain
|
* database. Note that this function will not enforce any additional
|
||||||
* the necessary additional parameters to reset the user's password, the
|
* account restrictions, including explicitly disabled accounts,
|
||||||
* password is reset.
|
* scheduling, and password expiration. It is the responsibility of the
|
||||||
|
* caller to enforce such restrictions, if desired.
|
||||||
*
|
*
|
||||||
* @param authenticationProvider
|
* @param authenticationProvider
|
||||||
* The AuthenticationProvider on behalf of which the user is being
|
* The AuthenticationProvider on behalf of which the user is being
|
||||||
@@ -342,10 +343,6 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
if (userModel == null)
|
if (userModel == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// If user is disabled, pretend user does not exist
|
|
||||||
if (userModel.isDisabled())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// Verify provided password is correct
|
// Verify provided password is correct
|
||||||
byte[] hash = encryptionService.createPasswordHash(password, userModel.getPasswordSalt());
|
byte[] hash = encryptionService.createPasswordHash(password, userModel.getPasswordSalt());
|
||||||
if (!Arrays.equals(hash, userModel.getPasswordHash()))
|
if (!Arrays.equals(hash, userModel.getPasswordHash()))
|
||||||
@@ -355,14 +352,6 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
|
|||||||
ModeledUser user = getObjectInstance(null, userModel);
|
ModeledUser user = getObjectInstance(null, userModel);
|
||||||
user.setCurrentUser(new ModeledAuthenticatedUser(authenticationProvider, user, credentials));
|
user.setCurrentUser(new ModeledAuthenticatedUser(authenticationProvider, user, credentials));
|
||||||
|
|
||||||
// Verify user account is still valid as of today
|
|
||||||
if (!user.isAccountValid())
|
|
||||||
throw new GuacamoleClientException("LOGIN.ERROR_NOT_VALID");
|
|
||||||
|
|
||||||
// Verify user account is allowed to be used at the current time
|
|
||||||
if (!user.isAccountAccessible())
|
|
||||||
throw new GuacamoleClientException("LOGIN.ERROR_NOT_ACCESSIBLE");
|
|
||||||
|
|
||||||
// Return now-authenticated user
|
// Return now-authenticated user
|
||||||
return user.getCurrentUser();
|
return user.getCurrentUser();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user