GUACAMOLE-708: Handle implicit permissions where no entity exists.

This commit is contained in:
Virtually Nick
2020-06-19 21:40:00 -04:00
parent e0aedefd6f
commit 2888d6a340
3 changed files with 21 additions and 15 deletions

View File

@@ -132,7 +132,7 @@ public class JDBCAuthenticationProviderService implements AuthenticationProvider
user = userService.retrieveSkeletonUser(authenticationProvider, authenticatedUser); user = userService.retrieveSkeletonUser(authenticationProvider, authenticatedUser);
// If auto account creation is enabled, add user to DB. // If auto account creation is enabled, add user to DB.
if(environment.autoCreateAbsentAccounts()) { if (environment.autoCreateAbsentAccounts()) {
userService.createObject(new PrivilegedModeledAuthenticatedUser(user.getCurrentUser()), user); userService.createObject(new PrivilegedModeledAuthenticatedUser(user.getCurrentUser()), user);
} }

View File

@@ -410,9 +410,9 @@ public abstract class ModeledDirectoryObjectService<InternalType extends Modeled
} }
/** /**
* Returns a collection of permissions that should be granted due to the * Returns an immutable collection of permissions that should be granted due
* creation of the given object. These permissions need not be granted * to the creation of the given object. These permissions need not be
* solely to the user creating the object. * granted solely to the user creating the object.
* *
* @param user * @param user
* The user creating the object. * The user creating the object.
@@ -427,16 +427,22 @@ public abstract class ModeledDirectoryObjectService<InternalType extends Modeled
protected Collection<ObjectPermissionModel> getImplicitPermissions(ModeledAuthenticatedUser user, protected Collection<ObjectPermissionModel> getImplicitPermissions(ModeledAuthenticatedUser user,
ModelType model) { ModelType model) {
// Get the user model and check for an entity ID.
UserModel userModel = user.getUser().getModel();
Integer entityId = userModel.getEntityID();
if (entityId == null)
return Collections.emptyList();
// Build list of implicit permissions // Build list of implicit permissions
Collection<ObjectPermissionModel> implicitPermissions = Collection<ObjectPermissionModel> implicitPermissions =
new ArrayList<ObjectPermissionModel>(IMPLICIT_OBJECT_PERMISSIONS.length); new ArrayList<>(IMPLICIT_OBJECT_PERMISSIONS.length);
UserModel userModel = user.getUser().getModel();
for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) { for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) {
// Create model which grants this permission to the current user // Create model which grants this permission to the current user
ObjectPermissionModel permissionModel = new ObjectPermissionModel(); ObjectPermissionModel permissionModel = new ObjectPermissionModel();
permissionModel.setEntityID(userModel.getEntityID()); permissionModel.setEntityID(entityId);
permissionModel.setType(permission); permissionModel.setType(permission);
permissionModel.setObjectIdentifier(model.getIdentifier()); permissionModel.setObjectIdentifier(model.getIdentifier());
@@ -445,7 +451,7 @@ public abstract class ModeledDirectoryObjectService<InternalType extends Modeled
} }
return implicitPermissions; return Collections.unmodifiableCollection(implicitPermissions);
} }
@@ -464,7 +470,9 @@ public abstract class ModeledDirectoryObjectService<InternalType extends Modeled
object.setIdentifier(model.getIdentifier()); object.setIdentifier(model.getIdentifier());
// Add implicit permissions // Add implicit permissions
getPermissionMapper().insert(getImplicitPermissions(user, model)); Collection<ObjectPermissionModel> implicitPermissions = getImplicitPermissions(user, model);
if (implicitPermissions != null && !implicitPermissions.isEmpty())
getPermissionMapper().insert(implicitPermissions);
// Add any arbitrary attributes // Add any arbitrary attributes
if (model.hasArbitraryAttributes()) if (model.hasArbitraryAttributes())

View File

@@ -52,7 +52,6 @@ import org.apache.guacamole.net.auth.ActivityRecord;
import org.apache.guacamole.net.auth.AuthenticatedUser; import org.apache.guacamole.net.auth.AuthenticatedUser;
import org.apache.guacamole.net.auth.AuthenticationProvider; import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.auth.User; import org.apache.guacamole.net.auth.User;
import org.apache.guacamole.net.auth.UserContext;
import org.apache.guacamole.net.auth.credentials.CredentialsInfo; import org.apache.guacamole.net.auth.credentials.CredentialsInfo;
import org.apache.guacamole.net.auth.permission.ObjectPermission; import org.apache.guacamole.net.auth.permission.ObjectPermission;
import org.apache.guacamole.net.auth.permission.ObjectPermissionSet; import org.apache.guacamole.net.auth.permission.ObjectPermissionSet;
@@ -297,8 +296,9 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
protected Collection<ObjectPermissionModel> protected Collection<ObjectPermissionModel>
getImplicitPermissions(ModeledAuthenticatedUser user, UserModel model) { getImplicitPermissions(ModeledAuthenticatedUser user, UserModel model) {
// Get original set of implicit permissions // Get original set of implicit permissions and make a copy
Collection<ObjectPermissionModel> implicitPermissions = super.getImplicitPermissions(user, model); Collection<ObjectPermissionModel> implicitPermissions =
new ArrayList<>(super.getImplicitPermissions(user, model));
// Grant implicit permissions to the new user // Grant implicit permissions to the new user
for (ObjectPermission.Type permissionType : IMPLICIT_USER_PERMISSIONS) { for (ObjectPermission.Type permissionType : IMPLICIT_USER_PERMISSIONS) {
@@ -313,7 +313,7 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
} }
return implicitPermissions; return Collections.unmodifiableCollection(implicitPermissions);
} }
@Override @Override
@@ -447,8 +447,6 @@ public class UserService extends ModeledDirectoryObjectService<ModeledUser, User
public ModeledUser retrieveSkeletonUser(AuthenticationProvider authenticationProvider, public ModeledUser retrieveSkeletonUser(AuthenticationProvider authenticationProvider,
AuthenticatedUser authenticatedUser) throws GuacamoleException { AuthenticatedUser authenticatedUser) throws GuacamoleException {
logger.info(">>>JDBC<<< Creating skeleton user {}", authenticatedUser.getIdentifier());
// Set up an empty user model // Set up an empty user model
ModeledUser user = getObjectInstance(null, ModeledUser user = getObjectInstance(null,
new UserModel(authenticatedUser.getIdentifier())); new UserModel(authenticatedUser.getIdentifier()));