public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();
			_certificates = new List<CertificateDto> ();
			_currentStep = WizardSteps.One;
			SetWizardStep ();
			ReloadCertificates ();

			//Events
			this.BtnTestConnection.Activated += TestConnection;
			this.BtnNext.Activated += OnClickNextButton;
			this.BtnBack.Activated += OnClickBackButton;
			this.BtnAddCertificate.Activated +=	(object sender, EventArgs e) => {
				var openPanel = new NSOpenPanel();
				openPanel.ReleasedWhenClosed = true;
				openPanel.Prompt = "Select file";

				var result = openPanel.RunModal();
				if (result == 1)
				{
					var filePath = openPanel.Url.AbsoluteString.Replace("file://",string.Empty);
					var cert = new X509Certificate2 ();
					ActionHelper.Execute (delegate() {
						cert.Import (filePath);
						var certfificateDto = new CertificateDto { Encoded = cert.ToPem(), Chain = cert.GetFormattedThumbPrint()};
						_certificates.Add(certfificateDto);
						ReloadCertificates();
					});
				}
			};

			this.RdoIdentitySource.Activated += (object sender, EventArgs e) => 
			{
				SetSpnControls();
			};
			this.RdoDomainController.Activated += (object sender, EventArgs e) => 
			{
				var anyDc = RdoDomainController.SelectedTag == 1;
				if(anyDc)
				{
					SetConnectionString();
				}
				else
				{
					TxtLdapConnection.StringValue = (NSString) string.Empty;
				}
				ChkProtect.Enabled = anyDc;
				EnableDisableConnectionString(!anyDc);
			};
			this.BtnRemoveCertificate.Activated += (object sender, EventArgs e) => {
				if (LstCertificates.SelectedRows.Count > 0) {
					foreach (var row in LstCertificates.SelectedRows) {
						_certificates.RemoveAt ((int)row);
					}
					ReloadCertificates();
				}
			};
			this.BtnPrimaryImport.Activated += (object sender, EventArgs e) => {
				
			};

			this.BtnSecondaryImport.Activated += (object sender, EventArgs e) => {

			};
			this.TxtDomainName.Changed += (object sender, EventArgs e) => {
				SetConnectionString();
			};

			this.ChkProtect.Activated += (object sender, EventArgs e) => {
				SetConnectionString();
			};
			this.RdoSpn.Activated += (object sender, EventArgs e) => {
				SetSpnControls();
			};
			BtnPrimaryImport.Enabled = false;
			BtnSecondaryImport.Enabled = false;
			this.TxtPrimaryUrl.Activated += (object sender, EventArgs e) => 
			{
				BtnPrimaryImport.Enabled = this.TxtPrimaryUrl.StringValue!= null && this.TxtPrimaryUrl.StringValue.StartsWith("ldaps://");
			};
			this.TxtSecondaryConnection.Activated += (object sender, EventArgs e) => 
			{
				BtnSecondaryImport.Enabled = this.TxtSecondaryConnection.StringValue!= null && this.TxtSecondaryConnection.StringValue.StartsWith("ldaps://");
			};
			BtnPrimaryImport.Activated += (object sender, EventArgs e) => 
			{
				ImportCertificates(TxtPrimaryUrl.StringValue);
			};
			BtnSecondaryImport.Activated += (object sender, EventArgs e) => 
			{
				ImportCertificates(TxtSecondaryConnection.StringValue);
			};
			if (IdentityProviderDto != null)
				DtoToView ();
			else
				IdentityProviderDto = new IdentityProviderDto ();
			this.BtnAdvanced.Activated += (object sender, EventArgs e) => 
			{
				var form = new ExternalDomainAdvancedSettingsController ()
				{
					IdentityProviderDto = new IdentityProviderDto
					{
						Schema = IdentityProviderDto.Schema == null ? new Dictionary<string, SchemaObjectMappingDto>() :new Dictionary<string, SchemaObjectMappingDto>(IdentityProviderDto.Schema),
						AttributesMap = IdentityProviderDto.AttributesMap == null ?  new Dictionary<string, string>() : new Dictionary<string, string>(IdentityProviderDto.AttributesMap),
						BaseDnForNestedGroupsEnabled = IdentityProviderDto.BaseDnForNestedGroupsEnabled,
						MatchingRuleInChainEnabled = IdentityProviderDto.MatchingRuleInChainEnabled,
						DirectGroupsSearchEnabled = IdentityProviderDto.DirectGroupsSearchEnabled
					}
				};
				var result = NSApplication.SharedApplication.RunModalForWindow (form.Window);

				if(result == 1)
				{
					IdentityProviderDto.Schema = GetSchema(form.IdentityProviderDto.Schema);
					IdentityProviderDto.AttributesMap = new Dictionary<string, string>(form.IdentityProviderDto.AttributesMap);
					IdentityProviderDto.BaseDnForNestedGroupsEnabled = form.IdentityProviderDto.BaseDnForNestedGroupsEnabled;
					IdentityProviderDto.MatchingRuleInChainEnabled = form.IdentityProviderDto.MatchingRuleInChainEnabled;
					IdentityProviderDto.DirectGroupsSearchEnabled = form.IdentityProviderDto.DirectGroupsSearchEnabled;
				}
			};
			SetSpnControls ();
		}
