mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-801 Created password update dialog on home screen, grant self READ and UPDATE permission to users upon creation, and added sql update script to grant self READ and UPDATE permissions for users in pre-existing databases.
This commit is contained in:
@@ -338,6 +338,47 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of permissions that should be granted due to the
|
||||
* creation of the given object. These permissions need not be granted
|
||||
* solely to the user creating the object.
|
||||
*
|
||||
* @param user
|
||||
* The user creating the object.
|
||||
*
|
||||
* @param model
|
||||
* The object being created.
|
||||
*
|
||||
* @return
|
||||
* The collection of implicit permissions that should be granted due to
|
||||
* the creation of the given object.
|
||||
*/
|
||||
protected Collection<ObjectPermissionModel> getImplicitPermissions(AuthenticatedUser user,
|
||||
ModelType model) {
|
||||
|
||||
// Build list of implicit permissions
|
||||
Collection<ObjectPermissionModel> implicitPermissions =
|
||||
new ArrayList<ObjectPermissionModel>(IMPLICIT_OBJECT_PERMISSIONS.length);
|
||||
|
||||
UserModel userModel = user.getUser().getModel();
|
||||
for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) {
|
||||
|
||||
// Create model which grants this permission to the current user
|
||||
ObjectPermissionModel permissionModel = new ObjectPermissionModel();
|
||||
permissionModel.setUserID(userModel.getObjectID());
|
||||
permissionModel.setUsername(userModel.getIdentifier());
|
||||
permissionModel.setType(permission);
|
||||
permissionModel.setObjectIdentifier(model.getIdentifier());
|
||||
|
||||
// Add permission
|
||||
implicitPermissions.add(permissionModel);
|
||||
|
||||
}
|
||||
|
||||
return implicitPermissions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the given object within the database. If the object already
|
||||
* exists, an error will be thrown. The internal model object will be
|
||||
@@ -369,27 +410,8 @@ public abstract class DirectoryObjectService<InternalType extends DirectoryObjec
|
||||
// Create object
|
||||
getObjectMapper().insert(model);
|
||||
|
||||
// Build list of implicit permissions
|
||||
Collection<ObjectPermissionModel> implicitPermissions =
|
||||
new ArrayList<ObjectPermissionModel>(IMPLICIT_OBJECT_PERMISSIONS.length);
|
||||
|
||||
UserModel userModel = user.getUser().getModel();
|
||||
for (ObjectPermission.Type permission : IMPLICIT_OBJECT_PERMISSIONS) {
|
||||
|
||||
// Create model which grants this permission to the current user
|
||||
ObjectPermissionModel permissionModel = new ObjectPermissionModel();
|
||||
permissionModel.setUserID(userModel.getObjectID());
|
||||
permissionModel.setUsername(userModel.getIdentifier());
|
||||
permissionModel.setType(permission);
|
||||
permissionModel.setObjectIdentifier(model.getIdentifier());
|
||||
|
||||
// Add permission
|
||||
implicitPermissions.add(permissionModel);
|
||||
|
||||
}
|
||||
|
||||
// Add implicit permissions
|
||||
getPermissionMapper().insert(implicitPermissions);
|
||||
getPermissionMapper().insert(getImplicitPermissions(user, model));
|
||||
|
||||
return getObjectInstance(user, model);
|
||||
}
|
||||
|
@@ -33,9 +33,11 @@ import org.glyptodon.guacamole.auth.jdbc.base.DirectoryObjectService;
|
||||
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||
import org.glyptodon.guacamole.GuacamoleException;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.ObjectPermissionModel;
|
||||
import org.glyptodon.guacamole.auth.jdbc.permission.UserPermissionMapper;
|
||||
import org.glyptodon.guacamole.auth.jdbc.security.PasswordEncryptionService;
|
||||
import org.glyptodon.guacamole.net.auth.User;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.ObjectPermissionSet;
|
||||
import org.glyptodon.guacamole.net.auth.permission.SystemPermission;
|
||||
import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
|
||||
@@ -47,7 +49,16 @@ import org.glyptodon.guacamole.net.auth.permission.SystemPermissionSet;
|
||||
* @author Michael Jumper, James Muehlner
|
||||
*/
|
||||
public class UserService extends DirectoryObjectService<ModeledUser, User, UserModel> {
|
||||
|
||||
|
||||
/**
|
||||
* All user permissions which are implicitly granted to the new user upon
|
||||
* creation.
|
||||
*/
|
||||
private static final ObjectPermission.Type[] IMPLICIT_USER_PERMISSIONS = {
|
||||
ObjectPermission.Type.READ,
|
||||
ObjectPermission.Type.UPDATE
|
||||
};
|
||||
|
||||
/**
|
||||
* Mapper for accessing users.
|
||||
*/
|
||||
@@ -160,6 +171,31 @@ public class UserService extends DirectoryObjectService<ModeledUser, User, UserM
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ObjectPermissionModel>
|
||||
getImplicitPermissions(AuthenticatedUser user, UserModel model) {
|
||||
|
||||
// Get original set of implicit permissions
|
||||
Collection<ObjectPermissionModel> implicitPermissions = super.getImplicitPermissions(user, model);
|
||||
|
||||
// Grant implicit permissions to the new user
|
||||
for (ObjectPermission.Type permissionType : IMPLICIT_USER_PERMISSIONS) {
|
||||
|
||||
ObjectPermissionModel permissionModel = new ObjectPermissionModel();
|
||||
permissionModel.setUserID(model.getObjectID());
|
||||
permissionModel.setUsername(model.getIdentifier());
|
||||
permissionModel.setType(permissionType);
|
||||
permissionModel.setObjectIdentifier(model.getIdentifier());
|
||||
|
||||
// Add new permission to implicit permission set
|
||||
implicitPermissions.add(permissionModel);
|
||||
|
||||
}
|
||||
|
||||
return implicitPermissions;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the user corresponding to the given credentials from the
|
||||
* database.
|
||||
|
@@ -0,0 +1,53 @@
|
||||
--
|
||||
-- Copyright (C) 2015 Glyptodon LLC
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
-- THE SOFTWARE.
|
||||
--
|
||||
|
||||
--
|
||||
-- Explicitly add permission for each user to READ and UPDATE him/herself
|
||||
--
|
||||
|
||||
INSERT INTO guacamole_user_permission
|
||||
(user_id, affected_user_id, permission)
|
||||
SELECT user_id, user_id, 'UPDATE'
|
||||
FROM guacamole_user
|
||||
WHERE
|
||||
user_id NOT IN (
|
||||
SELECT user_id
|
||||
FROM guacamole_user_permission
|
||||
WHERE
|
||||
user_id = affected_user_id
|
||||
AND permission = 'UPDATE'
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO guacamole_user_permission
|
||||
(user_id, affected_user_id, permission)
|
||||
SELECT user_id, user_id, 'READ'
|
||||
FROM guacamole_user
|
||||
WHERE
|
||||
user_id NOT IN (
|
||||
SELECT user_id
|
||||
FROM guacamole_user_permission
|
||||
WHERE
|
||||
user_id = affected_user_id
|
||||
AND permission = 'READ'
|
||||
);
|
||||
|
Reference in New Issue
Block a user