Esempio n. 1
0
        private async Task OnEditSamlDownPartyValidSubmitAsync(GeneralSamlDownPartyViewModel generalSamlDownParty, EditContext editContext)
        {
            try
            {
                if (generalSamlDownParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalSamlDownParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is SamlClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var samlDownParty = generalSamlDownParty.Form.Model.Map <SamlDownParty>(afterMap =>
                {
                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                if (generalSamlDownParty.CreateMode)
                {
                    var samlDownPartyResult = await DownPartyService.CreateSamlDownPartyAsync(samlDownParty);

                    generalSamlDownParty.Form.UpdateModel(ToViewModel(generalSamlDownParty, samlDownPartyResult));
                    generalSamlDownParty.CreateMode = false;
                    toastService.ShowSuccess("SAML 2.0 Down-party created.", "SUCCESS");
                }
                else
                {
                    var samlDownPartyResult = await DownPartyService.UpdateSamlDownPartyAsync(samlDownParty);

                    generalSamlDownParty.Form.UpdateModel(ToViewModel(generalSamlDownParty, samlDownPartyResult));
                    toastService.ShowSuccess("SAML 2.0 Down-party updated.", "SUCCESS");
                }
                generalSamlDownParty.Name = generalSamlDownParty.Form.Model.Name;
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalSamlDownParty.Form.SetFieldError(nameof(generalSamlDownParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
 private async Task DefaultLoadAsync()
 {
     try
     {
         SetGeneralDownParties(await DownPartyService.FilterDownPartyAsync(null));
     }
     catch (TokenUnavailableException)
     {
         await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
     }
     catch (Exception ex)
     {
         downPartyFilterForm.SetError(ex.Message);
     }
 }
Esempio n. 3
0
        private async Task DeleteOidcDownPartyAsync(GeneralOidcDownPartyViewModel generalOidcDownParty)
        {
            try
            {
                await DownPartyService.DeleteOidcDownPartyAsync(generalOidcDownParty.Name);

                DownParties.Remove(generalOidcDownParty);
                await OnStateHasChanged.InvokeAsync(DownParty);
            }
            catch (TokenUnavailableException)
            {
                await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
            }
            catch (Exception ex)
            {
                generalOidcDownParty.Form.SetError(ex.Message);
            }
        }
Esempio n. 4
0
        private async Task DefaultLoadAsync()
        {
            try
            {
                var generalSamlDownParty = DownParty as GeneralSamlDownPartyViewModel;
                var samlDownParty        = await DownPartyService.GetSamlDownPartyAsync(DownParty.Name);

                await generalSamlDownParty.Form.InitAsync(ToViewModel(generalSamlDownParty, samlDownParty));
            }
            catch (TokenUnavailableException)
            {
                await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
            }
            catch (HttpRequestException ex)
            {
                DownParty.Error = ex.Message;
            }
        }
Esempio n. 5
0
 private async Task OnDownPartyFilterValidSubmitAsync(EditContext editContext)
 {
     try
     {
         SetGeneralDownParties(await DownPartyService.FilterDownPartyAsync(downPartyFilterForm.Model.FilterName));
     }
     catch (FoxIDsApiException ex)
     {
         if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             downPartyFilterForm.SetFieldError(nameof(downPartyFilterForm.Model.FilterName), ex.Message);
         }
         else
         {
             throw;
         }
     }
 }
Esempio n. 6
0
        private async Task OnEditOidcDownPartyValidSubmitAsync(GeneralOidcDownPartyViewModel generalOidcDownParty, EditContext editContext)
        {
            try
            {
                if (generalOidcDownParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalOidcDownParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is OAuthClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var oidcDownParty = generalOidcDownParty.Form.Model.Map <OidcDownParty>(afterMap: afterMap =>
                {
                    if (generalOidcDownParty.Form.Model.Client?.DefaultResourceScope == true)
                    {
                        afterMap.Client.ResourceScopes.Add(new OAuthDownResourceScope {
                            Resource = generalOidcDownParty.Form.Model.Name, Scopes = generalOidcDownParty.Form.Model.Client.DefaultResourceScopeScopes
                        });
                    }
                    if (!(afterMap.Resource?.Scopes?.Count > 0))
                    {
                        afterMap.Resource = null;
                    }
                    if (generalOidcDownParty.Form.Model.Client?.ScopesViewModel?.Count() > 0)
                    {
                        afterMap.Client.Scopes = generalOidcDownParty.Form.Model.Client.ScopesViewModel.Map <List <OidcDownScope> >();
                    }
                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                OidcDownParty oidcDownPartyResult;
                if (generalOidcDownParty.CreateMode)
                {
                    oidcDownPartyResult = await DownPartyService.CreateOidcDownPartyAsync(oidcDownParty);
                }
                else
                {
                    oidcDownPartyResult = await DownPartyService.UpdateOidcDownPartyAsync(oidcDownParty);

                    if (oidcDownParty.Client != null)
                    {
                        foreach (var existingSecret in generalOidcDownParty.Form.Model.Client.ExistingSecrets.Where(s => s.Removed))
                        {
                            await DownPartyService.DeleteOidcClientSecretDownPartyAsync(existingSecret.Name);
                        }
                    }
                }
                if (oidcDownParty.Client != null && generalOidcDownParty.Form.Model.Client.Secrets.Count() > 0)
                {
                    await DownPartyService.CreateOidcClientSecretDownPartyAsync(new OAuthClientSecretRequest { PartyName = generalOidcDownParty.Form.Model.Name, Secrets = generalOidcDownParty.Form.Model.Client.Secrets });
                }

                var oauthDownSecrets = await DownPartyService.GetOAuthClientSecretDownPartyAsync(oidcDownPartyResult.Name);

                generalOidcDownParty.Form.UpdateModel(ToViewModel(generalOidcDownParty, oidcDownPartyResult, oauthDownSecrets));
                if (generalOidcDownParty.CreateMode)
                {
                    generalOidcDownParty.CreateMode = false;
                    toastService.ShowSuccess("OpenID Connect Down-party created.", "SUCCESS");
                }
                else
                {
                    toastService.ShowSuccess("OpenID Connect Down-party updated.", "SUCCESS");
                }
                generalOidcDownParty.Name = generalOidcDownParty.Form.Model.Name;
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalOidcDownParty.Form.SetFieldError(nameof(generalOidcDownParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 7
0
        private async Task ShowUpdateDownPartyAsync(GeneralDownPartyViewModel downParty)
        {
            downParty.CreateMode        = false;
            downParty.DeleteAcknowledge = false;
            downParty.ShowAdvanced      = false;
            downParty.Error             = null;
            downParty.Edit = true;
            if (downParty.Type == PartyTypes.Oidc)
            {
                try
                {
                    var generalOidcDownParty = downParty as GeneralOidcDownPartyViewModel;
                    var oidcDownParty        = await DownPartyService.GetOidcDownPartyAsync(downParty.Name);

                    var oidcDownSecrets = await DownPartyService.GetOidcClientSecretDownPartyAsync(downParty.Name);

                    await generalOidcDownParty.Form.InitAsync(oidcDownParty.Map((Action <OidcDownPartyViewModel>)(afterMap =>
                    {
                        if (afterMap.Client == null)
                        {
                            generalOidcDownParty.EnableClientTab = false;
                        }
                        else
                        {
                            generalOidcDownParty.EnableClientTab = true;
                            afterMap.Client.ExistingSecrets      = oidcDownSecrets.Select(s => new OAuthClientSecretViewModel {
                                Name = s.Name, Info = s.Info
                            }).ToList();
                            var defaultResourceScopeIndex = afterMap.Client.ResourceScopes.FindIndex(r => r.Resource.Equals(generalOidcDownParty.Name, StringComparison.Ordinal));
                            if (defaultResourceScopeIndex > -1)
                            {
                                afterMap.Client.DefaultResourceScope = true;
                                var defaultResourceScope             = afterMap.Client.ResourceScopes[defaultResourceScopeIndex];
                                if (defaultResourceScope.Scopes?.Count() > 0)
                                {
                                    foreach (var scope in defaultResourceScope.Scopes)
                                    {
                                        afterMap.Client.DefaultResourceScopeScopes.Add(scope);
                                    }
                                }
                                afterMap.Client.ResourceScopes.RemoveAt(defaultResourceScopeIndex);
                            }
                            else
                            {
                                afterMap.Client.DefaultResourceScope = false;
                            }

                            afterMap.Client.ScopesViewModel = afterMap.Client.Scopes.Map <List <OidcDownScopeViewModel> >() ?? new List <OidcDownScopeViewModel>();
                        }

                        if (afterMap.Resource == null)
                        {
                            generalOidcDownParty.EnableResourceTab = false;
                        }
                        else
                        {
                            generalOidcDownParty.EnableResourceTab = true;
                        }

                        if (afterMap.ClaimTransforms?.Count > 0)
                        {
                            afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                        }
                    })));
                }
                catch (TokenUnavailableException)
                {
                    await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
                }
                catch (HttpRequestException ex)
                {
                    downParty.Error = ex.Message;
                }
            }
            else if (downParty.Type == PartyTypes.OAuth2)
            {
                try
                {
                    var generalOAuthDownParty = downParty as GeneralOAuthDownPartyViewModel;
                    var oauthDownParty        = await DownPartyService.GetOAuthDownPartyAsync(downParty.Name);

                    var oauthDownSecrets = await DownPartyService.GetOAuthClientSecretDownPartyAsync(downParty.Name);

                    await generalOAuthDownParty.Form.InitAsync(oauthDownParty.Map <OAuthDownPartyViewModel>(afterMap =>
                    {
                        if (afterMap.Client == null)
                        {
                            generalOAuthDownParty.EnableClientTab = false;
                        }
                        else
                        {
                            generalOAuthDownParty.EnableClientTab = true;
                            afterMap.Client.ExistingSecrets       = oauthDownSecrets.Select(s => new OAuthClientSecretViewModel {
                                Name = s.Name, Info = s.Info
                            }).ToList();
                            var defaultResourceScopeIndex = afterMap.Client.ResourceScopes.FindIndex(r => r.Resource.Equals(generalOAuthDownParty.Name, StringComparison.Ordinal));
                            if (defaultResourceScopeIndex > -1)
                            {
                                afterMap.Client.DefaultResourceScope = true;
                                var defaultResourceScope             = afterMap.Client.ResourceScopes[defaultResourceScopeIndex];
                                if (defaultResourceScope.Scopes?.Count() > 0)
                                {
                                    foreach (var scope in defaultResourceScope.Scopes)
                                    {
                                        afterMap.Client.DefaultResourceScopeScopes.Add(scope);
                                    }
                                }
                                afterMap.Client.ResourceScopes.RemoveAt(defaultResourceScopeIndex);
                            }
                            else
                            {
                                afterMap.Client.DefaultResourceScope = false;
                            }

                            afterMap.Client.ScopesViewModel = afterMap.Client.Scopes.Map <List <OAuthDownScopeViewModel> >() ?? new List <OAuthDownScopeViewModel>();
                        }

                        if (afterMap.Resource == null)
                        {
                            generalOAuthDownParty.EnableResourceTab = false;
                        }
                        else
                        {
                            generalOAuthDownParty.EnableResourceTab = true;
                        }

                        if (afterMap.ClaimTransforms?.Count > 0)
                        {
                            afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                        }
                    }));
                }
                catch (TokenUnavailableException)
                {
                    await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
                }
                catch (HttpRequestException ex)
                {
                    downParty.Error = ex.Message;
                }
            }
            else if (downParty.Type == PartyTypes.Saml2)
            {
                try
                {
                    var generalSamlDownParty = downParty as GeneralSamlDownPartyViewModel;
                    var samlDownParty        = await DownPartyService.GetSamlDownPartyAsync(downParty.Name);

                    await generalSamlDownParty.Form.InitAsync(samlDownParty.Map <SamlDownPartyViewModel>(afterMap =>
                    {
                        afterMap.AuthnRequestBinding  = samlDownParty.AuthnBinding.RequestBinding;
                        afterMap.AuthnResponseBinding = samlDownParty.AuthnBinding.ResponseBinding;
                        if (!samlDownParty.LoggedOutUrl.IsNullOrEmpty())
                        {
                            afterMap.LogoutRequestBinding  = samlDownParty.LogoutBinding.RequestBinding;
                            afterMap.LogoutResponseBinding = samlDownParty.LogoutBinding.ResponseBinding;
                        }

                        generalSamlDownParty.CertificateInfoList.Clear();
                        if (afterMap.Keys?.Count() > 0)
                        {
                            foreach (var key in afterMap.Keys)
                            {
                                var certificate = new MTokens.JsonWebKey(key.JsonSerialize()).ToX509Certificate();
                                generalSamlDownParty.CertificateInfoList.Add(new CertificateInfoViewModel
                                {
                                    Subject    = certificate.Subject,
                                    ValidFrom  = certificate.NotBefore,
                                    ValidTo    = certificate.NotAfter,
                                    Thumbprint = certificate.Thumbprint,
                                    Key        = key
                                });
                            }
                        }

                        if (afterMap.ClaimTransforms?.Count > 0)
                        {
                            afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                        }
                    }));
                }
                catch (TokenUnavailableException)
                {
                    await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
                }
                catch (HttpRequestException ex)
                {
                    downParty.Error = ex.Message;
                }
            }
        }
Esempio n. 8
0
        private async Task OnEditSamlDownPartyValidSubmitAsync(GeneralSamlDownPartyViewModel generalSamlDownParty, EditContext editContext)
        {
            try
            {
                if (generalSamlDownParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalSamlDownParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is SamlClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var samlDownParty = generalSamlDownParty.Form.Model.Map <SamlDownParty>(afterMap =>
                {
                    afterMap.AuthnBinding = new SamlBinding {
                        RequestBinding = generalSamlDownParty.Form.Model.AuthnRequestBinding, ResponseBinding = generalSamlDownParty.Form.Model.AuthnResponseBinding
                    };
                    if (!afterMap.LoggedOutUrl.IsNullOrEmpty())
                    {
                        afterMap.LogoutBinding = new SamlBinding {
                            RequestBinding = generalSamlDownParty.Form.Model.LogoutRequestBinding, ResponseBinding = generalSamlDownParty.Form.Model.LogoutResponseBinding
                        };
                    }
                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                if (generalSamlDownParty.CreateMode)
                {
                    await DownPartyService.CreateSamlDownPartyAsync(samlDownParty);
                }
                else
                {
                    await DownPartyService.UpdateSamlDownPartyAsync(samlDownParty);
                }
                generalSamlDownParty.Name = generalSamlDownParty.Form.Model.Name;
                generalSamlDownParty.Edit = false;
                await OnStateHasChanged.InvokeAsync(DownParty);
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalSamlDownParty.Form.SetFieldError(nameof(generalSamlDownParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }