public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            OidcClientDto = new OidcClientDto {
                ClientId = OidcClientDtoOriginal.ClientId,
                OidcClientMetadataDTO = new OidcClientMetadataDto {
                    RedirectUris           = OidcClientDtoOriginal.OidcClientMetadataDTO.RedirectUris,
                    PostLogoutRedirectUris = OidcClientDtoOriginal.OidcClientMetadataDTO.PostLogoutRedirectUris,
                    CertSubjectDN          = OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN,
                    LogoutUri = OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri,
                    TokenEndpointAuthMethod = OidcClientDtoOriginal.OidcClientMetadataDTO.TokenEndpointAuthMethod
                }
            };

            TxtName.StringValue = OidcClientDtoOriginal.ClientId;
            var authIndex = OidcClientDtoOriginal.OidcClientMetadataDTO.TokenEndpointAuthMethod == "none" ? 0 : 1;

            CbTokenAuthMethod.SelectItem(authIndex);
            TxtLogoutUrl.StringValue = string.IsNullOrEmpty(OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri) ? string.Empty :
                                       OidcClientDtoOriginal.OidcClientMetadataDTO.LogoutUri;
            TxtCertificateDN.StringValue = string.IsNullOrEmpty(OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN) ?
                                           string.Empty : OidcClientDtoOriginal.OidcClientMetadataDTO.CertSubjectDN;
            ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris);
            ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris);

            BtnBrowseCertificate.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);
                        TxtCertificateDN.StringValue = cert.Subject;
                    });
                }
            };

            BtnAddRedirectUri.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Redirect Uri cannot be empty", "Alert");
                    return;
                }
                else if (!WebUtil.IsValidHttpUrl(TxtRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Redirect Uri is invalid", "Alert");
                    return;
                }
                OidcClientDto.OidcClientMetadataDTO.RedirectUris.Add(TxtRedirectUri.StringValue);
                ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris);
                TxtRedirectUri.StringValue = (NSString)string.Empty;
            };

            BtnAddPostLogoutRedirectUri.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtPostLogoutRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Post logout redirect Uri cannot be empty", "Alert");
                    return;
                }
                else if (!WebUtil.IsValidHttpUrl(TxtPostLogoutRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Post logout is invalid", "Alert");
                    return;
                }
                OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Add(TxtPostLogoutRedirectUri.StringValue);
                ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris);
                TxtPostLogoutRedirectUri.StringValue = (NSString)string.Empty;
            };

            BtnRemoveRedirectUri.Activated += (object sender, EventArgs e) => {
                if (RedirectUriTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in RedirectUriTableView.SelectedRows)
                    {
                        OidcClientDto.OidcClientMetadataDTO.RedirectUris.RemoveAt((int)row);
                    }
                    ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris);
                }
            };

            BtnRemovePostLogoutRedirectUri.Activated += (object sender, EventArgs e) => {
                if (PostLogoutRedirectUriTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in PostLogoutRedirectUriTableView.SelectedRows)
                    {
                        OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.RemoveAt((int)row);
                    }
                    ReloadTableView(PostLogoutRedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris);
                }
            };

            this.BtnApply.Activated += (object sender, EventArgs e) => {
                ActionHelper.Execute(delegate() {
                    if (string.IsNullOrEmpty(TxtCertificateDN.StringValue))
                    {
                        UIErrorHelper.ShowAlert("Please choose a valid certificate", "Alert");
                    }
                    else if (string.IsNullOrEmpty(TxtLogoutUrl.StringValue) || !WebUtil.IsValidHttpUrl(TxtLogoutUrl.StringValue))
                    {
                        UIErrorHelper.ShowAlert("Please enter valid logout uri", "Alert");
                    }
                    else if (OidcClientDto.OidcClientMetadataDTO.RedirectUris.Count == 0)
                    {
                        UIErrorHelper.ShowAlert("Please enter a valid redirect URI", "Alert");
                    }
                    else if (OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Count == 0)
                    {
                        UIErrorHelper.ShowAlert("Please enter a valid post logout redirect URI", "Alert");
                    }
                    else
                    {
                        OidcClientDto.OidcClientMetadataDTO.LogoutUri = TxtLogoutUrl.StringValue;
                        OidcClientDto.OidcClientMetadataDTO.TokenEndpointAuthMethod = (NSString)CbTokenAuthMethod.SelectedValue;
                        OidcClientDto.OidcClientMetadataDTO.CertSubjectDN           = TxtCertificateDN.StringValue;
                        var auth      = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                        OidcClientDto = SnapInContext.Instance.ServiceGateway.OidcClient.Update(ServerDto, TenantName, OidcClientDto.ClientId, OidcClientDto.OidcClientMetadataDTO, auth.Token);
                        NSNotificationCenter.DefaultCenter.PostNotificationName("RefreshTableView", this);
                    }
                });
            };
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            DtoToView();

            this.BtnAuthenticationAddCertificate.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(),
                        };
                        TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.TrustedCACertificates.Add(certfificateDto);
                        ReloadCertificates();
                    });
                }
            };

            this.BtnAuthenticationRemoveCertificate.Activated += (object sender, EventArgs e) => {
                if (CertificateTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in CertificateTableView.SelectedRows)
                    {
                        TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.TrustedCACertificates.RemoveAt((int)row);
                    }
                    ReloadCertificates();
                }
            };

            BtnAuthenticationPolicyAddPolicyOid.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtAuthenticationPolicyOid.StringValue))
                {
                    UIErrorHelper.ShowAlert("Policy OID cannot be empty", "Alert");
                    return;
                }
                TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Add(TxtAuthenticationPolicyOid.StringValue);
                ReloadTableView(AuthenticationPolicyOidTableView, TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs);
                TxtAuthenticationPolicyOid.StringValue   = (NSString)string.Empty;
                BtnAuthenticationRemovePolicyOid.Enabled = TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs != null &&
                                                           TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Count > 0;
            };

            BtnAuthenticationRemovePolicyOid.Activated += (object sender, EventArgs e) => {
                if (AuthenticationPolicyOidTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in AuthenticationPolicyOidTableView.SelectedRows)
                    {
                        TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.RemoveAt((int)row);
                    }
                    ReloadTableView(AuthenticationPolicyOidTableView, TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs);
                    BtnAuthenticationRemovePolicyOid.Enabled = TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs != null &&
                                                               TenantConfigurationDto.AuthenticationPolicy.ClientCertificatePolicy.CertPolicyOIDs.Count > 0;
                }
            };

            BtnClose.Activated += (object sender, EventArgs e) => {
                TenantConfigurationDto = null;
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };

            this.BtnSave.Activated += (object sender, EventArgs e) => {
                ActionHelper.Execute(delegate() {
                    ViewToDto();
                    var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                    SnapInContext.Instance.ServiceGateway.Tenant.UpdateConfig(ServerDto, TenantName, TenantConfigurationDto, auth.Token);
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(1);
                });
            };

            this.ChkDisableLogonBanner.Activated += (object sender, EventArgs e) => {
                CheckLogonBanner();
            };
            this.BtnUploadContent.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);

                    ActionHelper.Execute(delegate() {
                        var text = System.IO.File.ReadAllText(filePath);
                        if (!string.IsNullOrEmpty(text))
                        {
                            TxtBrandLogonBanner.StringValue = text;
                        }
                    });
                }
            };
            CheckLogonBanner();
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            ExternalIdentityProviderDto = new ExternalIdentityProviderDto()
            {
                NameIDFormats       = new List <string>(),
                SubjectFormats      = new Dictionary <string, string>(),
                SsoServices         = new List <ServiceEndpointDto>(),
                SloServices         = new List <ServiceEndpointDto>(),
                SigningCertificates = new CertificateChainDto {
                    Certificates = new List <CertificateDto>()
                }
            };

            // Name Id formats
            BtnAddNameIdFormat.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtNameIdFormat.StringValue))
                {
                    UIErrorHelper.ShowAlert("Name Id format cannot be empty", "Alert");
                    return;
                }
                ExternalIdentityProviderDto.NameIDFormats.Add(TxtNameIdFormat.StringValue);
                ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats);
                TxtNameIdFormat.StringValue = (NSString)string.Empty;
            };

            BtnRemoveNameIdFormat.Activated += (object sender, EventArgs e) => {
                if (LstNameIdFormat.SelectedRows.Count > 0)
                {
                    foreach (var row in LstNameIdFormat.SelectedRows)
                    {
                        ExternalIdentityProviderDto.NameIDFormats.RemoveAt((int)row);
                    }
                    ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats);
                }
            };
            ReloadTableView(LstNameIdFormat, ExternalIdentityProviderDto.NameIDFormats);

            // Subject formats
            BtnAddSubjectFormat.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtSubjectFormatName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Subject format name cannot be empty", "Alert");
                    return;
                }
                if (string.IsNullOrEmpty(TxtSubjectFormatValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("Subject format value cannot be empty", "Alert");
                    return;
                }
                if (ExternalIdentityProviderDto.SubjectFormats.ContainsKey(TxtSubjectFormatName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Subject format name already exists", "Alert");
                    return;
                }
                ExternalIdentityProviderDto.SubjectFormats.Add(TxtSubjectFormatName.StringValue, TxtSubjectFormatValue.StringValue);
                ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats);
                TxtSubjectFormatName.StringValue  = (NSString)string.Empty;
                TxtSubjectFormatValue.StringValue = (NSString)string.Empty;
            };

            BtnRemoveSubjectFormat.Activated += (object sender, EventArgs e) => {
                if (LstSubjectFormat.SelectedRows.Count > 0)
                {
                    foreach (var row in LstSubjectFormat.SelectedRows)
                    {
                        var source = LstSubjectFormat.DataSource as DictionaryDataSource;
                        var name   = source.Entries[(int)row];
                        ExternalIdentityProviderDto.SubjectFormats.Remove(name);
                    }
                    ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats);
                }
            };
            ReloadTableView(LstSubjectFormat, ExternalIdentityProviderDto.SubjectFormats);

            // Certificates
            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(),
                        };
                        ExternalIdentityProviderDto.SigningCertificates.Certificates.Add(certfificateDto);
                        ReloadCertificates();
                    });
                }
            };

            BtnRemoveCertificate.Activated += (object sender, EventArgs e) => {
                if (LstCertificates.SelectedRows.Count > 0)
                {
                    foreach (var row in LstCertificates.SelectedRows)
                    {
                        ExternalIdentityProviderDto.SigningCertificates.Certificates.RemoveAt((int)row);
                    }
                    ReloadCertificates();
                }
            };
            ReloadCertificates();

            // Sso Services
            BtnAddSso.Activated    += OnAddSsoServices;
            BtnRemoveSso.Activated += OnRemoveSsoServices;
            InitializeSsoServices();

            // Slo Services
            BtnAddSlo.Activated    += OnAddSloServices;
            BtnRemoveSlo.Activated += OnRemoveSloServices;
            InitializeSloServices();

            this.BtnSave.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtUniqueId.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please choose a Unique Id", "Alert");
                }
                else if (ExternalIdentityProviderDto.NameIDFormats.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose a Name Id format", "Alert");
                }
                else if (ExternalIdentityProviderDto.SubjectFormats.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose a Subject Id format", "Alert");
                }
                else if (ExternalIdentityProviderDto.SsoServices.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose a Sso Service", "Alert");
                }
                else if (ExternalIdentityProviderDto.SloServices.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose a Slo service", "Alert");
                }
                else if (ExternalIdentityProviderDto.SigningCertificates.Certificates.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose a certificate", "Alert");
                }
                else
                {
                    ExternalIdentityProviderDto.EntityID   = TxtUniqueId.StringValue;
                    ExternalIdentityProviderDto.Alias      = TxtAlias.StringValue;
                    ExternalIdentityProviderDto.JitEnabled = ChkJit.StringValue == "1";

                    ActionHelper.Execute(delegate {
                        var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                        SnapInContext.Instance.ServiceGateway.ExternalIdentityProvider.Create(ServerDto, TenantName, ExternalIdentityProviderDto, auth.Token);
                        this.Close();
                        NSApplication.SharedApplication.StopModalWithCode(1);
                    });
                }
            };

            BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };
            BtnViewCertificate.Activated += (object sender, EventArgs e) =>
            {
                if (LstCertificates.SelectedRows.Count > 0)
                {
                    var row         = LstCertificates.SelectedRows.First();
                    var encoded     = ExternalIdentityProviderDto.SigningCertificates.Certificates[(int)row].Encoded;
                    var bytes       = System.Text.Encoding.ASCII.GetBytes(encoded);
                    var certificate = new X509Certificate2(bytes);
                    CertificateService.DisplayX509Certificate2(this, certificate);
                }
            };
        }
