333 lines
11 KiB
C#
333 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
using C4IT.API;
|
|
using C4IT.Matrix42.WebClient;
|
|
|
|
using C4IT_CustomerPanel.libs;
|
|
|
|
using static C4IT_CustomerPanel.libs.ConfigClass;
|
|
|
|
namespace C4IT_CustomerPanel.forms.AuthenticationSettings
|
|
{
|
|
internal class cAuthenticationSettingsController : INotifyPropertyChanged
|
|
{
|
|
#region dependency properties
|
|
|
|
#region noPassthrough property
|
|
private bool _noPassthrough = default;
|
|
|
|
public bool noPassthrough
|
|
{
|
|
get { return _noPassthrough; }
|
|
set
|
|
{
|
|
if (value != _noPassthrough)
|
|
{
|
|
_noPassthrough = value;
|
|
OnPropertyChanged(nameof(noPassthrough));
|
|
CheckLogonSettings();
|
|
}
|
|
}
|
|
}
|
|
#endregion noPassthrough property
|
|
|
|
#region noLogonAtAll property
|
|
private bool _noLogonAtAll = default;
|
|
|
|
public bool noLogonAtAll
|
|
{
|
|
get { return _noLogonAtAll; }
|
|
set
|
|
{
|
|
if (value != _noLogonAtAll)
|
|
{
|
|
_noLogonAtAll = value;
|
|
OnPropertyChanged(nameof(noLogonAtAll));
|
|
CheckLogonSettings();
|
|
}
|
|
}
|
|
}
|
|
#endregion noLogonAtAll property
|
|
|
|
#region additionalMethod property
|
|
private enumAlternateAuthMethods _additionalMethod = default;
|
|
|
|
public enumAlternateAuthMethods additionalMethod
|
|
{
|
|
get { return _additionalMethod; }
|
|
set
|
|
{
|
|
if (value != _additionalMethod)
|
|
{
|
|
_additionalMethod = value;
|
|
OnPropertyChanged(nameof(additionalMethod));
|
|
CheckAdditionalMethodsSelection();
|
|
}
|
|
}
|
|
}
|
|
#endregion additionalMethod property
|
|
|
|
#region visibilityLogonMethod property
|
|
private bool _visibilityLogonMethod = default;
|
|
|
|
public bool visibilityLogonMethod
|
|
{
|
|
get { return _visibilityLogonMethod; }
|
|
set
|
|
{
|
|
if (value != _visibilityLogonMethod)
|
|
{
|
|
_visibilityLogonMethod = value;
|
|
OnPropertyChanged(nameof(visibilityLogonMethod));
|
|
CheckLogonSettings();
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityLogonMethod property
|
|
|
|
#region visibilityAdditionalLogonMethodBasic property
|
|
private bool _visibilityAdditionalLogonMethodBasic = default;
|
|
|
|
public bool visibilityAdditionalLogonMethodBasic
|
|
{
|
|
get { return _visibilityAdditionalLogonMethodBasic; }
|
|
set
|
|
{
|
|
if (value != _visibilityAdditionalLogonMethodBasic)
|
|
{
|
|
_visibilityAdditionalLogonMethodBasic = value;
|
|
OnPropertyChanged(nameof(visibilityAdditionalLogonMethodBasic));
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityAdditionalLogonMethodBasic property
|
|
|
|
#region visibilityAdditionalLogonMethodToken property
|
|
private bool _visibilityAdditionalLogonMethodToken = default;
|
|
|
|
public bool visibilityAdditionalLogonMethodToken
|
|
{
|
|
get { return _visibilityAdditionalLogonMethodToken; }
|
|
set
|
|
{
|
|
if (value != _visibilityAdditionalLogonMethodToken)
|
|
{
|
|
_visibilityAdditionalLogonMethodToken = value;
|
|
OnPropertyChanged(nameof(visibilityAdditionalLogonMethodToken));
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityAdditionalLogonMethodToken property
|
|
|
|
#region visibilityAdditionalLogonMethodForms property
|
|
private bool _visibilityAdditionalLogonMethodForms = default;
|
|
|
|
public bool visibilityAdditionalLogonMethodForms
|
|
{
|
|
get { return _visibilityAdditionalLogonMethodForms; }
|
|
set
|
|
{
|
|
if (value != _visibilityAdditionalLogonMethodForms)
|
|
{
|
|
_visibilityAdditionalLogonMethodForms = value;
|
|
OnPropertyChanged(nameof(visibilityAdditionalLogonMethodForms));
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityAdditionalLogonMethodForms property
|
|
|
|
#region visibilityErrorMessage property
|
|
private bool _visibilityErrorMessage = true;
|
|
|
|
public bool visibilityErrorMessage
|
|
{
|
|
get { return _visibilityErrorMessage; }
|
|
set
|
|
{
|
|
if (value != _visibilityErrorMessage)
|
|
{
|
|
_visibilityErrorMessage = value;
|
|
OnPropertyChanged(nameof(visibilityBlurMask));
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityErrorMessage property
|
|
|
|
#region visibilityBlurMask property
|
|
private bool _visibilityBlurMask = false;
|
|
|
|
public bool visibilityBlurMask
|
|
{
|
|
get { return _visibilityBlurMask; }
|
|
set
|
|
{
|
|
if (value != _visibilityBlurMask)
|
|
{
|
|
_visibilityBlurMask = value;
|
|
OnPropertyChanged(nameof(visibilityBlurMask));
|
|
}
|
|
}
|
|
}
|
|
#endregion visibilityBlurMask property
|
|
|
|
#region txtBasicUser property
|
|
private String _txtBasicUser = "imagoverum\\vvogel";
|
|
|
|
public String txtBasicUser
|
|
{
|
|
get { return _txtBasicUser; }
|
|
set
|
|
{
|
|
if (value != _txtBasicUser)
|
|
{
|
|
_txtBasicUser = value;
|
|
OnPropertyChanged(nameof(txtBasicUser));
|
|
}
|
|
}
|
|
}
|
|
#endregion txtErrorMessage property
|
|
|
|
#region txtBasicPassword property
|
|
private String _txtBasicPassword = "Matrix42";
|
|
|
|
public String txtBasicPassword
|
|
{
|
|
get { return _txtBasicPassword; }
|
|
set
|
|
{
|
|
if (value != _txtBasicPassword)
|
|
{
|
|
_txtBasicPassword = value;
|
|
OnPropertyChanged(nameof(txtBasicPassword));
|
|
}
|
|
}
|
|
}
|
|
#endregion txtBasicPassword property
|
|
|
|
#region txtTokenSecret property
|
|
private String _txtTokenSecret = "876543210987";
|
|
|
|
public String txtTokenSecret
|
|
{
|
|
get { return _txtTokenSecret; }
|
|
set
|
|
{
|
|
if (value != _txtTokenSecret)
|
|
{
|
|
_txtTokenSecret = value;
|
|
OnPropertyChanged(nameof(txtTokenSecret));
|
|
}
|
|
}
|
|
}
|
|
#endregion txtTokenSecret property
|
|
|
|
#region txtErrorMessage property
|
|
private String _txtErrorMessage = "You could not be authenticated. Please change your specification to ensure valid authentication.";
|
|
|
|
public String txtErrorMessage
|
|
{
|
|
get { return _txtErrorMessage; }
|
|
set
|
|
{
|
|
if (value != _txtErrorMessage)
|
|
{
|
|
_txtErrorMessage = value;
|
|
OnPropertyChanged(nameof(txtErrorMessage));
|
|
}
|
|
}
|
|
}
|
|
#endregion txtErrorMessage property
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
protected void OnPropertyChanged([CallerMemberName] string name = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
|
|
#endregion dependency properties
|
|
|
|
private bool isDesignMode = true;
|
|
|
|
public cAuthenticationSettingsController()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
public void Init(bool isDesignMode = true)
|
|
{
|
|
this.isDesignMode = isDesignMode;
|
|
visibilityErrorMessage = isDesignMode;
|
|
|
|
if (!isDesignMode)
|
|
{
|
|
var authConfig = ConfigClassV2.Instance.Authentication;
|
|
noPassthrough = authConfig.noPassthrough;
|
|
noLogonAtAll = authConfig.noLogonAtAll;
|
|
additionalMethod = authConfig.additionalMethod;
|
|
|
|
txtBasicUser = authConfig.BasicUsername;
|
|
var strDecodedBasicPassword = PrivateCustomerPanelSecurePassword.Instance.Decode(authConfig.BasicPassword);
|
|
txtBasicPassword = strDecodedBasicPassword;
|
|
|
|
txtTokenSecret = PrivateCustomerPanelSecurePassword.Instance.Decode(authConfig.M42AccessToken);
|
|
}
|
|
|
|
CheckLogonSettings();
|
|
CheckAdditionalMethodsSelection();
|
|
}
|
|
|
|
private void CheckLogonSettings()
|
|
{
|
|
visibilityLogonMethod = !noLogonAtAll || isDesignMode;
|
|
CheckAdditionalMethodsSelection();
|
|
}
|
|
|
|
private void CheckAdditionalMethodsSelection()
|
|
{
|
|
visibilityAdditionalLogonMethodBasic = visibilityLogonMethod && (additionalMethod == enumAlternateAuthMethods.authCredentials) || isDesignMode;
|
|
visibilityAdditionalLogonMethodToken = visibilityLogonMethod && (additionalMethod == enumAlternateAuthMethods.authToken) || isDesignMode;
|
|
visibilityAdditionalLogonMethodForms = visibilityLogonMethod && (additionalMethod == enumAlternateAuthMethods.authForms) || isDesignMode;
|
|
}
|
|
|
|
public void FormsAuthenticationStart()
|
|
{
|
|
visibilityBlurMask = true;
|
|
}
|
|
|
|
public async Task FormsAuthenticationFinished(string AccessToken)
|
|
{
|
|
if (!string.IsNullOrEmpty(AccessToken))
|
|
{
|
|
var m42WebClient = new cM42WebClientV2(MainWindow.MainInstance.ConfigSettings.GetMatrixServer(false), MainWindow.MainInstance.ConfigSettings.GetCultureName(), DisableDNSCache: true);
|
|
m42WebClient.RegisterBearerTokenAuthentication(AccessToken);
|
|
|
|
var _res = await m42WebClient.LogonAsync();
|
|
|
|
}
|
|
|
|
visibilityBlurMask = false;
|
|
}
|
|
|
|
public void SaveSettings()
|
|
{
|
|
var authConfig = ConfigClassV2.Instance.Authentication;
|
|
authConfig.noPassthrough = noPassthrough;
|
|
authConfig.noLogonAtAll = noLogonAtAll;
|
|
authConfig.additionalMethod = additionalMethod;
|
|
authConfig.BasicUsername = txtBasicUser;
|
|
var strEncodedBasicPassword = PrivateCustomerPanelSecurePassword.Instance.Encode(txtBasicPassword);
|
|
authConfig.BasicPassword = strEncodedBasicPassword;
|
|
authConfig.M42AccessToken = PrivateCustomerPanelSecurePassword.Instance.Encode(txtTokenSecret);
|
|
ConfigClassV2.Instance.Save(@"Authentication\*");
|
|
}
|
|
}
|
|
}
|