Esempio n. 1
0
 public void OnClickAddButton(object sender, EventArgs e)
 {
     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 if (string.IsNullOrEmpty(TxtDomain.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Domain", "Alert");
     }
     else
     {
         ActiveDirectoryJoinRequestDto = new ActiveDirectoryJoinRequestDto()
         {
             Username           = TxtUsername.StringValue,
             Password           = TxtPassword.StringValue,
             Domain             = TxtDomain.StringValue,
             OrganizationalUnit = TxtOU.StringValue
         };
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
        public void OnClickAddButton(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TxtUsername.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid username", "Alert");
            }
            else if (string.IsNullOrEmpty(TxtDescription.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid Description", "Alert");
            }
            else if (string.IsNullOrEmpty(TxtCertificatePath.StringValue))
            {
                UIErrorHelper.ShowAlert("Please enter valid Certificate", "Alert");
            }
            else
            {
                var cert = new X509Certificate2();
                ActionHelper.Execute(delegate() {
                    cert.Import(TxtCertificatePath.StringValue.Replace("file://", string.Empty));
                });

                SolutionUserDto = new SolutionUserDto()
                {
                    Name        = TxtUsername.StringValue,
                    Description = TxtDescription.StringValue,
                    Certificate = new CertificateDto {
                        Encoded = cert.ExportToPem()
                    }
                };
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(1);
            }
        }
Esempio n. 3
0
 partial void OnConnect(Foundation.NSObject sender)
 {
     ActionHelper.Execute(delegate() {
         if (ConnectPopupButton.SelectedItem.Title != "New Server")
         {
             var server    = ConnectPopupButton.SelectedItem.Title;
             var tokens    = SnapInContext.Instance.AuthTokenManager.GetAllAuthTokens();
             var serverDto = tokens.Where(x => x.ServerDto != null && x.ServerDto.ServerName == server).Select(x => x.ServerDto).FirstOrDefault();
             if (!WebUtil.PingHost(serverDto.ServerName))
             {
                 UIErrorHelper.ShowAlert("Server name or ip address no longer exists or not reachable", "Alert");
                 return;
             }
             else
             {
                 var mainWindowController = new MainWindowController(serverDto);
                 mainWindowController.Window.MakeKeyAndOrderFront(null);
             }
         }
         else
         {
             //var controller = new AddNewServerController ();
             var mainWindowController = new MainWindowController();
             mainWindowController.Window.MakeKeyAndOrderFront(null);
         }
         this.Window.IsVisible = false;
         //this.Close ();
     });
 }
        private bool Save()
        {
            var dto    = ViewToDto();
            var result = false;

            ActionHelper.Execute(delegate {
                if (RdoIdentitySource.Enabled)
                {
                    var auth      = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                    var returnDto = SnapInContext.Instance.ServiceGateway.IdentityProvider.Create(ServerDto, TenantName, dto, auth.Token);
                    if (returnDto != null)
                    {
                        var message = string.Format("External domain {0} created successfully.", returnDto.Name);
                        UIErrorHelper.ShowAlert(message, "Information");
                        this.Close();
                        NSApplication.SharedApplication.StopModalWithCode(0);
                    }
                }
                else
                {
                    var auth      = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                    var returnDto = SnapInContext.Instance.ServiceGateway.IdentityProvider.Update(ServerDto, TenantName, dto, auth.Token);
                    if (returnDto != null)
                    {
                        var message = string.Format("External domain {0} updated successfully.", returnDto.Name);
                        UIErrorHelper.ShowAlert(message, "Information");
                        this.Close();
                        NSApplication.SharedApplication.StopModalWithCode(0);
                    }
                }
                result = true;
            });
            return(result);
        }
        void ImportCertificates(string connection)
        {
            try
            {
                var xcert           = LdapSecureConnectionCertificateFetcher.FetchServerCertificate(connection);
                var cert            = new X509Certificate2(xcert);
                var thumbprint      = cert.GetFormattedThumbPrint();
                var certfificateDto = new CertificateDto {
                    Encoded = cert.ToPem(), Chain = thumbprint
                };

                var exists = _certificates.Exists(x => x.Chain == thumbprint);
                if (exists)
                {
                    UIErrorHelper.ShowAlert("Certificate with the same fingerprint already exists", "Error");
                    return;
                }
                _certificates.Add(certfificateDto);
                ReloadCertificates();
                UIErrorHelper.ShowAlert(string.Format("Certificate with subject {0} imported successfully", cert.Subject), "Information");
            }
            catch (Exception exception)
            {
                UIErrorHelper.ShowAlert(exception.Message, "Error");
            }
        }
Esempio n. 6
0
        void ClearButton_Activated(object sender, EventArgs e)
        {
            var isConfirm = UIErrorHelper.ShowConfirm(ClearConfirmation, "Confirm");

            if (isConfirm)
            {
                if (!_importEventLogs)
                {
                    var auth = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);

                    ActionHelper.Execute(delegate() {
                        var success = SnapInContext.Instance.ServiceGateway.SuperLogging.Delete(ServerDto, TenantName, auth.Token);
                        if (success)
                        {
                            Refresh();
                        }
                        else
                        {
                            UIErrorHelper.ShowAlert(null, FailedToClearEventLogsError);
                        }
                    });
                }
                else
                {
                    _eventLogs.Clear();
                    BindControls(_eventLogs);
                }
                ClearSelectedDetails();
            }
        }
Esempio n. 7
0
 private bool ValidateFilter()
 {
     if (string.IsNullOrWhiteSpace(ValueTextField.StringValue))
     {
         UIErrorHelper.ShowAlert(null, "Filter value cannot be left empty.");
         return(false);
     }
     return(true);
 }
Esempio n. 8
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(TxtEndpoint.StringValue))
                {
                    UIErrorHelper.ShowAlert("Endpoint has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtBinding.StringValue))
                {
                    UIErrorHelper.ShowAlert("Binding has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtIndex.StringValue))
                {
                    UIErrorHelper.ShowAlert("Index has invalid value", "Alert");
                }
                else if (ChkDefault.StringValue == "1" && DefaultSet && (AssertionConsumerServiceDto != null && !AssertionConsumerServiceDto.IsDefault))
                {
                    UIErrorHelper.ShowAlert("Multiple assertion consumer services chosen as default", "Alert");
                }
                else
                {
                    AssertionConsumerServiceDto = new AssertionConsumerServiceDto
                    {
                        Name      = TxtName.StringValue,
                        Endpoint  = TxtEndpoint.StringValue,
                        Binding   = TxtBinding.StringValue,
                        Index     = TxtIndex.IntValue,
                        IsDefault = ChkDefault.StringValue == "1"
                    };
                    IsUpdated = true;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(0);
                }
            };
            this.BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };

            if (AssertionConsumerServiceDto != null)
            {
                TxtIndex.IntValue       = AssertionConsumerServiceDto.Index;
                TxtName.StringValue     = AssertionConsumerServiceDto.Name;
                TxtEndpoint.StringValue = AssertionConsumerServiceDto.Endpoint;
                TxtBinding.StringValue  = AssertionConsumerServiceDto.Binding;
            }
        }
Esempio n. 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);
                }
            });
        }