Пример #4
0
        private bool CurrentStepIsValid()
        {
            var isAd = IsAdWinSelected();

            if (_currentStep == WizardSteps.Four)
            {
                if (isAd)
                {
                    if (RdoSpn.SelectedRow == 1)
                    {
                        if (string.IsNullOrEmpty(TxtSpn.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Please enter valid Service Principal Name", "Alert");
                            return(false);
                        }
                        else if (string.IsNullOrEmpty(TxtUpn.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Please enter valid User Principal Name", "Alert");
                            return(false);
                        }
                        else if (string.IsNullOrEmpty(TxtPassword.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Please enter valid password", "Alert");
                            return(false);
                        }
                    }
                }
                else if (string.IsNullOrEmpty(TxtUpn.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Username ", "Alert");
                    return(false);
                }
                else if (string.IsNullOrEmpty(TxtPassword.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Password", "Alert");
                    return(false);
                }
            }
            else if (_currentStep == WizardSteps.Two)
            {
                if (string.IsNullOrEmpty(TxtDomainName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Domain Name", "Alert");
                    return(false);
                }
                else if (string.IsNullOrEmpty(TxtFriendlyName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Friendly Name", "Alert");
                    return(false);
                }
                else if (string.IsNullOrEmpty(TxtDomainAlias.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Domain Alias", "Alert");
                    return(false);
                }
                else if (string.IsNullOrEmpty(TxtBaseDnUser.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid User base DN", "Alert");
                    return(false);
                }
                else if (string.IsNullOrEmpty(TxtBaseDnGroups.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Group base DN", "Alert");
                    return(false);
                }
                else if (RdoDomainController.SelectedRow == 1 && string.IsNullOrEmpty(TxtPrimaryConnection.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid LDAP Primary URL", "Alert");
                    return(false);
                }
            }
            else if (_currentStep == WizardSteps.Three)
            {
                if (_certificates.Count() < 1)
                {
                    UIErrorHelper.ShowAlert("Please choose atleast one certificate", "Alert");
                    return(false);
                }
            }
            else if (_currentStep == WizardSteps.One)
            {
                if (RdoIdentitySource.SelectedTag == 1)
                {
                    _domainName = GetDomainName();
                    if (string.IsNullOrEmpty(_domainName))
                    {
                        UIErrorHelper.ShowAlert("Node is not joined to AD", "Alert");
                        return(false);
                    }
                }
            }

            return(true);
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            if (ExternalIdentityProviderDto.NameIDFormats == null)
            {
                ExternalIdentityProviderDto.NameIDFormats = new List <string> ();
            }

            if (ExternalIdentityProviderDto.SubjectFormats == null)
            {
                ExternalIdentityProviderDto.SubjectFormats = new Dictionary <string, string> ();
            }
            if (ExternalIdentityProviderDto.SsoServices == null)
            {
                ExternalIdentityProviderDto.SsoServices = new List <ServiceEndpointDto> ();
            }
            if (ExternalIdentityProviderDto.SloServices == null)
            {
                ExternalIdentityProviderDto.SloServices = new List <ServiceEndpointDto> ();
            }
            if (ExternalIdentityProviderDto.SigningCertificates == null)
            {
                ExternalIdentityProviderDto.SigningCertificates = new CertificateChainDto {
                    Certificates = new List <CertificateDto>()
                }
            }
            ;
            TxtEntityName.StringValue = (NSString)(string.IsNullOrEmpty(ExternalIdentityProviderDto.EntityID) ? string.Empty : ExternalIdentityProviderDto.EntityID);
            TxtAlias.StringValue      = (NSString)(string.IsNullOrEmpty(ExternalIdentityProviderDto.Alias) ? string.Empty : ExternalIdentityProviderDto.Alias);
            BtnJit.StringValue        = ExternalIdentityProviderDto.JitEnabled ? "1" : "0";
            ReloadTableView(NameFormatTableView, ExternalIdentityProviderDto.NameIDFormats);
            ReloadTableView(SubjectFormatTableView, ExternalIdentityProviderDto.SubjectFormats);
            ReloadCertificates();
            InitializeSsoServices();
            InitializeSloServices();

            BtnViewCertificate.Activated += (object sender, EventArgs e) =>
            {
                if (CertificateTableView.SelectedRows.Count > 0)
                {
                    var row         = CertificateTableView.SelectedRows.First();
                    var encoded     = ExternalIdentityProviderDto.SigningCertificates.Certificates[(int)row].Encoded;
                    var bytes       = System.Text.Encoding.ASCII.GetBytes(encoded);
                    var certificate = new X509Certificate2(bytes);
                    CertificateService.DisplayX509Certificate2(this, certificate);
                }
            };

            EditButton.Activated += (object sender, EventArgs e) => {
                ActionHelper.Execute(delegate() {
                    var form = new AddNewExternalIdentityProviderController
                    {
                        ServerDto  = ServerDto,
                        TenantName = TenantName,
                        ExternalIdentityProviderDto = ExternalIdentityProviderDto
                    };
                    var result = NSApplication.SharedApplication.RunModalForWindow(form.Window);
                    if (result == VMIdentityConstants.DIALOGOK)
                    {
                        if (form.ExternalIdentityProviderDto != null)
                        {
                            UIErrorHelper.ShowAlert("External IDP " + form.ExternalIdentityProviderDto.EntityID + " updated successfully", "Information");
                            Refresh(sender, e);
                        }
                    }
                });
            };
        }
Пример #6
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            OidcClientDto = new OidcClientDto {
                OidcClientMetadataDTO = new OidcClientMetadataDto {
                    RedirectUris           = new List <string>(),
                    PostLogoutRedirectUris = new List <string>()
                }
            };
            BtnSelectCertificate.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);
                        TxtCertificateDN.StringValue = cert.Subject;
                    });
                }
            };

            BtnAddRedirectUri.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Redirect Uri cannot be empty", "Alert");
                    return;
                }
                else if (!WebUtil.IsValidHttpUrl(TxtRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Redirect Uri is invalid", "Alert");
                    return;
                }
                OidcClientDto.OidcClientMetadataDTO.RedirectUris.Add(TxtRedirectUri.StringValue);
                ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris);
                TxtRedirectUri.StringValue = (NSString)string.Empty;
            };

            BtnAddPostLogoutRedirectUri.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtPostLogoutRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Post logout redirect Uri cannot be empty", "Alert");
                    return;
                }
                else if (!WebUtil.IsValidHttpUrl(TxtPostLogoutRedirectUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Post logout is invalid", "Alert");
                    return;
                }
                OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Add(TxtPostLogoutRedirectUri.StringValue);
                ReloadTableView(PostLogoutUtiTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris);
                TxtPostLogoutRedirectUri.StringValue = (NSString)string.Empty;
            };

            BtnRemoveRedirectUri.Activated += (object sender, EventArgs e) => {
                if (RedirectUriTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in RedirectUriTableView.SelectedRows)
                    {
                        OidcClientDto.OidcClientMetadataDTO.RedirectUris.RemoveAt((int)row);
                    }
                    ReloadTableView(RedirectUriTableView, OidcClientDto.OidcClientMetadataDTO.RedirectUris);
                }
            };

            BtnRemovePostLogoutRedirectUri.Activated += (object sender, EventArgs e) => {
                if (PostLogoutUtiTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in PostLogoutUtiTableView.SelectedRows)
                    {
                        OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.RemoveAt((int)row);
                    }
                    ReloadTableView(PostLogoutUtiTableView, OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris);
                }
            };

            BtnClose.Activated += (object sender, EventArgs e) => {
                OidcClientDto = null;
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };

            this.BtnSave.Activated += (object sender, EventArgs e) => {
                var value = (NSString)CbAuthTokenMethod.SelectedValue;
                if (value == "private_key_jwt" && string.IsNullOrEmpty(TxtCertificateDN.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please choose a valid certificate", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtLogoutUri.StringValue) || !WebUtil.IsValidHttpUrl(TxtLogoutUri.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid logout uri", "Alert");
                }
                else if (OidcClientDto.OidcClientMetadataDTO.RedirectUris.Count == 0)
                {
                    UIErrorHelper.ShowAlert("Please enter a valid redirect URI", "Alert");
                }
                else if (OidcClientDto.OidcClientMetadataDTO.PostLogoutRedirectUris.Count == 0)
                {
                    UIErrorHelper.ShowAlert("Please enter a valid post logout redirect URI", "Alert");
                }
                else
                {
                    OidcClientDto.OidcClientMetadataDTO.LogoutUri = TxtLogoutUri.StringValue;
                    OidcClientDto.OidcClientMetadataDTO.TokenEndpointAuthMethod = (NSString)CbAuthTokenMethod.SelectedValue;
                    OidcClientDto.OidcClientMetadataDTO.CertSubjectDN           = TxtCertificateDN.StringValue;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(1);
                }
            };

            CbAuthTokenMethod.SelectItem(0);
        }
