示例#1
0
  /**
   * Create any new system permissions for a given user. All permissions in the given list will be
   * inserted.
   *
   * @param user_id The ID of the user whose permissions should be updated.
   * @param permissions The new system permissions that the given user should have when this
   *     operation completes.
   * @throws GuacamoleException If permission to administer system permissions is denied.
   */
  private void createSystemPermissions(int user_id, Collection<SystemPermission> permissions)
      throws GuacamoleException {

    // If no permissions given, stop now
    if (permissions.isEmpty()) return;

    // Only a system administrator can add system permissions.
    permissionCheckService.verifySystemAccess(
        this.user_id, SystemPermission.Type.ADMINISTER.name());

    // Insert all requested permissions
    for (SystemPermission permission : permissions) {

      // Insert permission
      SystemPermissionKey newSystemPermission = new SystemPermissionKey();
      newSystemPermission.setUser_id(user_id);
      newSystemPermission.setPermission(MySQLConstants.getSystemConstant(permission.getType()));
      systemPermissionDAO.insert(newSystemPermission);
    }
  }