Example #1
0
        private async Task OnEditOidcUpPartyValidSubmitAsync(GeneralOidcUpPartyViewModel generalOidcUpParty, EditContext editContext)
        {
            try
            {
                if (generalOidcUpParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalOidcUpParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is OAuthClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var oidcUpParty = generalOidcUpParty.Form.Model.Map <OidcUpParty>(afterMap: afterMap =>
                {
                    afterMap.UpdateState         = PartyUpdateStates.Automatic;
                    afterMap.DisableSingleLogout = !generalOidcUpParty.Form.Model.EnableSingleLogout;
                    afterMap.Client.DisableFrontChannelLogout = !generalOidcUpParty.Form.Model.Client.EnableFrontChannelLogout;

                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                if (generalOidcUpParty.CreateMode)
                {
                    await UpPartyService.CreateOidcUpPartyAsync(oidcUpParty);
                }
                else
                {
                    await UpPartyService.UpdateOidcUpPartyAsync(oidcUpParty);
                }

                generalOidcUpParty.Name = generalOidcUpParty.Form.Model.Name;
                generalOidcUpParty.Edit = false;
                await OnStateHasChanged.InvokeAsync(UpParty);
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalOidcUpParty.Form.SetFieldError(nameof(generalOidcUpParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Example #2
0
 private async Task DefaultLoadAsync()
 {
     try
     {
         SetGeneralUpParties(await UpPartyService.FilterUpPartyAsync(null));
     }
     catch (TokenUnavailableException)
     {
         await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
     }
     catch (Exception ex)
     {
         upPartyFilterForm.SetError(ex.Message);
     }
 }
Example #3
0
        private async Task DefaultLoadAsync()
        {
            try
            {
                var generalLoginUpParty = UpParty as GeneralLoginUpPartyViewModel;
                var loginUpParty        = await UpPartyService.GetLoginUpPartyAsync(UpParty.Name);

                await generalLoginUpParty.Form.InitAsync(ToViewModel(loginUpParty));
            }
            catch (TokenUnavailableException)
            {
                await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
            }
            catch (HttpRequestException ex)
            {
                UpParty.Error = ex.Message;
            }
        }
Example #4
0
        private async Task DeleteLoginUpPartyAsync(GeneralLoginUpPartyViewModel generalLoginUpParty)
        {
            try
            {
                await UpPartyService.DeleteLoginUpPartyAsync(generalLoginUpParty.Name);

                UpParties.Remove(generalLoginUpParty);
                await OnStateHasChanged.InvokeAsync(UpParty);
            }
            catch (TokenUnavailableException)
            {
                await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
            }
            catch (Exception ex)
            {
                generalLoginUpParty.Form.SetError(ex.Message);
            }
        }
Example #5
0
 private async Task OnUpPartyFilterValidSubmitAsync(EditContext editContext)
 {
     try
     {
         SetGeneralUpParties(await UpPartyService.FilterUpPartyAsync(upPartyFilterForm.Model.FilterName));
     }
     catch (FoxIDsApiException ex)
     {
         if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             upPartyFilterForm.SetFieldError(nameof(upPartyFilterForm.Model.FilterName), ex.Message);
         }
         else
         {
             throw;
         }
     }
 }
Example #6
0
        private async Task OnEditLoginUpPartyValidSubmitAsync(GeneralLoginUpPartyViewModel generalLoginUpParty, EditContext editContext)
        {
            try
            {
                if (generalLoginUpParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalLoginUpParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is OAuthClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                if (generalLoginUpParty.CreateMode)
                {
                    var loginUpPartyResult = await UpPartyService.CreateLoginUpPartyAsync(generalLoginUpParty.Form.Model.Map <LoginUpParty>(afterMap: afterMap =>
                    {
                        afterMap.DisableSingleLogout  = !generalLoginUpParty.Form.Model.EnableSingleLogout;
                        afterMap.DisableResetPassword = !generalLoginUpParty.Form.Model.EnableResetPassword;

                        if (afterMap.ClaimTransforms?.Count() > 0)
                        {
                            int order = 1;
                            foreach (var claimTransform in afterMap.ClaimTransforms)
                            {
                                claimTransform.Order = order++;
                            }
                        }
                    }));

                    generalLoginUpParty.Form.UpdateModel(ToViewModel(loginUpPartyResult));
                    generalLoginUpParty.CreateMode = false;
                    toastService.ShowSuccess("Login Up-party created.", "SUCCESS");
                }
                else
                {
                    var loginUpParty = await UpPartyService.UpdateLoginUpPartyAsync(generalLoginUpParty.Form.Model.Map <LoginUpParty>(afterMap: afterMap =>
                    {
                        afterMap.DisableSingleLogout  = !generalLoginUpParty.Form.Model.EnableSingleLogout;
                        afterMap.DisableResetPassword = !generalLoginUpParty.Form.Model.EnableResetPassword;

                        if (afterMap.ClaimTransforms?.Count() > 0)
                        {
                            int order = 1;
                            foreach (var claimTransform in afterMap.ClaimTransforms)
                            {
                                claimTransform.Order = order++;
                            }
                        }
                    }));

                    generalLoginUpParty.Form.UpdateModel(ToViewModel(loginUpParty));
                    toastService.ShowSuccess("Login Up-party updated.", "SUCCESS");
                }
                generalLoginUpParty.Name = generalLoginUpParty.Form.Model.Name;
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalLoginUpParty.Form.SetFieldError(nameof(generalLoginUpParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Example #7
0
        private async Task OnEditSamlUpPartyValidSubmitAsync(GeneralSamlUpPartyViewModel generalSamlUpParty, EditContext editContext)
        {
            try
            {
                if (generalSamlUpParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalSamlUpParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is SamlClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var samlUpParty = generalSamlUpParty.Form.Model.Map <SamlUpParty>(afterMap =>
                {
                    afterMap.DisableSingleLogout = !generalSamlUpParty.Form.Model.EnableSingleLogout;

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

                if (generalSamlUpParty.CreateMode)
                {
                    await UpPartyService.CreateSamlUpPartyAsync(samlUpParty);
                }
                else
                {
                    await UpPartyService.UpdateSamlUpPartyAsync(samlUpParty);
                }
                generalSamlUpParty.Name = generalSamlUpParty.Form.Model.Name;
                generalSamlUpParty.Edit = false;
                await OnStateHasChanged.InvokeAsync(UpParty);
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalSamlUpParty.Form.SetFieldError(nameof(generalSamlUpParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Example #8
0
        private async Task ShowUpdateUpPartyAsync(GeneralUpPartyViewModel upParty)
        {
            upParty.CreateMode        = false;
            upParty.DeleteAcknowledge = false;
            upParty.ShowAdvanced      = false;
            upParty.Error             = null;
            upParty.Edit = true;
            if (upParty.Type == PartyTypes.Login)
            {
                try
                {
                    var generalLoginUpParty = upParty as GeneralLoginUpPartyViewModel;
                    var loginUpParty        = await UpPartyService.GetLoginUpPartyAsync(upParty.Name);

                    await generalLoginUpParty.Form.InitAsync(loginUpParty.Map <LoginUpPartyViewModel>(afterMap: afterMap =>
                    {
                        afterMap.EnableSingleLogout  = !loginUpParty.DisableSingleLogout;
                        afterMap.EnableResetPassword = !loginUpParty.DisableResetPassword;

                        if (afterMap.ClaimTransforms?.Count > 0)
                        {
                            afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                        }
                    }));
                }
                catch (TokenUnavailableException)
                {
                    await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
                }
                catch (HttpRequestException ex)
                {
                    upParty.Error = ex.Message;
                }
            }
            else if (upParty.Type == PartyTypes.Oidc)
            {
                try
                {
                    var generalOidcUpParty = upParty as GeneralOidcUpPartyViewModel;
                    var oidcUpParty        = await UpPartyService.GetOidcUpPartyAsync(upParty.Name);

                    await generalOidcUpParty.Form.InitAsync(oidcUpParty.Map((Action <OidcUpPartyViewModel>)(afterMap =>
                    {
                        if (oidcUpParty.UpdateState == PartyUpdateStates.Manual)
                        {
                            afterMap.IsManual = true;
                        }

                        if (oidcUpParty.UpdateState == PartyUpdateStates.AutomaticStopped)
                        {
                            afterMap.AutomaticStopped = true;
                        }
                        else
                        {
                            afterMap.AutomaticStopped = false;
                        }

                        afterMap.EnableSingleLogout = !oidcUpParty.DisableSingleLogout;
                        if (oidcUpParty.Client != null)
                        {
                            afterMap.Client.EnableFrontChannelLogout = !oidcUpParty.Client.DisableFrontChannelLogout;
                        }

                        foreach (var key in oidcUpParty.Keys)
                        {
                            afterMap.KeyIds.Add(key.Kid);
                        }

                        if (afterMap.ClaimTransforms?.Count > 0)
                        {
                            afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                        }
                    })));
                }
                catch (TokenUnavailableException)
                {
                    await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
                }
                catch (HttpRequestException ex)
                {
                    upParty.Error = ex.Message;
                }
            }
            else if (upParty.Type == PartyTypes.Saml2)
            {
                try
                {
                    var generalSamlUpParty = upParty as GeneralSamlUpPartyViewModel;
                    var samlUpParty        = await UpPartyService.GetSamlUpPartyAsync(upParty.Name);

                    await generalSamlUpParty.Form.InitAsync(samlUpParty.Map <SamlUpPartyViewModel>(afterMap =>
                    {
                        afterMap.EnableSingleLogout = !samlUpParty.DisableSingleLogout;

                        afterMap.AuthnRequestBinding  = samlUpParty.AuthnBinding.RequestBinding;
                        afterMap.AuthnResponseBinding = samlUpParty.AuthnBinding.ResponseBinding;
                        if (!samlUpParty.LogoutUrl.IsNullOrEmpty())
                        {
                            afterMap.LogoutRequestBinding  = samlUpParty.LogoutBinding.RequestBinding;
                            afterMap.LogoutResponseBinding = samlUpParty.LogoutBinding.ResponseBinding;
                        }

                        generalSamlUpParty.CertificateInfoList.Clear();
                        foreach (var key in afterMap.Keys)
                        {
                            var certificate = new MTokens.JsonWebKey(key.JsonSerialize()).ToX509Certificate();
                            generalSamlUpParty.CertificateInfoList.Add(new CertificateInfoViewModel
                            {
                                Subject    = certificate.Subject,
                                ValidFrom  = certificate.NotBefore,
                                ValidTo    = certificate.NotAfter,
                                IsValid    = certificate.IsValid(),
                                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)
                {
                    upParty.Error = ex.Message;
                }
            }
        }
Example #9
0
        private async Task OnEditSamlUpPartyValidSubmitAsync(GeneralSamlUpPartyViewModel generalSamlUpParty, EditContext editContext)
        {
            try
            {
                if (generalSamlUpParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalSamlUpParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is SamlClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var samlUpParty = generalSamlUpParty.Form.Model.Map <SamlUpParty>(afterMap =>
                {
                    afterMap.DisableSingleLogout = !generalSamlUpParty.Form.Model.EnableSingleLogout;

                    if (generalSamlUpParty.Form.Model.AuthnContextComparisonViewModel != SamlAuthnContextComparisonTypesVievModel.Null)
                    {
                        afterMap.AuthnContextComparison = (SamlAuthnContextComparisonTypes)Enum.Parse(typeof(SamlAuthnContextComparisonTypes), generalSamlUpParty.Form.Model.AuthnContextComparisonViewModel.ToString());
                    }

                    if (generalSamlUpParty.Form.Model.IsManual)
                    {
                        afterMap.UpdateState = PartyUpdateStates.Manual;
                    }
                    else
                    {
                        afterMap.UpdateState = PartyUpdateStates.Automatic;
                    }

                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                if (generalSamlUpParty.CreateMode)
                {
                    var samlUpPartyResult = await UpPartyService.CreateSamlUpPartyAsync(samlUpParty);

                    generalSamlUpParty.Form.UpdateModel(ToViewModel(generalSamlUpParty, samlUpPartyResult));
                    generalSamlUpParty.CreateMode = false;
                    toastService.ShowSuccess("SAML 2.0 Up-party created.", "SUCCESS");
                }
                else
                {
                    var samlUpPartyResult = await UpPartyService.UpdateSamlUpPartyAsync(samlUpParty);

                    generalSamlUpParty.Form.UpdateModel(ToViewModel(generalSamlUpParty, samlUpPartyResult));
                    toastService.ShowSuccess("SAML 2.0 Up-party updated.", "SUCCESS");
                }
                generalSamlUpParty.Name = generalSamlUpParty.Form.Model.Name;
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalSamlUpParty.Form.SetFieldError(nameof(generalSamlUpParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
Example #10
0
        private async Task OnReadMetadataFileAsync(GeneralSamlUpPartyViewModel generalSamlUpParty)
        {
            generalSamlUpParty.Form.ClearError();
            try
            {
                var files = await fileReaderService.CreateReference(readMetadataFileElement).EnumerateFilesAsync();

                var file = files.FirstOrDefault();
                if (file == null)
                {
                    return;
                }

                string metadataXml;
                await using (var stream = await file.OpenReadAsync())
                {
                    byte[] resultBytes = new byte[stream.Length];
                    await stream.ReadAsync(resultBytes, 0, (int)stream.Length);

                    metadataXml = Encoding.ASCII.GetString(resultBytes);
                }

                var samlUpParty = await UpPartyService.ReadSamlUpPartyMetadataAsync(new SamlReadMetadataRequest { Type = SamlReadMetadataType.Xml, Metadata = metadataXml });

                generalSamlUpParty.Form.Model.Issuer   = samlUpParty.Issuer;
                generalSamlUpParty.Form.Model.AuthnUrl = samlUpParty.AuthnUrl;
                if (samlUpParty.AuthnRequestBinding.HasValue)
                {
                    generalSamlUpParty.Form.Model.AuthnRequestBinding = samlUpParty.AuthnRequestBinding.Value;
                }

                generalSamlUpParty.Form.Model.LogoutUrl = samlUpParty.LogoutUrl;
                if (!string.IsNullOrEmpty(samlUpParty.SingleLogoutResponseUrl))
                {
                    generalSamlUpParty.Form.Model.SingleLogoutResponseUrl = samlUpParty.SingleLogoutResponseUrl;
                }
                if (samlUpParty.LogoutRequestBinding.HasValue)
                {
                    generalSamlUpParty.Form.Model.LogoutRequestBinding = samlUpParty.LogoutRequestBinding.Value;
                }

                generalSamlUpParty.KeyInfoList     = new List <KeyInfoViewModel>();
                generalSamlUpParty.Form.Model.Keys = new List <JwtWithCertificateInfo>();

                if (samlUpParty.Keys?.Count() > 0)
                {
                    foreach (var key in samlUpParty.Keys)
                    {
                        generalSamlUpParty.KeyInfoList.Add(new KeyInfoViewModel
                        {
                            Subject    = key.CertificateInfo.Subject,
                            ValidFrom  = key.CertificateInfo.ValidFrom,
                            ValidTo    = key.CertificateInfo.ValidTo,
                            IsValid    = key.CertificateInfo.IsValid(),
                            Thumbprint = key.CertificateInfo.Thumbprint,
                            Key        = key
                        });
                        generalSamlUpParty.Form.Model.Keys.Add(key);
                    }
                }

                generalSamlUpParty.Form.Model.SignAuthnRequest = samlUpParty.SignAuthnRequest;
            }
            catch (Exception ex)
            {
                generalSamlUpParty.Form.SetError($"Failing SAML 2.0 metadata. {ex.Message}");
            }
        }