Пример #7
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            IsUpdated = false;
            //Events
            this.BtnAdd.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Name has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtIndex.StringValue))
                {
                    UIErrorHelper.ShowAlert("Index has invalid value", "Alert");
                }
                else if (ChDefault.StringValue == "1" && DefaultSet && (AttributeConsumerServiceDto != null && !AttributeConsumerServiceDto.IsDefault))
                {
                    UIErrorHelper.ShowAlert("Multiple attribute consumer services chosen as default", "Alert");
                }
                else
                {
                    AttributeConsumerServiceDto = new AttributeConsumerServiceDto
                    {
                        Name       = TxtName.StringValue,
                        Index      = TxtIndex.IntValue,
                        IsDefault  = ChDefault.StringValue == "1",
                        Attributes = (AttributeTableView.DataSource as AttributeDataSource).Entries
                    };
                    IsUpdated = true;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(0);
                }
            };
            this.BtnAddAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtAttributeName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Attribute name cannot be empty", "Alert");
                    return;
                }
                if (string.IsNullOrEmpty(TxtFriendlyName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Attribute friendly name cannot be empty", "Alert");
                    return;
                }
                if (string.IsNullOrEmpty(TxtNameFormat.StringValue))
                {
                    UIErrorHelper.ShowAlert("Attribute name format cannot be empty", "Alert");
                    return;
                }
                var attributeDto = new AttributeDto
                {
                    Name         = TxtAttributeName.StringValue,
                    FriendlyName = TxtFriendlyName.StringValue,
                    NameFormat   = TxtNameFormat.StringValue
                };
                TxtAttributeName.StringValue = string.Empty;
                TxtFriendlyName.StringValue  = string.Empty;
                TxtNameFormat.StringValue    = string.Empty;
                _attributes.Add(attributeDto);
                AttributeTableView.DataSource = new AttributeDataSource {
                    Entries = _attributes
                };
                AttributeTableView.ReloadData();
            };
            this.BtnRemoveAttribute.Activated += (object sender, EventArgs e) => {
                if (AttributeTableView.SelectedRow > -1)
                {
                    _attributes.RemoveAt((int)AttributeTableView.SelectedRow);
                    AttributeTableView.DataSource = new AttributeDataSource {
                        Entries = _attributes
                    };
                    AttributeTableView.ReloadData();
                }
            };
            this.BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };

            if (AttributeConsumerServiceDto != null)
            {
                TxtName.StringValue   = AttributeConsumerServiceDto.Name;
                _attributes           = AttributeConsumerServiceDto.Attributes;
                ChDefault.StringValue = AttributeConsumerServiceDto.IsDefault ? "1" : "0";
                TxtIndex.IntValue     = AttributeConsumerServiceDto.Index;
            }
            InitializeAttributes();
        }