Esempio n. 10
0
 public void OnClickAddButton(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TxtUserName.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid username", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtFirstName.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid First Name", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtLastName.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Last name", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtEmail.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Email", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtDescription.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Description", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtPassword.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Password", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtConfirmPassword.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Confirm Password", "Alert");
     }
     else if (TxtPassword.StringValue != TxtConfirmPassword.StringValue)
     {
         UIErrorHelper.ShowAlert("Password and confirm password values do not match", "Alert");
     }
     else
     {
         UserDto = new UserDto()
         {
             Name          = TxtUserName.StringValue,
             PersonDetails = new PersonUserDto {
                 FirstName    = TxtFirstName.StringValue,
                 LastName     = TxtLastName.StringValue,
                 EmailAddress = TxtEmail.StringValue,
                 Description  = TxtDescription.StringValue
             },
             PasswordDetails = new PasswordDetailsDto {
                 Password = TxtPassword.StringValue
             }
         };
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
        public void OnClickSaveButton(object sender, EventArgs e)
        {
            ActionHelper.Execute(delegate() {
                if (string.IsNullOrEmpty(TxtUrl.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Url", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtCertificate.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Certificate path", "Alert");
                }                 /*else if (RelyingPartyDto.SignatureAlgorithms.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one signature algorithm", "Alert");
                                   * } else if (RelyingPartyDto.AssertionConsumerServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one assertion consumer service", "Alert");
                                   * } else if (RelyingPartyDto.AttributeConsumerServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one attribute consumer service", "Alert");
                                   * } else if (RelyingPartyDto.SingleLogoutServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one single logout service", "Alert");
                                   * }*/
                else if (!string.IsNullOrEmpty(TxtCertificate.StringValue) && TxtCertificate.StringValue != "Certificate" &&
                         !System.IO.File.Exists(TxtCertificate.StringValue.Replace("file://", string.Empty)))
                {
                    UIErrorHelper.ShowAlert("Certificate path is not valid", "Alert");
                }
                else
                {
                    var encoded = string.Empty;
                    var cert    = new X509Certificate2();
                    ActionHelper.Execute(delegate() {
                        if (TxtCertificate.StringValue == "Certificate")
                        {
                            encoded = _certificate.ToPem();
                        }
                        else
                        {
                            cert.Import(TxtCertificate.StringValue.Replace("file://", string.Empty));
                            encoded = cert.ToPem();
                        }

                        RelyingPartyDto.Name        = RelyingPartyDtoOriginal.Name;
                        RelyingPartyDto.Certificate = new CertificateDto {
                            Encoded = encoded
                        };
                        RelyingPartyDto.Url = TxtUrl.StringValue;

                        var auth        = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                        RelyingPartyDto = SnapInContext.Instance.ServiceGateway.RelyingParty.Update(ServerDto, TenantName, RelyingPartyDto, auth.Token);

                        NSNotificationCenter.DefaultCenter.PostNotificationName("RefreshTableView", this);
                    });
                }
            });
        }
Esempio n. 12
0
        public void OnClickAddButton(object sender, EventArgs e)
        {
            ActionHelper.Execute(delegate() {
                if (string.IsNullOrEmpty(TxtName.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid name", "Alert");
                }
                else if (!string.IsNullOrEmpty(TxtName.StringValue) && TxtName.StringValue.Contains("/"))
                {
                    UIErrorHelper.ShowAlert("Relying party name contains and invalid character.", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtUrl.StringValue))
                {
                    UIErrorHelper.ShowAlert("Please enter valid Url", "Alert");
                }                 /*else if (string.IsNullOrEmpty (TxtCertificate.StringValue)) {
                                   *    UIErrorHelper.ShowAlert ("Please enter valid Certificate path", "Alert");
                                   * } else if (RelyingPartyDto.SignatureAlgorithms.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one signature algorithm", "Alert");
                                   * } else if (RelyingPartyDto.AssertionConsumerServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one assertion consumer service", "Alert");
                                   * } else if (RelyingPartyDto.AttributeConsumerServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one attribute consumer service", "Alert");
                                   * } else if (RelyingPartyDto.SingleLogoutServices.Count == 0) {
                                   *    UIErrorHelper.ShowAlert ("Please add atleast one single logout service", "Alert");
                                   * }*/
                else if (!string.IsNullOrEmpty(TxtCertificate.StringValue))
                {
                    if (!System.IO.File.Exists(TxtCertificate.StringValue.Replace("file://", string.Empty)))
                    {
                        UIErrorHelper.ShowAlert("Certificate path is not valid", "Alert");
                    }
                    else
                    {
                        var cert = new X509Certificate2();
                        ActionHelper.Execute(delegate() {
                            cert.Import(TxtCertificate.StringValue.Replace("file://", string.Empty));
                        });
                        RelyingPartyDto.Name        = TxtName.StringValue;
                        RelyingPartyDto.Certificate = new CertificateDto {
                            Encoded = cert.ToPem()
                        };
                        RelyingPartyDto.Url = TxtUrl.StringValue;

                        var auth        = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
                        RelyingPartyDto = SnapInContext.Instance.ServiceGateway.RelyingParty.Create(ServerDto, Tenant, RelyingPartyDto, auth.Token);
                        SaveSuccessful  = true;
                        this.Close();
                        NSApplication.SharedApplication.StopModalWithCode(1);
                    }
                }
            });
        }
 private bool IsValid()
 {
     if (IdentityProviderDto.Schema[ObjectId.ObjectIdUser.ToString()].AttributeMappings.Count > 0 &&
         string.IsNullOrEmpty(UserClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("User class name cannot be empty", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdPasswordSettings.ToString()].AttributeMappings.Count > 0 &&
              string.IsNullOrEmpty(TxtPasswordClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Password class name cannot be empty", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdDomain.ToString()].AttributeMappings.Count > 0 &&
              string.IsNullOrEmpty(TxtDomainClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Domain class name cannot be empty", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdGroup.ToString()].AttributeMappings.Count > 0 &&
              string.IsNullOrEmpty(TxtGroupClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Group class name cannot be empty", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdUser.ToString()].AttributeMappings.Count == 0 &&
              !string.IsNullOrEmpty(UserClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("User class name cannot exist without any schema mapping", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdPasswordSettings.ToString()].AttributeMappings.Count == 0 &&
              !string.IsNullOrEmpty(TxtPasswordClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Password class name cannot exist without any schema mapping", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdDomain.ToString()].AttributeMappings.Count == 0 &&
              !string.IsNullOrEmpty(TxtDomainClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Domain class name cannot exist without any schema mapping", "Alert");
         return(false);
     }
     else if (IdentityProviderDto.Schema[ObjectId.ObjectIdGroup.ToString()].AttributeMappings.Count == 0 &&
              !string.IsNullOrEmpty(TxtGroupClassName.StringValue))
     {
         UIErrorHelper.ShowAlert("Group class name cannot exist without any schema mapping", "Alert");
         return(false);
     }
     return(true);
 }
Esempio n. 14
0
 void TestConnection(object sender, EventArgs e)
 {
     ActionHelper.Execute(delegate {
         var dto       = ViewToDto();
         var auth      = SnapInContext.Instance.AuthTokenManager.GetAuthToken(ServerDto.ServerName);
         var returnDto = SnapInContext.Instance.ServiceGateway.IdentityProvider.Probe(ServerDto, TenantName, dto, auth.Token);
         if (returnDto != null)
         {
             var message = string.Format("Test connection successful.", returnDto.Name);
             UIErrorHelper.ShowAlert(message, "Information");
         }
     });
 }
 public void OnClickOkButton(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TXTTenantName.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid tenant name", "Alert");
     }
     else
     {
         TenantDto = new TenantDto {
             Name = TXTTenantName.StringValue
         };
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            IsUpdated = false;

            //Events
            this.BtnAdd.Activated += (object sender, EventArgs e) => {
                if (string.IsNullOrEmpty(TxtMaxKeySize.StringValue))

                {
                    UIErrorHelper.ShowAlert("Max Key size has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtMinKeySize.StringValue))
                {
                    UIErrorHelper.ShowAlert("Min Key size has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtPriority.StringValue))
                {
                    UIErrorHelper.ShowAlert("Priority has invalid value", "Alert");
                }
                else
                {
                    SignatureAlgorithmDto = new SignatureAlgorithmDto
                    {
                        MaxKeySize = TxtMaxKeySize.IntValue,
                        MinKeySize = TxtMinKeySize.IntValue,
                        Priority   = TxtPriority.IntValue,
                    };
                    IsUpdated = true;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(0);
                }
            };
            this.BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };


            if (SignatureAlgorithmDto != null)
            {
                TxtMaxKeySize.IntValue = SignatureAlgorithmDto.MaxKeySize;
                TxtMinKeySize.IntValue = SignatureAlgorithmDto.MinKeySize;
                TxtPriority.IntValue   = SignatureAlgorithmDto.Priority;
            }
        }
        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(TxtBinding.StringValue))
                {
                    UIErrorHelper.ShowAlert("Binding has invalid value", "Alert");
                }
                else if (string.IsNullOrEmpty(TxtEndpoint.StringValue))
                {
                    UIErrorHelper.ShowAlert("Endpoint has invalid value", "Alert");
                }
                else
                {
                    ServiceEndpointDto = new ServiceEndpointDto
                    {
                        Name     = TxtName.StringValue,
                        Binding  = TxtBinding.StringValue,
                        Endpoint = TxtEndpoint.StringValue
                    };
                    IsUpdated = true;
                    this.Close();
                    NSApplication.SharedApplication.StopModalWithCode(0);
                }
            };
            this.BtnClose.Activated += (object sender, EventArgs e) => {
                this.Close();
                NSApplication.SharedApplication.StopModalWithCode(0);
            };

            if (ServiceEndpointDto != null)
            {
                TxtName.StringValue     = ServiceEndpointDto.Name;
                TxtEndpoint.StringValue = ServiceEndpointDto.Endpoint;
                TxtBinding.StringValue  = ServiceEndpointDto.Binding;
            }
        }
 private bool IsSloServiceValid()
 {
     if (string.IsNullOrEmpty(TxtSloName.StringValue))
     {
         UIErrorHelper.ShowAlert("Slo service name cannot be empty", "Alert");
         return(false);
     }
     else if (string.IsNullOrEmpty(TxtSloBinding.StringValue))
     {
         UIErrorHelper.ShowAlert("Slo service binding cannot be empty", "Alert");
         return(false);
     }
     else if (string.IsNullOrEmpty(TxtSloEndpoint.StringValue))
     {
         UIErrorHelper.ShowAlert("Slo service endpoint cannot be empty", "Alert");
         return(false);
     }
     return(true);
 }
Esempio n. 19
0
        void UpdateButton_Activated(object sender, EventArgs e)
        {
            var isValid = ValidateFilter();

            if (isValid)
            {
                FilterColumn col            = new FilterColumn();
                Operator     oper           = new Operator();
                var          selColumnValue = ColumnComboBox.SelectedValue as NSString;
                var          column         = (FilterColumn)col.GetByDescription(selColumnValue.ToString());

                var selOpValue = OperatorComboBox.SelectedValue as NSString;
                var op         = (Operator)oper.GetByDescription(selOpValue.ToString());
                var criteria   = new FilterCriteriaDto
                {
                    Column   = column,
                    Operator = op,
                    Value    = ValueTextField.StringValue
                };

                var isDuplicate = IsDuplicate(criteria);

                if (!isDuplicate)
                {
                    var row = (int)FilterTableView.SelectedRow;
                    if (row > -1)
                    {
                        Filters [row] = criteria;
                        RefreshGrid(Filters);
                        ValueTextField.StringValue = (NSString)string.Empty;
                    }
                }
                else
                {
                    UIErrorHelper.ShowAlert(null, "You are trying to add a duplicate filter.");
                }
            }
            SetDeleteButtonStatus();
            SetUpdateButtonStatus();
            SetAddButtonStatus();
        }
Esempio n. 20
0
        void ImportButton_Activated(object sender, EventArgs e)
        {
            if (_autoRefresh)
            {
                UIErrorHelper.ShowAlert(null, ImportSwitchoffWarning);
                return;
            }

            var proceed = true;
            var ds      = EventsLogTableView.DataSource as SuperLogDataSource;

            if (ds != null && ds.Entries.Count > 0)
            {
                proceed = UIErrorHelper.ShowConfirm(LoseEventLogsConfirm, "Confirm");
            }

            if (proceed)
            {
                ActionHelper.Execute(delegate
                {
                    var timestamp  = DateTime.Now.ToString(TimestampFormat);
                    var openDialog = new NSOpenPanel
                    {
                        AllowedFileTypes        = new string[] { "json" },
                        Title                   = SelectFileTitle,
                        AllowsMultipleSelection = false
                    };

                    var result = openDialog.RunModal();
                    if (result == 1)
                    {
                        var filepath          = openDialog.Url.AbsoluteString.Replace("file://", string.Empty);
                        var json              = File.ReadAllText(filepath);
                        _eventLogs            = JsonConvert.JsonDeserialize <List <EventLogDto> >(json);
                        var filteredEventLogs = ServiceHelper.ApplyFilter(_eventLogs, _filters);
                        BindControls(filteredEventLogs);
                    }
                });
                _importEventLogs = true;
            }
        }
Esempio n. 21
0
        public void OnClickBrowseButton(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();
                try {
                    cert.Import(filePath);
                } catch (Exception) {
                    UIErrorHelper.ShowAlert("Invalid X509 certificate", "Alert");
                }
                TxtCertificate.StringValue = filePath;
            }
        }
        public void OnClickAddButton(object sender, EventArgs e)
        {
            var activeDirectoryJoinRequestDto = new ActiveDirectoryJoinRequestDto()
            {
                Username           = TxtUsername.StringValue,
                Password           = TxtPassword.StringValue,
                Domain             = TxtDomain.StringValue,
                OrganizationalUnit = TxtOU.StringValue
            };
            var success = LeaveActiveDirectory(activeDirectoryJoinRequestDto);

            if (success)
            {
                UIErrorHelper.ShowAlert("AD leave operation was succesful. Please reboot the node.", "Information");
            }
            else
            {
                UIErrorHelper.ShowAlert("AD leave operation failed.", "Information");
                return;
            }
            this.Close();
            NSApplication.SharedApplication.StopModalWithCode(1);
        }
Esempio n. 23
0
 public void OnClickLoginButton(object sender, EventArgs e)
 {
     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
     {
         LoginDto = new LoginDto()
         {
             User       = TxtUsername.StringValue,
             Pass       = TxtPassword.StringValue,
             TenantName = ServerDto.Tenant,
             DomainName = ServerDto.Tenant
         };
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
Esempio n. 24
0
 public void OnClickAddButton(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TxtGroupName.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid group name", "Alert");
     }
     else if (string.IsNullOrEmpty(TxtDescription.StringValue))
     {
         UIErrorHelper.ShowAlert("Please enter valid Description", "Alert");
     }
     else
     {
         GroupDto = new GroupDto()
         {
             GroupName    = TxtGroupName.StringValue,
             GroupDetails = new GroupDetailsDto {
                 Description = TxtDescription.StringValue
             }
         };
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
        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");
                }
            }
        }
        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);
        }
Esempio n. 27
0
        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;
                }
                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;
                }
                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))
                    {
                        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);
                    SnapInContext.Instance.ServiceGateway.Tenant.UpdatePasswordAndLockoutConfig(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();
            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);
                        }
                    }
                });
            };
        }
        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);
                }
            };
        }