2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Threading;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
using System.Windows.Forms;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Actions;
|
2018-10-24 00:13:03 +02:00
|
|
|
|
using XenAdmin.Commands;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
using XenAdmin.Controls.DataGridViewEx;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAdmin.Dialogs;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
using XenAdmin.Network;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
using XenAPI;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.TabPages
|
|
|
|
|
{
|
|
|
|
|
public partial class AdPage : BaseTabPage
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The pool this settings page refers to (can be a poolOfOne). Only set on the GUI thread, and we also assert that it is only
|
|
|
|
|
/// ever set once.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Pool pool;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private Host coordinator;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
private IXenConnection _connection;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private Thread _loggedInStatusUpdater;
|
2018-07-25 19:55:33 +02:00
|
|
|
|
private bool _updateInProgress;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
private readonly object _statusUpdaterLock = new object();
|
2018-07-25 19:55:33 +02:00
|
|
|
|
|
2018-07-27 14:16:01 +02:00
|
|
|
|
private string _storedDomain;
|
|
|
|
|
private string _storedUsername;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private readonly CollectionChangeEventHandler Pool_CollectionChangedWithInvoke;
|
|
|
|
|
public IXenObject XenObject
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
ClearHandles();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
_connection = value == null ? null : value.Connection;
|
|
|
|
|
if (_connection == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
pool = Helpers.GetPoolOfOne(_connection);
|
|
|
|
|
if (pool == null) // Cache not populated
|
|
|
|
|
_connection.Cache.RegisterCollectionChanged<Pool>(Pool_CollectionChangedWithInvoke);
|
|
|
|
|
else
|
|
|
|
|
pool.PropertyChanged += pool_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (_connection.Session != null)
|
|
|
|
|
_connection.Session.PropertyChanged += Session_PropertyChanged;
|
|
|
|
|
checkAdType();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (_loggedInStatusUpdater == null)
|
|
|
|
|
{
|
|
|
|
|
// Fire off the the thread that will update the logged in status
|
|
|
|
|
_loggedInStatusUpdater = new Thread(updateLoggedInStatus);
|
|
|
|
|
_loggedInStatusUpdater.IsBackground = true;
|
|
|
|
|
_loggedInStatusUpdater.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AdPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Pool_CollectionChangedWithInvoke = Program.ProgramInvokeHandler(Pool_CollectionChanged);
|
|
|
|
|
ColumnSubject.CellTemplate = new KeyValuePairCell();
|
|
|
|
|
tTipLogoutButton.SetToolTip(Messages.AD_CANNOT_MODIFY_ROOT);
|
|
|
|
|
tTipRemoveButton.SetToolTip(Messages.AD_CANNOT_MODIFY_ROOT);
|
2018-07-25 20:02:35 +02:00
|
|
|
|
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Text = Messages.ACTIVE_DIRECTORY_TAB_TITLE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 18:47:27 +02:00
|
|
|
|
public override string HelpID => "TabPageAD";
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method is used when the cache was not populated by the time we set the XenObject. It sets the appropriate event handlers,
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// references to the coordinator and the pool, and populates the tab with the correct configuration. It de-registers
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// itself when successful.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
void Pool_CollectionChanged(object sender, CollectionChangeEventArgs e)
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
pool = Helpers.GetPoolOfOne(_connection);
|
|
|
|
|
if (pool == null) // Cache not populated
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
_connection.Cache.DeregisterCollectionChanged<Pool>(Pool_CollectionChangedWithInvoke);
|
2018-07-25 20:02:35 +02:00
|
|
|
|
pool.PropertyChanged += pool_PropertyChanged;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
|
|
|
|
|
Program.Invoke(this, checkAdType);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private void RefreshCoordinator()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator != null)
|
|
|
|
|
coordinator.PropertyChanged -= coordinator_PropertyChanged;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
coordinator = Helpers.GetCoordinator(_connection);
|
|
|
|
|
if (coordinator != null)
|
|
|
|
|
coordinator.PropertyChanged += coordinator_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clears all event handles that could be set in this control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ClearHandles()
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (pool != null)
|
|
|
|
|
pool.PropertyChanged -= pool_PropertyChanged;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator != null)
|
|
|
|
|
coordinator.PropertyChanged -= coordinator_PropertyChanged;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (_connection != null)
|
|
|
|
|
{
|
|
|
|
|
_connection.Cache.DeregisterBatchCollectionChanged<Subject>(SubjectCollectionChanged);
|
|
|
|
|
if (_connection.Session != null)
|
|
|
|
|
_connection.Session.PropertyChanged -= Session_PropertyChanged;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 13:38:33 +01:00
|
|
|
|
public override void PageHidden()
|
|
|
|
|
{
|
|
|
|
|
ClearHandles();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// <summary>
|
2018-07-27 19:18:05 +02:00
|
|
|
|
/// We keep track of the actions currently running so we can disable the tab if we are in the middle of configuring AD.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
void History_CollectionChanged(object sender, CollectionChangeEventArgs e)
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (e.Action == CollectionChangeAction.Add &&
|
|
|
|
|
(e.Element is EnableAdAction || e.Element is DisableAdAction))
|
|
|
|
|
{
|
|
|
|
|
AsyncAction action = (AsyncAction)e.Element;
|
|
|
|
|
action.Completed += action_Completed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (_connection != null && _connection == action.Connection)
|
|
|
|
|
Program.Invoke(this, checkAdType);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-05 15:28:21 +02:00
|
|
|
|
void action_Completed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
AsyncAction action = (AsyncAction)sender;
|
2013-08-05 15:28:21 +02:00
|
|
|
|
action.Completed -= action_Completed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (_connection != null && _connection == action.Connection)
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, checkAdType);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 20:02:35 +02:00
|
|
|
|
void Session_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-25 20:02:35 +02:00
|
|
|
|
Program.BeginInvoke(this, RepopulateListBox);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We need to update the configuration if the authentication method changes, and also various labels display the name of the
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// coordinator and should also be updated if that changes.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender1"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2021-08-31 12:31:16 +02:00
|
|
|
|
void coordinator_PropertyChanged(object sender1, PropertyChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == "external_auth_type" || e.PropertyName == "name_label")
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, checkAdType);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-07-27 19:18:05 +02:00
|
|
|
|
/// Various labels display the name of the pool and should also be updated if that changes.
|
2021-08-31 12:31:16 +02:00
|
|
|
|
/// Additionally if the pool coordinator changes we need to update our event handles.
|
2018-07-27 19:18:05 +02:00
|
|
|
|
/// There is a sanity check in the checkAdType() method in case this event is stuck in a queue.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
2018-07-25 20:02:35 +02:00
|
|
|
|
void pool_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (e.PropertyName == "name_label" || e.PropertyName == "master")
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, checkAdType);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSubjectListEnable(bool enable)
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
GridViewSubjectList.Enabled = enable;
|
2018-07-26 11:58:24 +02:00
|
|
|
|
if (GridViewSubjectList.Enabled)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
LabelGridViewDisabled.Visible = false;
|
|
|
|
|
RepopulateListBox();
|
2018-07-25 20:02:35 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (r.IsLocalRootRow)
|
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
r.ToggleExpandedState();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-07-26 11:58:24 +02:00
|
|
|
|
foreach (AdSubjectRow row in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.IsLocalRootRow)
|
|
|
|
|
continue;
|
|
|
|
|
row.subject.PropertyChanged -= subject_PropertyChanged;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
GridViewSubjectList.Rows.Clear();
|
2018-07-26 11:58:24 +02:00
|
|
|
|
LabelGridViewDisabled.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkAdType()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
2021-08-31 12:31:16 +02:00
|
|
|
|
//refresh the coordinator in case the cache is slow
|
|
|
|
|
RefreshCoordinator();
|
2018-07-27 19:18:05 +02:00
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
log.WarnFormat("Could not resolve pool coordinator for connection '{0}'; disabling.", Helpers.GetName(_connection));
|
|
|
|
|
OnCoordinatorUnavailable();
|
2018-07-27 19:23:33 +02:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-27 19:23:33 +02:00
|
|
|
|
|
|
|
|
|
var action = (from ActionBase act in ConnectionsManager.History
|
2021-11-09 12:18:48 +01:00
|
|
|
|
let async = act as AsyncAction
|
|
|
|
|
where async != null && !async.IsCompleted && !async.Cancelled && async.Connection == _connection
|
|
|
|
|
&& (async is EnableAdAction || async is DisableAdAction)
|
|
|
|
|
select async).FirstOrDefault();
|
2018-07-27 19:23:33 +02:00
|
|
|
|
|
|
|
|
|
if (action != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
OnAdConfiguring();
|
|
|
|
|
}
|
2021-08-31 12:31:16 +02:00
|
|
|
|
else if (coordinator.external_auth_type == Auth.AUTH_TYPE_NONE) // AD is not yet configured
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
OnAdDisabled();
|
|
|
|
|
}
|
2018-07-27 19:18:05 +02:00
|
|
|
|
else // AD is already configured
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (coordinator.external_auth_type != Auth.AUTH_TYPE_AD)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
log.WarnFormat("Unrecognised value '{0}' for external_auth_type on pool coordinator '{1}' for pool '{2}'; assuming AD enabled on pool.",
|
|
|
|
|
coordinator.external_auth_type, Helpers.GetName(coordinator), Helpers.GetName(_connection));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2018-07-27 19:23:33 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
OnAdEnabled();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 11:58:24 +02:00
|
|
|
|
private void SubjectCollectionChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-26 11:58:24 +02:00
|
|
|
|
Program.BeginInvoke(this, RepopulateListBox);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string Domain
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host coordinator = Helpers.GetCoordinator(_connection);
|
|
|
|
|
if (coordinator == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
log.WarnFormat("Could not resolve pool coordinator for connection '{0}'; disabling.", Helpers.GetName(_connection));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return Messages.UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
return coordinator.external_auth_service_name;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAdEnabled()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
flowLayoutPanel1.Enabled = true;
|
|
|
|
|
SetSubjectListEnable(true);
|
|
|
|
|
buttonJoinLeave.Text = Messages.AD_LEAVE_DOMAIN;
|
|
|
|
|
buttonJoinLeave.Enabled = true;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
labelBlurb.Text = string.Format(Helpers.GetPool(_connection) != null ? Messages.AD_CONFIGURED_BLURB : Messages.AD_CONFIGURED_BLURB_HOST, Helpers.GetName(_connection).Ellipsise(70), Domain.Ellipsise(30));
|
|
|
|
|
_connection.Cache.RegisterBatchCollectionChanged<Subject>(SubjectCollectionChanged);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAdDisabled()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
flowLayoutPanel1.Enabled = false;
|
|
|
|
|
SetSubjectListEnable(false);
|
|
|
|
|
buttonJoinLeave.Text = Messages.AD_JOIN_DOMAIN;
|
|
|
|
|
buttonJoinLeave.Enabled = true;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
labelBlurb.Text = string.Format(Helpers.GetPool(_connection) != null ? Messages.AD_NOT_CONFIGURED_BLURB : Messages.AD_NOT_CONFIGURED_BLURB_HOST,
|
|
|
|
|
Helpers.GetName(_connection).Ellipsise(70));
|
|
|
|
|
_connection.Cache.DeregisterBatchCollectionChanged<Subject>(SubjectCollectionChanged);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAdConfiguring()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
flowLayoutPanel1.Enabled = false;
|
|
|
|
|
SetSubjectListEnable(false);
|
|
|
|
|
buttonJoinLeave.Enabled = false;
|
2018-07-27 19:18:05 +02:00
|
|
|
|
labelBlurb.Text = string.Format(Helpers.GetPool(_connection) != null ? Messages.AD_CONFIGURING_BLURB : Messages.AD_CONFIGURING_BLURB_HOST,
|
|
|
|
|
Helpers.GetName(_connection).Ellipsise(70));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
private void OnCoordinatorUnavailable()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
|
|
|
|
flowLayoutPanel1.Enabled = false;
|
|
|
|
|
SetSubjectListEnable(false);
|
|
|
|
|
buttonJoinLeave.Enabled = false;
|
2021-08-31 12:31:16 +02:00
|
|
|
|
labelBlurb.Text = Messages.AD_COORDINATOR_UNAVAILABLE_BLURB;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RepopulateListBox()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2018-07-26 11:58:24 +02:00
|
|
|
|
if (!GridViewSubjectList.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Dictionary<string, bool> selectedSubjectUuids = new Dictionary<string, bool>();
|
|
|
|
|
Dictionary<string, bool> expandedSubjectUuids = new Dictionary<string, bool>();
|
|
|
|
|
bool rootExpanded = false;
|
|
|
|
|
string topSubject = "";
|
|
|
|
|
if (GridViewSubjectList.FirstDisplayedScrollingRowIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
AdSubjectRow topRow = GridViewSubjectList.Rows[GridViewSubjectList.FirstDisplayedScrollingRowIndex] as AdSubjectRow;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
if (topRow != null && topRow.subject != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
topSubject = topRow.subject.uuid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GridViewSubjectList.SelectedRows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
if (r.subject != null)
|
|
|
|
|
selectedSubjectUuids.Add(r.subject.uuid, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (AdSubjectRow row in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.Expanded)
|
|
|
|
|
if (row.subject == null)
|
|
|
|
|
rootExpanded = true;
|
|
|
|
|
else
|
|
|
|
|
expandedSubjectUuids.Add(row.subject.uuid, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-07-25 19:55:33 +02:00
|
|
|
|
_updateInProgress = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
GridViewSubjectList.SuspendLayout();
|
2018-07-26 11:58:24 +02:00
|
|
|
|
|
|
|
|
|
foreach (AdSubjectRow row in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.IsLocalRootRow)
|
|
|
|
|
continue;
|
|
|
|
|
row.subject.PropertyChanged -= subject_PropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
GridViewSubjectList.Rows.Clear();
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var rows = new List<DataGridViewRow> { new AdSubjectRow(null) }; //local root account
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
foreach (Subject subject in _connection.Cache.Subjects) //all other subjects in the pool
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
subject.PropertyChanged += subject_PropertyChanged;
|
|
|
|
|
rows.Add(new AdSubjectRow(subject));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
GridViewSubjectList.Rows.AddRange(rows.ToArray());
|
2018-07-25 00:32:42 +02:00
|
|
|
|
|
|
|
|
|
GridViewSubjectList.Sort(GridViewSubjectList.SortedColumn ?? ColumnSubject,
|
|
|
|
|
GridViewSubjectList.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// restore old selection, old expansion state and top row
|
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
r.Selected = !r.IsLocalRootRow && selectedSubjectUuids.ContainsKey(r.subject.uuid);
|
|
|
|
|
r.Expanded = r.IsLocalRootRow ? rootExpanded : expandedSubjectUuids.ContainsKey(r.subject.uuid);
|
|
|
|
|
|
|
|
|
|
if (!r.IsLocalRootRow && topSubject == r.subject.uuid)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
GridViewSubjectList.FirstDisplayedScrollingRowIndex = r.Index;
|
|
|
|
|
}
|
|
|
|
|
if (GridViewSubjectList.SelectedRows.Count == 0)
|
|
|
|
|
GridViewSubjectList.Rows[0].Selected = true;
|
|
|
|
|
|
2018-06-21 15:41:19 +02:00
|
|
|
|
HelpersGUI.ResizeGridViewColumnToAllCells(ColumnSubject);
|
|
|
|
|
HelpersGUI.ResizeGridViewColumnToAllCells(ColumnRoles);
|
|
|
|
|
HelpersGUI.ResizeGridViewColumnToAllCells(ColumnStatus);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
GridViewSubjectList.ResumeLayout();
|
2018-07-25 19:55:33 +02:00
|
|
|
|
_updateInProgress = false;
|
|
|
|
|
EnableButtons();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 20:02:35 +02:00
|
|
|
|
private void subject_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2020-05-19 01:44:50 +02:00
|
|
|
|
if (e.PropertyName != "roles" && e.PropertyName != "other_config")
|
2018-07-26 11:12:19 +02:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-26 11:12:19 +02:00
|
|
|
|
var subject = sender as Subject;
|
|
|
|
|
if (subject == null)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-26 11:12:19 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
{
|
|
|
|
|
if (!GridViewSubjectList.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var found = (from DataGridViewRow row in GridViewSubjectList.Rows
|
2021-11-09 12:18:48 +01:00
|
|
|
|
let adRow = row as AdSubjectRow
|
|
|
|
|
where adRow != null && adRow.subject != null && adRow.subject.opaque_ref == subject.opaque_ref
|
|
|
|
|
select adRow).FirstOrDefault();
|
2018-07-26 11:12:19 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
GridViewSubjectList.SuspendLayout();
|
|
|
|
|
|
|
|
|
|
if (found == null)
|
|
|
|
|
GridViewSubjectList.Rows.Add(new AdSubjectRow(subject));
|
|
|
|
|
else
|
|
|
|
|
found.RefreshCellContent(subject);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
GridViewSubjectList.ResumeLayout();
|
2018-07-25 19:55:33 +02:00
|
|
|
|
EnableButtons();
|
2018-07-26 11:12:19 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Background thread called periodically to update subjects logged in status.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void updateLoggedInStatus()
|
|
|
|
|
{
|
|
|
|
|
// This could get a bit spammy with a repeated exception, consider a back off or summary approach if it becomes an issue
|
|
|
|
|
Program.AssertOffEventThread();
|
2018-07-27 19:18:05 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
while (!Disposing && !IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bool showing = false;
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, delegate
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
showing = Program.MainWindow.TheTabControl.SelectedTab == Program.MainWindow.TabPageAD;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
if (showing)
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
String[] loggedInSids = _connection.Session.get_all_subject_identifiers();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
// Want fast access time for when we take the lock and switch off the background thread
|
|
|
|
|
Dictionary<string, bool> loggedSids = new Dictionary<string, bool>();
|
|
|
|
|
foreach (string s in loggedInSids)
|
|
|
|
|
loggedSids.Add(s, true);
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, delegate
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
// local root row
|
|
|
|
|
if (r.IsLocalRootRow)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
r.LoggedIn = loggedSids.ContainsKey(r.subject.subject_identifier);
|
|
|
|
|
}
|
2018-07-25 19:55:33 +02:00
|
|
|
|
EnableButtons();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-11-09 12:18:48 +01:00
|
|
|
|
lock (_statusUpdaterLock)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-11-09 12:18:48 +01:00
|
|
|
|
Monitor.Wait(_statusUpdaterLock, 5000);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
showLoggedInStatusError();
|
|
|
|
|
log.Error(e);
|
2018-07-27 19:18:05 +02:00
|
|
|
|
Thread.Sleep(5000);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showLoggedInStatusError()
|
|
|
|
|
{
|
2015-04-16 15:17:02 +02:00
|
|
|
|
Program.Invoke(this, delegate
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (r.IsLocalRootRow)
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
r.SetStatusLost();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Custom AD Row Class
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used in the DataGridView on the ConfigureAdDialog. Stores information about the subject and the different text to show if the
|
|
|
|
|
/// row is expanded or not.
|
|
|
|
|
/// </summary>
|
2018-07-25 00:32:42 +02:00
|
|
|
|
private class AdSubjectRow : DataGridViewRow
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
private readonly DataGridViewImageCell _cellExpander = new DataGridViewImageCell();
|
|
|
|
|
private readonly DataGridViewImageCell _cellGroupOrUser = new DataGridViewImageCell();
|
|
|
|
|
private readonly KeyValuePairCell _cellSubjectInfo = new KeyValuePairCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _cellRoles = new DataGridViewTextBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _cellLoggedIn = new DataGridViewTextBoxCell();
|
|
|
|
|
|
|
|
|
|
internal Subject subject { get; private set; }
|
|
|
|
|
private bool expanded;
|
|
|
|
|
private bool loggedIn;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The row is created with unknown status until it's updated from outside the class
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool statusLost = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public bool LoggedIn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return loggedIn;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
loggedIn = value;
|
|
|
|
|
statusLost = false;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
RefreshCellContent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal bool IsLocalRootRow
|
|
|
|
|
{
|
|
|
|
|
get { return subject == null; }
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The full list of the subject's roles
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly string expandedRoles = string.Empty;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Topmost of the subject's roles
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly string contractedRoles = string.Empty;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The detailed info from the subject's other_config along with their display name
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly List<KeyValuePair<string, string>> expandedSubjectInfo = new List<KeyValuePair<String, String>>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The subject's display name
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly List<KeyValuePair<string, string>> contractedSubjectInfo = new List<KeyValuePair<String, String>>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-07-25 00:32:42 +02:00
|
|
|
|
/// A DataGridViewRow that corresponds to a subject and shows their
|
|
|
|
|
/// information in expanded and collapsed states
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
2018-07-25 00:32:42 +02:00
|
|
|
|
/// <param name="subject">If null, if it is a root account (no subject)</param>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
internal AdSubjectRow(Subject subject)
|
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
if (subject == null) //root account
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
expandedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_LOCAL_ROOT_ACCOUNT, ""));
|
|
|
|
|
expandedSubjectInfo.Add(new KeyValuePair<string, string>("", ""));
|
|
|
|
|
expandedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_ALWAYS_GRANTED_ACCESS, ""));
|
|
|
|
|
contractedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_LOCAL_ROOT_ACCOUNT, ""));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
this.subject = subject;
|
|
|
|
|
var roles = subject.Connection.ResolveAll(subject.roles);
|
2015-10-26 17:01:55 +01:00
|
|
|
|
roles.Sort();
|
|
|
|
|
roles.Reverse();
|
2018-07-25 00:32:42 +02:00
|
|
|
|
if (roles.Count > 0)
|
|
|
|
|
expandedRoles = roles.Select(r => r.FriendlyName()).Aggregate((acc, s) => acc + "\n" + s);
|
|
|
|
|
|
2017-09-03 04:33:29 +02:00
|
|
|
|
contractedRoles = roles.Count > 0
|
|
|
|
|
? roles.Count > 1 ? roles[0].FriendlyName().AddEllipsis() : roles[0].FriendlyName()
|
2015-10-26 17:01:55 +01:00
|
|
|
|
: "";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
contractedSubjectInfo.Add(new KeyValuePair<string, string>(subject.DisplayName ?? subject.SubjectName ?? "", ""));
|
|
|
|
|
expandedSubjectInfo = Subject.ExtractKvpInfo(subject);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
Cells.AddRange(_cellExpander, _cellGroupOrUser, _cellSubjectInfo, _cellRoles, _cellLoggedIn);
|
|
|
|
|
RefreshCellContent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 11:12:19 +02:00
|
|
|
|
public void RefreshCellContent(Subject subj = null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-26 11:12:19 +02:00
|
|
|
|
if (subj != null)
|
|
|
|
|
subject = subj;
|
|
|
|
|
|
2020-06-18 02:20:29 +02:00
|
|
|
|
_cellExpander.Value = expanded ? Images.StaticImages.expanded_triangle : Images.StaticImages.contracted_triangle;
|
|
|
|
|
_cellGroupOrUser.Value = IsLocalRootRow || !subject.IsGroup ? Images.StaticImages._000_User_h32bit_16 : Images.StaticImages._000_UserAndGroup_h32bit_16;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
_cellSubjectInfo.Value = expanded ? expandedSubjectInfo : contractedSubjectInfo;
|
|
|
|
|
_cellRoles.Value = expanded ? expandedRoles : contractedRoles;
|
|
|
|
|
_cellLoggedIn.Value = IsLocalRootRow || subject.IsGroup || statusLost
|
|
|
|
|
? "-"
|
|
|
|
|
: loggedIn ? Messages.YES : Messages.NO;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
public void ToggleExpandedState()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
expanded = !expanded;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
RefreshCellContent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Expanded
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return expanded;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
if (expanded != value)
|
|
|
|
|
{
|
|
|
|
|
expanded = value;
|
|
|
|
|
RefreshCellContent();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
public void SetStatusLost()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-25 00:32:42 +02:00
|
|
|
|
if (statusLost)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
statusLost = true;
|
2018-07-25 00:32:42 +02:00
|
|
|
|
RefreshCellContent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-25 00:32:42 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void buttonJoinLeave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (buttonJoinLeave.Text == Messages.AD_JOIN_DOMAIN)
|
|
|
|
|
{
|
|
|
|
|
// We're enabling AD
|
2018-07-27 14:16:01 +02:00
|
|
|
|
// Obtain domain, username and password; store the domain and username
|
|
|
|
|
// so the user won't have to retype it for future join attempts
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 14:16:01 +02:00
|
|
|
|
using (var joinPrompt = new AdPasswordPrompt(true)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{ Domain = _storedDomain, Username = _storedUsername })
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-27 14:16:01 +02:00
|
|
|
|
var result = joinPrompt.ShowDialog(this);
|
|
|
|
|
_storedDomain = joinPrompt.Domain;
|
|
|
|
|
_storedUsername = joinPrompt.Username;
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2018-07-27 19:23:33 +02:00
|
|
|
|
new EnableAdAction(_connection, joinPrompt.Domain, joinPrompt.Username, joinPrompt.Password).RunAsync();
|
2018-07-27 14:16:01 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// We're disabling AD
|
|
|
|
|
|
|
|
|
|
// Warn if the user will boot himself out by disabling AD
|
2018-07-27 19:18:05 +02:00
|
|
|
|
Session session = _connection.Session;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (session == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (session.IsLocalSuperuser)
|
|
|
|
|
{
|
|
|
|
|
// User is authenticated using local root account. Confirm anyway.
|
|
|
|
|
string msg = string.Format(Messages.AD_LEAVE_CONFIRM,
|
2018-07-27 19:18:05 +02:00
|
|
|
|
Helpers.GetName(_connection).Ellipsise(50).EscapeAmpersands(), Domain.Ellipsise(30));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-06-20 11:49:12 +02:00
|
|
|
|
DialogResult r;
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new NoIconDialog(msg,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2020-04-22 15:47:03 +02:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{ WindowTitle = Messages.AD_FEATURE_NAME })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
|
|
|
|
r = dlg.ShowDialog(this);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
|
|
|
|
if (r != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Warn user will be booted out.
|
2018-07-27 19:18:05 +02:00
|
|
|
|
string msg = string.Format(Helpers.GetPool(_connection) != null ? Messages.AD_LEAVE_WARNING : Messages.AD_LEAVE_WARNING_HOST,
|
|
|
|
|
Helpers.GetName(_connection).Ellipsise(50), Domain.Ellipsise(30));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-06-20 11:49:12 +02:00
|
|
|
|
DialogResult r;
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new WarningDialog(msg,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2020-04-22 15:47:03 +02:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{ WindowTitle = Messages.ACTIVE_DIRECTORY_TAB_TITLE })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
|
|
|
|
r = dlg.ShowDialog(this);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
|
|
|
|
if (r != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
Host coordinator = Helpers.GetCoordinator(_connection);
|
|
|
|
|
if (coordinator == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
// Really shouldn't happen unless we have been very slow with the cache
|
2021-08-31 12:31:16 +02:00
|
|
|
|
log.Error("Could not retrieve coordinator when trying to look up domain..");
|
2013-06-24 13:41:48 +02:00
|
|
|
|
throw new Exception(Messages.CONNECTION_IO_EXCEPTION);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
using (var passPrompt = new AdPasswordPrompt(false, coordinator.external_auth_service_name))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-07-27 14:16:01 +02:00
|
|
|
|
var result = passPrompt.ShowDialog(this);
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var creds = new Dictionary<string, string>();
|
|
|
|
|
if (result != DialogResult.Ignore)
|
|
|
|
|
{
|
|
|
|
|
creds.Add(DisableAdAction.KEY_USER, passPrompt.Username);
|
2022-04-12 16:36:01 +02:00
|
|
|
|
creds.Add(DisableAdAction.KEY_PASS, passPrompt.Password);
|
2018-07-27 19:18:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new DisableAdAction(_connection, creds).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 14:05:40 +02:00
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (!buttonAdd.Enabled)
|
|
|
|
|
return;
|
2018-07-25 19:55:33 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
using (var dlog = new ResolvingSubjectsDialog(_connection))
|
2018-07-27 14:16:01 +02:00
|
|
|
|
dlog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Double check, this method is called from a context menu as well and the state could have changed under it
|
|
|
|
|
if (!ButtonRemove.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-11 15:02:35 +02:00
|
|
|
|
var subjectsToRemove = GridViewSubjectList.SelectedRows.Cast<AdSubjectRow>().Select(r => r.subject).ToList();
|
|
|
|
|
if (subjectsToRemove.Count < 1)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
var removeMessage = subjectsToRemove.Count == 1
|
2021-12-01 23:40:16 +01:00
|
|
|
|
? string.Format(Messages.AD_REMOVE_USER_ONE, subjectsToRemove[0].DisplayName ?? subjectsToRemove[0].SubjectName)
|
|
|
|
|
: string.Format(Messages.AD_REMOVE_USER_MANY, subjectsToRemove.Count);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-07-11 15:02:35 +02:00
|
|
|
|
string adminMessage = null;
|
|
|
|
|
var conn = subjectsToRemove.FirstOrDefault(s => s.Connection != null)?.Connection;
|
|
|
|
|
|
|
|
|
|
if (conn != null && Helpers.StockholmOrGreater(conn) && !conn.Cache.Hosts.Any(Host.RestrictPoolSecretRotation))
|
|
|
|
|
{
|
|
|
|
|
var poolAdminsToRemove = (from Subject s in subjectsToRemove
|
2021-11-09 12:18:48 +01:00
|
|
|
|
let roles = s.Connection.ResolveAll(s.roles)
|
|
|
|
|
where roles.Any(r => r.name_label == Role.MR_ROLE_POOL_ADMIN)
|
|
|
|
|
select s).ToList();
|
2020-07-11 15:02:35 +02:00
|
|
|
|
|
|
|
|
|
if (subjectsToRemove.Count == poolAdminsToRemove.Count)
|
|
|
|
|
adminMessage = poolAdminsToRemove.Count == 1
|
|
|
|
|
? Messages.QUESTION_ADMIN_EXIT_PROCEDURE_ONE
|
|
|
|
|
: Messages.QUESTION_ADMIN_EXIT_PROCEDURE_MANY;
|
|
|
|
|
else if (poolAdminsToRemove.Count > 0)
|
|
|
|
|
adminMessage = poolAdminsToRemove.Count == 1
|
|
|
|
|
? Messages.QUESTION_ADMIN_EXIT_PROCEDURE_ONE_OF_MANY
|
|
|
|
|
: string.Format(Messages.QUESTION_ADMIN_EXIT_PROCEDURE_SOME_OF_MANY, poolAdminsToRemove.Count);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(adminMessage))
|
|
|
|
|
removeMessage = string.Format("{0}\n\n{1} {2}", removeMessage, adminMessage, Messages.QUESTION_ADMIN_EXIT_PROCEDURE_ADVISORY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var dlg = new WarningDialog(removeMessage,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2020-04-22 15:47:03 +02:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{ WindowTitle = Messages.AD_FEATURE_NAME })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
2020-07-11 15:02:35 +02:00
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-07-11 15:02:35 +02:00
|
|
|
|
if (dlg.ShowDialog(this) != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// Warn if user is revoking his currently-in-use credentials
|
2018-07-27 19:18:05 +02:00
|
|
|
|
Session session = _connection.Session;
|
2020-01-30 01:02:24 +01:00
|
|
|
|
if (session != null && session.SessionSubject != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
foreach (Subject entry in subjectsToRemove)
|
|
|
|
|
{
|
2020-01-30 01:02:24 +01:00
|
|
|
|
if (entry.opaque_ref == session.SessionSubject)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
string subjectName = entry.DisplayName ?? entry.SubjectName;
|
|
|
|
|
if (subjectName == null)
|
|
|
|
|
{
|
|
|
|
|
subjectName = entry.subject_identifier;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
subjectName = subjectName.Ellipsise(256);
|
|
|
|
|
}
|
2021-11-15 12:48:46 +01:00
|
|
|
|
string msg = string.Format(entry.IsGroup ? Messages.AD_CONFIRM_LOGOUT_CURRENT_USER_GROUP : Messages.AD_CONFIRM_LOGOUT_CURRENT_USER,
|
2018-07-27 19:18:05 +02:00
|
|
|
|
subjectName, Helpers.GetName(_connection).Ellipsise(50));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2016-06-20 11:49:12 +02:00
|
|
|
|
DialogResult r;
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new WarningDialog(msg,
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
2020-04-22 15:47:03 +02:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{ WindowTitle = Messages.AD_FEATURE_NAME })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
|
|
|
|
r = dlg.ShowDialog(this);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
|
|
|
|
if (r != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-25 19:55:33 +02:00
|
|
|
|
|
2018-07-27 19:18:05 +02:00
|
|
|
|
var action = new AddRemoveSubjectsAction(_connection, new List<string>(), subjectsToRemove);
|
2018-07-25 19:55:33 +02:00
|
|
|
|
using (var dlog = new ActionProgressDialog(action, ProgressBarStyle.Continuous))
|
2018-07-27 14:16:01 +02:00
|
|
|
|
dlog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GridViewSubjectList_SelectionChanged(object sender, EventArgs e)
|
2018-07-25 19:55:33 +02:00
|
|
|
|
{
|
|
|
|
|
if (!_updateInProgress)
|
|
|
|
|
EnableButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableButtons()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
if (GridViewSubjectList.SelectedRows.Count < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-10-24 00:13:03 +02:00
|
|
|
|
bool adminSelected = false;
|
|
|
|
|
bool allSelectedLoggedIn = true;
|
|
|
|
|
|
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
if (r.IsLocalRootRow)
|
|
|
|
|
adminSelected = true;
|
|
|
|
|
|
|
|
|
|
if (!r.LoggedIn)
|
|
|
|
|
allSelectedLoggedIn = false;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
tTipChangeRole.SuppressTooltip = ButtonChangeRoles.Enabled = !adminSelected;
|
|
|
|
|
tTipChangeRole.SetToolTip(Messages.AD_CANNOT_MODIFY_ROOT);
|
|
|
|
|
|
|
|
|
|
tTipLogoutButton.SuppressTooltip = !adminSelected;
|
2018-10-24 00:13:03 +02:00
|
|
|
|
ButtonLogout.Enabled = !adminSelected && allSelectedLoggedIn;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
tTipRemoveButton.SuppressTooltip = ButtonRemove.Enabled = !adminSelected;
|
|
|
|
|
|
|
|
|
|
toolStripMenuItemChangeRoles.Enabled = ButtonChangeRoles.Enabled;
|
|
|
|
|
toolStripMenuItemLogout.Enabled = ButtonLogout.Enabled;
|
|
|
|
|
toolStripMenuItemRemove.Enabled = ButtonRemove.Enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:32:42 +02:00
|
|
|
|
private void GridViewSubjectList_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0 || e.ColumnIndex != ColumnExpand.Index)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var row = GridViewSubjectList.Rows[e.RowIndex] as AdSubjectRow;
|
|
|
|
|
if (row != null)
|
|
|
|
|
row.ToggleExpandedState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GridViewSubjectList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var row = GridViewSubjectList.Rows[e.RowIndex] as AdSubjectRow;
|
|
|
|
|
if (row != null)
|
|
|
|
|
row.ToggleExpandedState();
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void GridViewSubjectList_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// First of all, the admin row is always displayed at the top.
|
|
|
|
|
AdSubjectRow row1 = (AdSubjectRow)GridViewSubjectList.Rows[e.RowIndex1];
|
|
|
|
|
AdSubjectRow row2 = (AdSubjectRow)GridViewSubjectList.Rows[e.RowIndex2];
|
|
|
|
|
if (row1.IsLocalRootRow)
|
|
|
|
|
{
|
|
|
|
|
e.SortResult = GridViewSubjectList.SortOrder == SortOrder.Ascending ? -1 : 1;
|
|
|
|
|
}
|
|
|
|
|
else if (row2.IsLocalRootRow)
|
|
|
|
|
{
|
|
|
|
|
e.SortResult = GridViewSubjectList.SortOrder == SortOrder.Ascending ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Next we look to see which column we are sorting on
|
|
|
|
|
switch (GridViewSubjectList.SortedColumn.Index)
|
|
|
|
|
{
|
|
|
|
|
case 0: // shouldn't happen (expander column)
|
|
|
|
|
case 1: // Group/individual picture column
|
|
|
|
|
e.SortResult = GroupCompare(row1.subject, row2.subject);
|
|
|
|
|
break;
|
|
|
|
|
case 2: // Name and detail column
|
|
|
|
|
e.SortResult = NameCompare(row1.subject, row2.subject);
|
|
|
|
|
break;
|
|
|
|
|
case 3: // Role Column
|
|
|
|
|
e.SortResult = RoleCompare(row1.subject, row2.subject);
|
|
|
|
|
break;
|
|
|
|
|
case 4: // Logged in column
|
|
|
|
|
e.SortResult = LoggedInCompare(row1, row2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int RoleCompare(Subject s1, Subject s2)
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
List<Role> s1Roles = _connection.ResolveAll(s1.roles);
|
|
|
|
|
List<Role> s2Roles = _connection.ResolveAll(s2.roles);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
s1Roles.Sort();
|
|
|
|
|
s2Roles.Sort();
|
|
|
|
|
// If one subject doesn't have any roles, but it below the one with roles
|
|
|
|
|
if (s1Roles.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
if (s2Roles.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (s2Roles.Count < 1)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return s1Roles[0].CompareTo(s2Roles[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int NameCompare(Subject s1, Subject s2)
|
|
|
|
|
{
|
|
|
|
|
return StringUtility.NaturalCompare(s1.SubjectName, s2.SubjectName) * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int LoggedInCompare(AdSubjectRow s1, AdSubjectRow s2)
|
|
|
|
|
{
|
|
|
|
|
if (s1.LoggedIn)
|
|
|
|
|
{
|
|
|
|
|
if (s2.LoggedIn)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (s2.LoggedIn)
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GroupCompare(Subject s1, Subject s2)
|
|
|
|
|
{
|
|
|
|
|
if (s1.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
if (s2.IsGroup)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (s2.IsGroup)
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
private static string GetFormattedSubjectList(List<Subject> selectedSubjects)
|
|
|
|
|
{
|
|
|
|
|
var listOfSubjects = string.Join(", ",
|
|
|
|
|
selectedSubjects.Select(sub => sub.DisplayName ?? sub.SubjectName ?? sub.subject_identifier).ToList()
|
|
|
|
|
);
|
|
|
|
|
return listOfSubjects;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void ButtonChangeRoles_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-07-27 19:18:05 +02:00
|
|
|
|
if (Helpers.FeatureForbidden(_connection, Host.RestrictRBAC))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-03-16 02:50:45 +01:00
|
|
|
|
UpsellDialog.ShowUpsellDialog(string.Format(Messages.UPSELL_BLURB_RBAC, BrandManager.ProductBrand), this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Double check, this method is called from a context menu as well and the state could have changed under it
|
|
|
|
|
if (!ButtonChangeRoles.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var selectedRows = GridViewSubjectList.SelectedRows.Cast<AdSubjectRow>().ToList();
|
|
|
|
|
var selectedSubjects = selectedRows.Where(r => !r.IsLocalRootRow).Select(r => r.subject).ToList();
|
|
|
|
|
var loggedInSelectedSubjects = selectedRows.Where(r => !r.IsLocalRootRow && r.LoggedIn).Select(r => r.subject).ToList();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-07-11 15:02:35 +02:00
|
|
|
|
using (var dialog = new RoleSelectionDialog(_connection, selectedSubjects))
|
|
|
|
|
if (dialog.ShowDialog(this) == DialogResult.OK)
|
|
|
|
|
{
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var selectedRoles = dialog.SelectedRoles.OrderBy(x => x).ToList();
|
|
|
|
|
var subjectsToLogout = new List<Subject>();
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var logSelfOut = false;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
foreach (var subject in loggedInSelectedSubjects)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var subjectRoles = subject.roles.Select(_connection.Resolve).OrderBy(x => x).ToList();
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
if (!selectedRoles.SequenceEqual(subjectRoles))
|
2021-12-01 23:40:16 +01:00
|
|
|
|
subjectsToLogout.Add(subject);
|
2021-11-09 12:18:48 +01:00
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (subject.opaque_ref == _connection.Session.SessionSubject)
|
|
|
|
|
logSelfOut = true;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (subjectsToLogout.Count > 0 && !ConfirmLogout(logSelfOut, true, subjectsToLogout))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var actions = new List<AsyncAction>();
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var successfulSubjects = new List<Subject>();
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
foreach (var subject in selectedSubjects)
|
|
|
|
|
{
|
|
|
|
|
var action = new AddRemoveRolesAction(_connection, subject, dialog.SelectedRoles);
|
2021-12-01 23:40:16 +01:00
|
|
|
|
action.Completed += actionBase =>
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (!actionBase.IsCancelled && actionBase.Exception == null)
|
|
|
|
|
successfulSubjects.Add(subject);
|
2021-11-09 12:18:48 +01:00
|
|
|
|
};
|
|
|
|
|
actions.Add(action);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var format = selectedSubjects.Count > 1 ? Messages.AD_ADDING_REMOVING_ROLES_ON_MULTIPLE : Messages.AD_ADDING_REMOVING_ROLES_ON;
|
|
|
|
|
var actionTitle = string.Format(format, GetFormattedSubjectList(selectedSubjects));
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var updateRolesAction = new MultipleAction(_connection, actionTitle, Messages.IN_PROGRESS, Messages.COMPLETED, actions, true, true);
|
2021-12-01 23:40:16 +01:00
|
|
|
|
updateRolesAction.Completed += actionBase => Program.Invoke(this, () =>
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (actionBase.IsCancelled)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return;
|
2021-12-01 23:40:16 +01:00
|
|
|
|
|
|
|
|
|
var successfulSubjectsToLogOut = successfulSubjects.Where(subjectsToLogout.Contains).ToList();
|
|
|
|
|
if (successfulSubjectsToLogOut.Count <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LogoutSubjects(_connection.Session, successfulSubjectsToLogOut);
|
2021-11-09 12:18:48 +01:00
|
|
|
|
});
|
|
|
|
|
updateRolesAction.RunAsync();
|
2020-07-11 15:02:35 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonLogout_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Double check, this method is called from a context menu as well and the state could have changed under it
|
|
|
|
|
if (!ButtonLogout.Enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var session = _connection.Session;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (session == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-10-24 00:13:03 +02:00
|
|
|
|
var subjectsToLogout = new List<Subject>();
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var logSelfOut = false;
|
2018-10-24 00:13:03 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
if (r.IsLocalRootRow || !r.LoggedIn)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
subjectsToLogout.Add(r.subject);
|
2018-10-24 00:13:03 +02:00
|
|
|
|
|
2020-01-30 01:02:24 +01:00
|
|
|
|
if (session.SessionSubject != null && r.subject.opaque_ref == session.SessionSubject)
|
2018-10-24 00:13:03 +02:00
|
|
|
|
logSelfOut = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (subjectsToLogout.Count <= 0 || !ConfirmLogout(logSelfOut, false, subjectsToLogout))
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return;
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
LogoutSubjects(session, subjectsToLogout);
|
2021-11-09 12:18:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
private void LogoutSubjects(Session session, List<Subject> subjectsToLogout)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
// We go through the list and disconnect each user session, doing our own last if necessary
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
var currentSubject = subjectsToLogout.FirstOrDefault(subject => subject.subject_identifier == session.UserSid);
|
|
|
|
|
var otherSubjects = subjectsToLogout.Where(subject => subject.subject_identifier != session.UserSid).ToList();
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (otherSubjects.Count == 0 && currentSubject != null)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
LogOutCurrentSubject(currentSubject);
|
|
|
|
|
return;
|
2021-11-09 12:18:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var actions = otherSubjects.Select(NewLogOutSubjectAction).ToList();
|
|
|
|
|
var format = otherSubjects.Count > 1 ? Messages.TERMINATING_USER_SESSION_MULTIPLE : Messages.TERMINATING_USER_SESSION;
|
|
|
|
|
var actionTitle = string.Format(format, GetFormattedSubjectList(otherSubjects));
|
2021-11-09 12:18:48 +01:00
|
|
|
|
|
|
|
|
|
var logoutAction = new MultipleAction(_connection, actionTitle, Messages.IN_PROGRESS, Messages.COMPLETED, actions, true, true);
|
2021-12-01 23:40:16 +01:00
|
|
|
|
logoutAction.Completed += actionBase => Program.Invoke(this, () =>
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (!(actionBase is MultipleAction ma) || actionBase.IsCancelled)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return;
|
2021-12-01 23:40:16 +01:00
|
|
|
|
|
|
|
|
|
if (currentSubject != null)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
//passing in elevated credentials avoids multiple prompts
|
|
|
|
|
LogOutCurrentSubject(currentSubject, new AsyncAction.SudoElevationResult(ma.sudoUsername, ma.sudoPassword, null));
|
2021-11-09 12:18:48 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// signal the background thread to update the logged in status
|
|
|
|
|
lock (_statusUpdaterLock)
|
|
|
|
|
Monitor.Pulse(_statusUpdaterLock);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
logoutAction.RunAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
private void LogOutCurrentSubject(Subject currentSubject, AsyncAction.SudoElevationResult sudoElevation = null)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var action = NewLogOutSubjectAction(currentSubject);
|
|
|
|
|
action.Completed += actionBase => Program.Invoke(this, () =>
|
|
|
|
|
{
|
2022-03-08 12:37:24 +01:00
|
|
|
|
if (actionBase.IsCancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
//Session.logout_subject_identifier logs out all sessions except the current one,
|
|
|
|
|
//so if an elevated session was not needed, the current session will not have been
|
|
|
|
|
//logged out, hence we need to disconnect explicitly.
|
|
|
|
|
new DisconnectCommand(Program.MainWindow, _connection, false).Run();
|
|
|
|
|
});
|
|
|
|
|
action.RunAsync(sudoElevation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AsyncAction NewLogOutSubjectAction(Subject subject)
|
|
|
|
|
{
|
|
|
|
|
return new DelegatedAsyncAction(_connection,
|
|
|
|
|
string.Format(Messages.TERMINATING_USER_SESSION, subject.DisplayName ?? subject.SubjectName),
|
|
|
|
|
Messages.IN_PROGRESS, Messages.COMPLETED,
|
|
|
|
|
s => Session.logout_subject_identifier(s, subject.subject_identifier),
|
|
|
|
|
"session.logout_subject_identifier");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ConfirmLogout(bool logSelfOut, bool isRoleChange, List<Subject> subjectsToLogout)
|
|
|
|
|
{
|
|
|
|
|
var logoutCurrentSubject = false;
|
|
|
|
|
|
2018-10-24 00:13:03 +02:00
|
|
|
|
if (logSelfOut)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var format =
|
|
|
|
|
isRoleChange
|
|
|
|
|
? subjectsToLogout.Count > 1
|
|
|
|
|
? Messages.AD_LOGOUT_CURRENT_USER_MANY_ROLE_CHANGE
|
|
|
|
|
: Messages.AD_LOGOUT_CURRENT_USER_ONE_ROLE_CHANGE
|
|
|
|
|
: subjectsToLogout.Count > 1
|
|
|
|
|
? Messages.AD_LOGOUT_CURRENT_USER_MANY
|
|
|
|
|
: Messages.AD_LOGOUT_CURRENT_USER_ONE;
|
|
|
|
|
|
|
|
|
|
var warnMsg = string.Format(format, Helpers.GetName(_connection).Ellipsise(50));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new WarningDialog(warnMsg,
|
2021-11-09 12:18:48 +01:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
|
|
|
|
{ WindowTitle = Messages.AD_FEATURE_NAME })
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2018-10-24 00:13:03 +02:00
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
|
|
|
|
if (dlg.ShowDialog(this) != DialogResult.Yes)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-11-15 12:48:46 +01:00
|
|
|
|
logoutCurrentSubject = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 23:40:16 +01:00
|
|
|
|
if (!DisconnectCommand.ConfirmCancelRunningActions(Program.MainWindow, this, _connection, true))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-11-15 12:48:46 +01:00
|
|
|
|
if (!logoutCurrentSubject) //CA-68645
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-12-01 23:40:16 +01:00
|
|
|
|
var logoutMessage =
|
|
|
|
|
isRoleChange
|
|
|
|
|
? subjectsToLogout.Count == 1
|
|
|
|
|
? string.Format(Messages.AD_LOGOUT_USER_ONE_ROLE_CHANGE,
|
|
|
|
|
subjectsToLogout[0].DisplayName ?? subjectsToLogout[0].SubjectName)
|
|
|
|
|
: string.Format(Messages.AD_LOGOUT_USER_MANY_ROLE_CHANGE, subjectsToLogout.Count)
|
|
|
|
|
: subjectsToLogout.Count == 1
|
|
|
|
|
? string.Format(Messages.AD_LOGOUT_USER_ONE,
|
|
|
|
|
subjectsToLogout[0].DisplayName ?? subjectsToLogout[0].SubjectName)
|
|
|
|
|
: string.Format(Messages.AD_LOGOUT_USER_MANY, subjectsToLogout.Count);
|
|
|
|
|
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new WarningDialog(logoutMessage,
|
2021-11-09 12:18:48 +01:00
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true))
|
|
|
|
|
{ WindowTitle = Messages.AD_FEATURE_NAME })
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
2018-10-24 00:13:03 +02:00
|
|
|
|
//CA-64818: DialogResult can be No if the No button has been hit
|
|
|
|
|
//or Cancel if the dialog has been closed from the control box
|
|
|
|
|
if (dlg.ShowDialog(this) != DialogResult.Yes)
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return false;
|
2016-06-20 11:49:12 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 12:18:48 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|