Пример #8
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            _certs = new List <string> ();
            TxtTenantName.Enabled = !UpdateCredentials;
            txtUsername.Enabled   = !UpdateCredentials;
            TxtPassword.Enabled   = !UpdateCredentials;
            if (UpdateCredentials)
            {
                TxtTenantName.StringValue = TenantDto.Name;
            }
            else
            {
                TenantDto = new TenantDto();
            }
            TenantDto.Credentials = new TenantCredentialsDto()
            {
                Certificates = new List <CertificateDto>()
            };

            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);
                        _certs.Add(filePath);
                        var certfificateDto = new CertificateDto {
                            Encoded = cert.ExportToPem(),
                        };
                        TenantDto.Credentials.Certificates.Add(certfificateDto);
                        ReloadCertificates();
                    });
                }
            };

            BtnRemoveCertificate.Activated += (object sender, EventArgs e) => {
                if (CertificateChainTableView.SelectedRows.Count > 0)
                {
                    foreach (var row in CertificateChainTableView.SelectedRows)
                    {
                        _certs.RemoveAt((int)row);
                        TenantDto.Credentials.Certificates.RemoveAt((int)row);
                    }
                    ReloadCertificates();
                }
            };

            BtnBrowsePrivateKey.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);

                    ActionHelper.Execute(delegate() {
                        if (ShaWithRsaSigner.IsPrivateKeyValid(filePath))
                        {
                            var text       = System.IO.File.ReadAllText(filePath);
                            var privateKey = PrivateKeyHelper.ExtractBase64EncodedPayload(text);
                            TxtPrivateKeyPath.StringValue    = filePath;
                            TenantDto.Credentials.PrivateKey = new PrivateKeyDto()
                            {
                                Algorithm = EncrptionAlgorithm.RSA, Encoded = privateKey
                            };
                        }
                        else
                        {
                            UIErrorHelper.ShowAlert("Selected private key is not valid", "Alert");
                        }
                    });
                }
            };

            BtnClose.Activated += (object sender, EventArgs e) => {
                TenantDto = null;
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };
            this.BtnSave.Activated += (object sender, EventArgs e) => {
                if (!UpdateCredentials && string.IsNullOrEmpty(TxtTenantName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid tenant name", "Alert");
                }
                else if (!UpdateCredentials && string.IsNullOrEmpty(txtUsername.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid username", "Alert");
                }
                else if (!UpdateCredentials && string.IsNullOrEmpty(TxtPassword.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid password", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtPrivateKeyPath.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid private key", "Alert");
                }
                else if (_certs.Count < 2)
                {
                    UIErrorHelper.ShowAlert("Please enter atleast 2 valid Certificates", "Alert");
                }
                else
                {
                    TenantDto.Name     = TxtTenantName.StringValue;
                    TenantDto.Username = txtUsername.StringValue;
                    TenantDto.Password = TxtPassword.StringValue;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(1);
                }
            };
        }
Пример #9
0
        public void OnClickAddButton(object sender, EventArgs e)
        {
            ActionHelper.Execute(delegate() {
                if (string.IsNullOrEmpty(TxtServer.StringValue))
                {
                    UIErrorHelper.ShowAlert("Server name cannot be empty", "Alert");
                }
                else if (!WebUtil.PingHost(TxtServer.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid server name or ip address", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtPort.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid server STS port", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtTenant.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid tenant name", "Alert");
                }
                else if (this.CbSaml.StringValue == "1" && string.IsNullOrEmpty(TxtStsEndpoint.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid STS endpoint", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtUsername.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid username", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtPassword.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid password", "Alert");
                }
                else
                {
                    var legacy = this.CbSaml.StringValue == "1";
                    ServerDto  = new ServerDto()
                    {
                        ServerName = TxtServer.StringValue,
                        Port       = TxtPort.StringValue,
                        Tenant     = TxtTenant.StringValue,
                        Protocol   = CbSsl.StringValue == "1" ? "https" : "http",
                        TokenType  = legacy ? TokenType.SAML : TokenType.Bearer,
                        Url        = LblUrl.StringValue,
                        StsUrl     = string.IsNullOrEmpty(TxtStsEndpoint.StringValue) ? string.Empty : TxtStsEndpoint.StringValue
                    };

                    LoginDto = new LoginDto {
                        User       = TxtUsername.StringValue,
                        Pass       = TxtPassword.StringValue,
                        DomainName = TxtTenant.StringValue,
                        TenantName = TxtTenant.StringValue
                    };
                    NSApplication.SharedApplication.StopModalWithCode(1);

//					if(!_changeServer)
//					{
//						var mainWindowController = new MainWindowController (ServerDto);
//						mainWindowController.Window.MakeKeyAndOrderFront (this);
//					}
                }
            });
        }
Пример #10
0
        public void OnClickAddButton(object sender, EventArgs e)
        {
            if (IsValid())
            {
                var serverDto = new ServerDto {
                    ServerName = TxtServer.StringValue,
                    Tenant     = TxtTenant.StringValue,
                    Port       = TxtPort.StringValue,
                    Protocol   = CbSsl.StringValue == "1" ? "https" : "http",
                    TokenType  = CbSaml.StringValue == "1" ? TokenType.SAML : TokenType.Bearer,
                    Url        = LblServerUrl.StringValue,
                    StsUrl     = string.IsNullOrEmpty(TxtStsUrl.StringValue) ? string.Empty : TxtStsUrl.StringValue
                };
                var login = new LoginDto {
                    User       = TxtUsername.StringValue,
                    Pass       = TxtPassword.StringValue,
                    DomainName = TxtDomain.StringValue,
                    TenantName = TxtTenant.StringValue
                };
                try {
                    TxtIDTokenString.StringValue      = string.Empty;
                    TxtAccessTokenString.StringValue  = string.Empty;
                    TxtRefreshTokenString.StringValue = string.Empty;
                    TxtSamlToken.StringValue          = string.Empty;

                    if (CbSaml.StringValue == "0")
                    {
                        if (RdoTypeGroup.SelectedTag == 1)
                        {
                            var auth = SnapInContext.Instance.ServiceGateway.Authentication.Login(serverDto, login, Constants.ClientId);
                            PopulateToken(auth);
                        }
                        else if (RdoTypeGroup.SelectedTag == 2)
                        {
                            var cert = new X509Certificate2(TxtCertificate.StringValue);
                            var rsa  = ShaWithRsaSigner.PrivatePemKeyToRSACryptoServiceProvider(TxtPrivateKey.StringValue);
                            var auth = SnapInContext.Instance.ServiceGateway.JwtTokenService.GetTokenFromCertificate(serverDto, cert, rsa);
                            PopulateToken(auth);
                        }
                    }
                    else
                    {
                        if (RdoTypeGroup.SelectedTag == 1)
                        {
                            var auth  = SnapInContext.Instance.ServiceGateway.SamlTokenService.Authenticate(serverDto, login, Constants.ClientId);
                            var bytes = Convert.FromBase64String(auth.Token.AccessToken);
                            var token = System.Text.Encoding.Default.GetString(bytes);
                            TxtSamlToken.StringValue = token;
                        }
                        else if (RdoTypeGroup.SelectedTag == 2)
                        {
                            var cert  = new X509Certificate2(TxtCertificate.StringValue);
                            var rsa   = ShaWithRsaSigner.PrivatePemKeyToRSACryptoServiceProvider(TxtPrivateKey.StringValue);
                            var token = SnapInContext.Instance.ServiceGateway.SamlTokenService.GetSamlTokenFromCertificate(serverDto, cert, rsa);
                            TxtSamlToken.StringValue = token;
                        }
                        else if (RdoTypeGroup.SelectedTag == 3)
                        {
                            var cert      = new X509Certificate2(TxtCertificate.StringValue);
                            var rsa       = ShaWithRsaSigner.PrivatePemKeyToRSACryptoServiceProvider(TxtPrivateKey.StringValue);
                            var tokenText = System.IO.File.ReadAllText(TxtTokenFile.StringValue);
                            var token     = SnapInContext.Instance.ServiceGateway.SamlTokenService.GetSamlTokenFromToken(serverDto, tokenText, cert, rsa);
                            TxtSamlToken.StringValue = token;
                        }
                    }
                }

                catch (WebException exp)
                {
                    if (CbSaml.StringValue == "1")
                    {
                        if (exp != null && exp.Response != null)
                        {
                            var response = exp.Response as HttpWebResponse;
                            var resp     = new StreamReader(exp.Response.GetResponseStream()).ReadToEnd();
                            UIErrorHelper.ShowAlert(resp, "Error");
                            return;
                        }
                        else
                        {
                            UIErrorHelper.ShowAlert(exp.Message, "Error");
                            return;
                        }
                    }
                    else
                    {
                        if (exp.Response is HttpWebResponse)
                        {
                            var response = exp.Response as HttpWebResponse;
                            if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                            {
                                var resp  = new StreamReader(exp.Response.GetResponseStream()).ReadToEnd();
                                var error = JsonConvert.Deserialize <AuthErrorDto> (resp);
                                if (error != null)
                                {
                                    if (error.Error == AuthError.InvalidToken)
                                    {
                                        UIErrorHelper.ShowAlert("Token Expired", "Error");
                                    }
                                    else
                                    {
                                        UIErrorHelper.ShowAlert(error.Details, "Error");
                                    }
                                }
                            }
                            else
                            {
                                if (response != null && response.StatusCode == HttpStatusCode.BadRequest && response.ContentType == "application/json;charset=UTF-8")
                                {
                                    var resp  = new StreamReader(response.GetResponseStream()).ReadToEnd();
                                    var error = JsonConvert.Deserialize <AuthErrorDto> (resp);
                                    if (resp.Contains(AuthError.InvalidGrant))
                                    {
                                        if (error != null)
                                        {
                                            UIErrorHelper.ShowAlert("Invalid username or password", "Error");
                                        }
                                        else
                                        {
                                            UIErrorHelper.ShowAlert(exp.Message + " Details: " + resp, "Error");
                                        }
                                    }
                                    else
                                    {
                                        UIErrorHelper.ShowAlert(exp.Message + " Details: " + resp, "Error");
                                    }
                                }
                                else if (response != null && response.ContentType == "application/json")
                                {
                                    var resp = new StreamReader(response.GetResponseStream()).ReadToEnd();
                                    UIErrorHelper.ShowAlert(exp.Message + " Details: " + resp, "Error");
                                }
                                else
                                {
                                    UIErrorHelper.ShowAlert(exp.Message, "Error");
                                }
                            }
                        }
                        else
                        {
                            UIErrorHelper.ShowAlert(exp.Message, "Error");
                        }
                    }
                }
                catch (Exception exp)
                {
                    UIErrorHelper.ShowAlert(exp.Message, "Error");
                }
            }
        }
Пример #11
0
        private bool IsValid()
        {
            if (string.IsNullOrEmpty(TxtServer.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid server", "Alert");
                return(false);
            }
            else if (!WebUtil.PingHost(TxtServer.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid server name or ip address", "Alert");
                return(false);
            }
            else if (string.IsNullOrEmpty(TxtTenant.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid tenant name", "Alert");
                return(false);
            }
            else if (string.IsNullOrEmpty(TxtPort.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid port", "Alert");
                return(false);
            }
            else if (this.CbSaml.StringValue == "1" && string.IsNullOrEmpty(TxtStsUrl.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid STS endpoint", "Alert");
                return(false);
            }
            else
            {
                var userCredentialOption = RdoTypeGroup.SelectedTag == 1;
                var certificateOption    = RdoTypeGroup.SelectedTag == 2;
                var tokenOption          = CbSaml.StringValue == "1" && RdoTypeGroup.SelectedTag == 3;
                var certOrtokenOption    = certificateOption || tokenOption;

                if (userCredentialOption && string.IsNullOrEmpty(TxtUsername.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid username", "Alert");
                    return(false);
                }
                else if (userCredentialOption && string.IsNullOrEmpty(TxtDomain.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid domain name", "Alert");
                    return(false);
                }
                else if (userCredentialOption && string.IsNullOrEmpty(TxtPassword.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid password", "Alert");
                    return(false);
                }
                else if (certOrtokenOption && string.IsNullOrEmpty(TxtPrivateKey.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid private key", "Alert");
                    return(false);
                }
                else if (certOrtokenOption && !string.IsNullOrEmpty(TxtPrivateKey.StringValue))
                {
                    try {
                        if (!System.IO.File.Exists(TxtPrivateKey.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Private key file not found", "Alert");
                            return(false);
                        }
                    } catch (Exception exc) {
                        UIErrorHelper.ShowAlert("Private key file - " + exc.Message, "Alert");
                        return(false);
                    }
                }
                else if (certOrtokenOption && string.IsNullOrEmpty(TxtCertificate.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid certificate", "Alert");
                    return(false);
                }
                else if (certOrtokenOption && !string.IsNullOrEmpty(TxtCertificate.StringValue))
                {
                    try {
                        if (!System.IO.File.Exists(TxtCertificate.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Certificate file not found", "Alert");
                            return(false);
                        }
                        else
                        {
                            var cert = new X509Certificate2();
                            cert.Import(TxtCertificate.StringValue);
                        }
                    } catch (Exception exc) {
                        UIErrorHelper.ShowAlert("Certificate file - " + exc.Message, "Alert");
                        return(false);
                    }
                }
                else if (tokenOption && string.IsNullOrEmpty(TxtTokenFile.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid token file", "Alert");
                }
                else if (tokenOption && !string.IsNullOrEmpty(TxtTokenFile.StringValue))
                {
                    try {
                        if (!System.IO.File.Exists(TxtTokenFile.StringValue))
                        {
                            UIErrorHelper.ShowAlert("Token file not found", "Alert");
                            return(false);
                        }
                    } catch (Exception exc) {
                        UIErrorHelper.ShowAlert("Token file - " + exc.Message, "Alert");
                        return(false);
                    }
                }
            }
            return(true);
        }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            this.BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };


            // Attributes
            BtnAddAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtAttributeName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Attribute name cannot be empty", "Alert");
                    return;
                }
                else if (string.IsNullOrEmpty(TxtAttributeValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("Attribute value cannot be empty", "Alert");
                    return;
                }
                IdentityProviderDto.AttributesMap.Add(TxtAttributeName.StringValue, TxtAttributeValue.StringValue);
                ReloadTableView(AttributeMapTableView, IdentityProviderDto.AttributesMap);
                TxtAttributeName.StringValue  = (NSString)string.Empty;
                TxtAttributeValue.StringValue = (NSString)string.Empty;
            };

            BtnRemoveAttribute.Activated += (object sender, EventArgs e) => {
                if (AttributeMapTableView.SelectedRows.Count > 0)
                {
                    foreach (var index in AttributeMapTableView.SelectedRows)
                    {
                        var ds = (AttributeMapTableView.DataSource) as DictionaryDataSource;
                        if (ds != null)
                        {
                            var entry = ds.Entries[(int)index];
                            ds.Datasource.Remove(entry);
                            ds.Entries.RemoveAt((int)index);
                        }
                    }
                    ReloadTableView(AttributeMapTableView, IdentityProviderDto.AttributesMap);
                }
            };

            if (IdentityProviderDto.AttributesMap == null)
            {
                IdentityProviderDto.AttributesMap = new Dictionary <string, string> ();
            }

            if (IdentityProviderDto.Schema == null)
            {
                IdentityProviderDto.Schema = new Dictionary <string, SchemaObjectMappingDto> ();
            }

            ReloadTableView(AttributeMapTableView, IdentityProviderDto.AttributesMap);

            // User Schema
            BtnAddUserSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtUserAttributeValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("User schema attribute name cannot be empty", "Alert");
                    return;
                }
                else if (((int)UsersAttributeList.SelectedIndex) < 0)
                {
                    UIErrorHelper.ShowAlert("User schema attribute value cannot be empty", "Alert");
                    return;
                }
                var key = ObjectId.ObjectIdUser.ToString();
                var ds  = (UsersMapTableView.DataSource) as DictionaryDataSource;
                if (ds != null && ds.Entries.Contains(UsersAttributeList.SelectedValue.ToString()))
                {
                    UIErrorHelper.ShowAlert("User schema attribute by this name already exists.", "Alert");
                    return;
                }
                IdentityProviderDto.Schema[key].AttributeMappings.Add(UsersAttributeList.SelectedValue.ToString(), TxtUserAttributeValue.StringValue);

                ReloadTableView(UsersMapTableView, IdentityProviderDto.Schema[key].AttributeMappings);
                TxtUserAttributeValue.StringValue = (NSString)string.Empty;
                UsersAttributeList.SelectItem((nint)(-1));
            };

            BtnRemoveUserSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (UsersMapTableView.SelectedRows.Count > 0)
                {
                    var ds    = (UsersMapTableView.DataSource) as DictionaryDataSource;
                    var index = UsersMapTableView.SelectedRows.First();
                    var entry = ds.Entries[(int)index];
                    var d     = ObjectId.ObjectIdUser.ToString();
                    IdentityProviderDto.Schema[d].AttributeMappings.Remove(entry);
                    ReloadTableView(UsersMapTableView, IdentityProviderDto.Schema[d].AttributeMappings);
                }
            };
            var desc = ObjectId.ObjectIdUser.ToString();

            if (!IdentityProviderDto.Schema.ContainsKey(desc))
            {
                IdentityProviderDto.Schema.Add(desc, new SchemaObjectMappingDto {
                    AttributeMappings = new Dictionary <string, string>()
                });
            }
            else
            {
                var attribMap = new Dictionary <string, string> ();
                foreach (var item in IdentityProviderDto.Schema[desc].AttributeMappings)
                {
                    UserAttributeId p;
                    if (Enum.TryParse(item.Key, out p))
                    {
                        attribMap.Add(p.GetDescription(), item.Value);
                    }
                }
                IdentityProviderDto.Schema[desc].AttributeMappings = attribMap;
            }
            ReloadTableView(UsersMapTableView, IdentityProviderDto.Schema[desc].AttributeMappings);

            // Password Schema
            BtnAddPasswordSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtPasswordValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("Password schema attribute name cannot be empty", "Alert");
                    return;
                }
                else if (((int)PasswordAttributeList.SelectedIndex) < 0)
                {
                    UIErrorHelper.ShowAlert("Password schema attribute value cannot be empty", "Alert");
                    return;
                }
                var key = ObjectId.ObjectIdPasswordSettings.ToString();
                var ds  = (PasswordTableView.DataSource) as DictionaryDataSource;
                if (ds != null && ds.Entries.Contains(PasswordAttributeList.SelectedValue.ToString()))
                {
                    UIErrorHelper.ShowAlert("Password schema attribute by this name already exists.", "Alert");
                    return;
                }
                IdentityProviderDto.Schema[key].AttributeMappings.Add(PasswordAttributeList.SelectedValue.ToString(), TxtPasswordValue.StringValue);

                ReloadTableView(PasswordTableView, IdentityProviderDto.Schema[key].AttributeMappings);
                TxtPasswordValue.StringValue = (NSString)string.Empty;
                PasswordAttributeList.SelectItem((nint)(-1));
            };

            BtnRemovePasswordSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (PasswordTableView.SelectedRows.Count > 0)
                {
                    var ds    = (PasswordTableView.DataSource) as DictionaryDataSource;
                    var index = PasswordTableView.SelectedRows.First();
                    var entry = ds.Entries[(int)index];
                    var d     = ObjectId.ObjectIdPasswordSettings.ToString();
                    IdentityProviderDto.Schema[d].AttributeMappings.Remove(entry);
                    ReloadTableView(PasswordTableView, IdentityProviderDto.Schema[d].AttributeMappings);
                }
            };
            var desc1 = ObjectId.ObjectIdPasswordSettings.ToString();

            if (!IdentityProviderDto.Schema.ContainsKey(desc1))
            {
                IdentityProviderDto.Schema.Add(desc1, new SchemaObjectMappingDto {
                    AttributeMappings = new Dictionary <string, string> ()
                });
            }
            else
            {
                var attribMap = new Dictionary <string, string> ();
                foreach (var item in IdentityProviderDto.Schema[desc1].AttributeMappings)
                {
                    PasswordAttributeId p;
                    if (Enum.TryParse(item.Key, out p))
                    {
                        attribMap.Add(p.GetDescription(), item.Value);
                    }
                }
                IdentityProviderDto.Schema [desc1].AttributeMappings = attribMap;
            }
            ReloadTableView(PasswordTableView, IdentityProviderDto.Schema[desc1].AttributeMappings);


            // Group Schema
            BtnAddGroupSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtGroupValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("Group schema attribute name cannot be empty", "Alert");
                    return;
                }
                else if (((int)GroupAttributes.SelectedIndex) < 0)
                {
                    UIErrorHelper.ShowAlert("Group schema attribute value cannot be empty", "Alert");
                    return;
                }
                var key = ObjectId.ObjectIdGroup.ToString();
                var ds  = (GroupAttributesTableView.DataSource) as DictionaryDataSource;
                if (ds != null && ds.Entries.Contains(GroupAttributes.SelectedValue.ToString()))
                {
                    UIErrorHelper.ShowAlert("Group schema attribute by this name already exists.", "Alert");
                    return;
                }
                IdentityProviderDto.Schema[key].AttributeMappings.Add(GroupAttributes.SelectedValue.ToString(), TxtGroupValue.StringValue);

                ReloadTableView(GroupAttributesTableView, IdentityProviderDto.Schema[key].AttributeMappings);
                TxtGroupValue.StringValue = (NSString)string.Empty;
                GroupAttributes.SelectItem((nint)(-1));
            };

            BtnRemoveGroupSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (GroupAttributesTableView.SelectedRows.Count > 0)
                {
                    var ds    = (GroupAttributesTableView.DataSource) as DictionaryDataSource;
                    var index = GroupAttributesTableView.SelectedRows.First();
                    var entry = ds.Entries[(int)index];
                    var d     = ObjectId.ObjectIdGroup.ToString();
                    IdentityProviderDto.Schema[d].AttributeMappings.Remove(entry);
                    ReloadTableView(GroupAttributesTableView, IdentityProviderDto.Schema[d].AttributeMappings);
                }
            };
            var desc2 = ObjectId.ObjectIdGroup.ToString();

            if (!IdentityProviderDto.Schema.ContainsKey(desc2))
            {
                IdentityProviderDto.Schema.Add(desc2, new SchemaObjectMappingDto {
                    AttributeMappings = new Dictionary <string, string>()
                });
            }
            else
            {
                var attribMap = new Dictionary <string, string> ();
                foreach (var item in IdentityProviderDto.Schema[desc2].AttributeMappings)
                {
                    GroupAttributeId p;
                    if (Enum.TryParse(item.Key, out p))
                    {
                        attribMap.Add(p.GetDescription(), item.Value);
                    }
                }
                IdentityProviderDto.Schema [desc2].AttributeMappings = attribMap;
            }
            ReloadTableView(GroupAttributesTableView, IdentityProviderDto.Schema[desc2].AttributeMappings);

            // Domain Schema
            BtnAddDomainSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtDomainValue.StringValue))
                {
                    UIErrorHelper.ShowAlert("Domain schema attribute name cannot be empty", "Alert");
                    return;
                }
                else if (((int)DomainList.SelectedIndex) < 0)
                {
                    UIErrorHelper.ShowAlert("Domain schema attribute value cannot be empty", "Alert");
                    return;
                }
                var key = ObjectId.ObjectIdDomain.ToString();
                var ds  = (DomainAttributesTableView.DataSource) as DictionaryDataSource;
                if (ds != null && ds.Entries.Contains(DomainList.SelectedValue.ToString()))
                {
                    UIErrorHelper.ShowAlert("Domain schema attribute by this name already exists.", "Alert");
                    return;
                }
                IdentityProviderDto.Schema[key].AttributeMappings.Add(DomainList.SelectedValue.ToString(), TxtDomainValue.StringValue);
                ReloadTableView(DomainAttributesTableView, IdentityProviderDto.Schema[key].AttributeMappings);
                TxtDomainValue.StringValue = (NSString)string.Empty;
                DomainList.SelectItem((nint)(-1));
            };

            BtnRemoveDomainSchemaAttribute.Activated += (object sender, EventArgs e) => {
                if (DomainAttributesTableView.SelectedRows.Count > 0)
                {
                    var ds    = (DomainAttributesTableView.DataSource) as DictionaryDataSource;
                    var index = DomainAttributesTableView.SelectedRows.First();
                    var entry = ds.Entries[(int)index];
                    var d     = ObjectId.ObjectIdDomain.ToString();
                    IdentityProviderDto.Schema[d].AttributeMappings.Remove(entry);
                    ReloadTableView(DomainAttributesTableView, IdentityProviderDto.Schema[d].AttributeMappings);
                }
            };
            var desc3 = ObjectId.ObjectIdDomain.ToString();

            if (!IdentityProviderDto.Schema.ContainsKey(desc3))
            {
                IdentityProviderDto.Schema.Add(desc3, new SchemaObjectMappingDto {
                    AttributeMappings = new Dictionary <string, string>()
                });
            }
            else
            {
                var attribMap = new Dictionary <string, string> ();
                foreach (var item in IdentityProviderDto.Schema[desc3].AttributeMappings)
                {
                    DomainAttributeId p;
                    if (Enum.TryParse(item.Key, out p))
                    {
                        attribMap.Add(p.GetDescription(), item.Value);
                    }
                }
                IdentityProviderDto.Schema [desc3].AttributeMappings = attribMap;
            }
            ReloadTableView(DomainAttributesTableView, IdentityProviderDto.Schema[desc3].AttributeMappings);

            this.BtnApply.Activated += (object sender, EventArgs e) => {
                if (IsValid())
                {
                    IdentityProviderDto.BaseDnForNestedGroupsEnabled = BtnBaseDnForNestedGroups.StringValue == "1";
                    IdentityProviderDto.DirectGroupsSearchEnabled    = BtnGroupSearch.StringValue == "1";
                    IdentityProviderDto.MatchingRuleInChainEnabled   = BtnMatchRuleInChain.StringValue == "1";

                    var user = ObjectId.ObjectIdUser.ToString();
                    var pass = ObjectId.ObjectIdPasswordSettings.ToString();
                    var grp  = ObjectId.ObjectIdGroup.ToString();
                    var dmn  = ObjectId.ObjectIdDomain.ToString();
                    IdentityProviderDto.Schema [user].ObjectClass = UserClassName.StringValue;
                    IdentityProviderDto.Schema[pass].ObjectClass  = TxtPasswordClassName.StringValue;
                    IdentityProviderDto.Schema[grp].ObjectClass   = TxtGroupClassName.StringValue;
                    IdentityProviderDto.Schema[dmn].ObjectClass   = TxtDomainClassName.StringValue;

                    var schema = new Dictionary <string, SchemaObjectMappingDto>();

                    if (IdentityProviderDto.Schema[user].AttributeMappings.Count > 0)
                    {
                        schema.Add(user, IdentityProviderDto.Schema[user]);
                    }
                    if (IdentityProviderDto.Schema[pass].AttributeMappings.Count > 0)
                    {
                        schema.Add(pass, IdentityProviderDto.Schema[pass]);
                    }
                    if (IdentityProviderDto.Schema[grp].AttributeMappings.Count > 0)
                    {
                        schema.Add(grp, IdentityProviderDto.Schema[grp]);
                    }
                    if (IdentityProviderDto.Schema[dmn].AttributeMappings.Count > 0)
                    {
                        schema.Add(dmn, IdentityProviderDto.Schema[dmn]);
                    }

                    IdentityProviderDto.Schema = new Dictionary <string, SchemaObjectMappingDto>(schema);

                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(1);
                }
            };

            if (IdentityProviderDto.AttributesMap == null)
            {
                IdentityProviderDto.AttributesMap = new Dictionary <string, string>();
            }
            if (IdentityProviderDto.Schema == null)
            {
                IdentityProviderDto.Schema = new Dictionary <string, SchemaObjectMappingDto>();
            }
            DtoToView();
        }