Пример #2
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            _certificates = new List <CertificateDto> ();
            var title = string.Empty;

            if (IdentityProviderDto != null)
            {
                var tag = GetIdFromIdentitySourceType(IdentityProviderDto.Type);

                if (tag == 1)
                {
                    title        = VMIdentityConstants.AD_WIN_AUTH_TITLE;
                    _currentStep = WizardSteps.Four;
                }
                else
                {
                    if (tag == 2)
                    {
                        title = VMIdentityConstants.AD_AS_LDAP_TITLE;
                    }
                    else
                    {
                        title = VMIdentityConstants.OPEN_LDAP_TITLE;
                    }
                    _currentStep = WizardSteps.Two;
                }

                isUpdate = true;
            }
            else
            {
                title        = VMIdentityConstants.NEW_EXTERNAL_DOMAIN_TITLE;
                _currentStep = WizardSteps.One;
                isUpdate     = false;
            }
            this.Window.Title = (NSString)title;
            SetWizardStep();
            ReloadCertificates();

            //Events
            this.BtnTestConnection.Activated += TestConnection;
            this.BtnNext.Activated           += OnClickNextButton;
            this.BtnBack.Activated           += OnClickBackButton;
            this.BtnAddCertificate.Activated += (object sender, EventArgs e) => {
                var openPanel = new NSOpenPanel();
                openPanel.ReleasedWhenClosed = true;
                openPanel.Prompt             = "Select file";

                var result = openPanel.RunModal();
                if (result == 1)
                {
                    var filePath = openPanel.Url.AbsoluteString.Replace("file://", string.Empty);
                    var cert     = new X509Certificate2();
                    ActionHelper.Execute(delegate() {
                        cert.Import(filePath);
                        var certfificateDto = new CertificateDto {
                            Encoded = cert.ExportToPem(), Chain = cert.GetFormattedThumbPrint()
                        };
                        _certificates.Add(certfificateDto);
                        ReloadCertificates();
                    });
                }
            };

            this.RdoIdentitySource.Activated += (object sender, EventArgs e) =>
            {
                SetSpnControls();
            };
            this.RdoDomainController.Activated += (object sender, EventArgs e) =>
            {
                var anyDc = RdoDomainController.SelectedTag == 1;
                if (anyDc)
                {
                    SetConnectionString();
                }
                else
                {
                    TxtLdapConnection.StringValue = (NSString)string.Empty;
                }
                ChkProtect.Enabled = anyDc;
                EnableDisableConnectionString(!anyDc);
            };
            this.BtnRemoveCertificate.Activated += (object sender, EventArgs e) => {
                if (LstCertificates.SelectedRows.Count > 0)
                {
                    foreach (var row in LstCertificates.SelectedRows)
                    {
                        _certificates.RemoveAt((int)row);
                    }
                    ReloadCertificates();
                }
            };
            this.BtnPrimaryImport.Activated += (object sender, EventArgs e) => {
            };

            this.BtnSecondaryImport.Activated += (object sender, EventArgs e) => {
            };
            this.TxtDomainName.Changed        += (object sender, EventArgs e) => {
                SetConnectionString();
            };

            this.ChkProtect.Activated += (object sender, EventArgs e) => {
                SetConnectionString();
            };
            this.RdoSpn.Activated += (object sender, EventArgs e) => {
                SetSpnControls();
            };
            BtnPrimaryImport.Enabled      = false;
            BtnSecondaryImport.Enabled    = false;
            this.TxtPrimaryUrl.Activated += (object sender, EventArgs e) =>
            {
                BtnPrimaryImport.Enabled = this.TxtPrimaryUrl.StringValue != null && this.TxtPrimaryUrl.StringValue.StartsWith("ldaps://");
            };
            this.TxtSecondaryConnection.Activated += (object sender, EventArgs e) =>
            {
                BtnSecondaryImport.Enabled = this.TxtSecondaryConnection.StringValue != null && this.TxtSecondaryConnection.StringValue.StartsWith("ldaps://");
            };
            BtnPrimaryImport.Activated += (object sender, EventArgs e) =>
            {
                ImportCertificates(TxtPrimaryUrl.StringValue);
            };
            BtnSecondaryImport.Activated += (object sender, EventArgs e) =>
            {
                ImportCertificates(TxtSecondaryConnection.StringValue);
            };
            if (IdentityProviderDto != null)
            {
                DtoToView();
            }
            else
            {
                IdentityProviderDto = new IdentityProviderDto();
            }
            this.BtnAdvanced.Activated += (object sender, EventArgs e) =>
            {
                var form = new ExternalDomainAdvancedSettingsController()
                {
                    IdentityProviderDto = new IdentityProviderDto
                    {
                        Schema        = IdentityProviderDto.Schema == null ? new Dictionary <string, SchemaObjectMappingDto>() :new Dictionary <string, SchemaObjectMappingDto>(IdentityProviderDto.Schema),
                        AttributesMap = IdentityProviderDto.AttributesMap == null ?  new Dictionary <string, string>() : new Dictionary <string, string>(IdentityProviderDto.AttributesMap),
                        BaseDnForNestedGroupsEnabled = IdentityProviderDto.BaseDnForNestedGroupsEnabled,
                        MatchingRuleInChainEnabled   = IdentityProviderDto.MatchingRuleInChainEnabled,
                        DirectGroupsSearchEnabled    = IdentityProviderDto.DirectGroupsSearchEnabled
                    }
                };
                var result = NSApplication.SharedApplication.RunModalForWindow(form.Window);

                if (result == 1)
                {
                    IdentityProviderDto.Schema        = GetSchema(form.IdentityProviderDto.Schema);
                    IdentityProviderDto.AttributesMap = new Dictionary <string, string>(form.IdentityProviderDto.AttributesMap);
                    IdentityProviderDto.BaseDnForNestedGroupsEnabled = form.IdentityProviderDto.BaseDnForNestedGroupsEnabled;
                    IdentityProviderDto.MatchingRuleInChainEnabled   = form.IdentityProviderDto.MatchingRuleInChainEnabled;
                    IdentityProviderDto.DirectGroupsSearchEnabled    = form.IdentityProviderDto.DirectGroupsSearchEnabled;
                }
            };
            SetSpnControls();
        }