private bool ValidateLogout(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) { var isValid = true; try { if (!samlUpParty.SingleLogoutResponseUrl.IsNullOrWhiteSpace() && samlUpParty.LogoutUrl.IsNullOrWhiteSpace()) { throw new Exception("Logout URL is required if single logout response URL is configured."); } if (!samlUpParty.LogoutUrl.IsNullOrWhiteSpace()) { if(samlUpParty.LogoutBinding == null) { throw new Exception("Logout binding is required."); } } else { samlUpParty.LogoutBinding = null; } } catch (Exception ex) { isValid = false; logger.Warning(ex); modelState.TryAddModelError(nameof(samlUpParty.LogoutBinding).ToCamelCase(), ex.Message); } return isValid; }
private bool ValidateMetadataNameIdFormats(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) { var isValid = true; try { if (samlUpParty.MetadataNameIdFormats?.Count > 0) { foreach (var nameIdFormat in samlUpParty.MetadataNameIdFormats) { try { _ = new Uri(nameIdFormat); } catch (Exception ex) { throw new Exception($"Metadata NameId format '{nameIdFormat}' not a Uri.", ex); } } } } catch (Exception ex) { isValid = false; logger.Warning(ex); modelState.TryAddModelError(nameof(samlUpParty.MetadataNameIdFormats).ToCamelCase(), ex.Message); } return(isValid); }
public bool ValidateSignatureAlgorithm(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) => ValidateSignatureAlgorithm(modelState, nameof(samlUpParty.SignatureAlgorithm), samlUpParty.SignatureAlgorithm);
private bool ValidateSignatureAlgorithmAndSigningKeys(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) { return ValidateSignatureAlgorithm(modelState, nameof(samlUpParty.SignatureAlgorithm), samlUpParty.SignatureAlgorithm) && ValidateSigningKeys(modelState, nameof(samlUpParty.Keys), samlUpParty.Keys); }
public bool ValidateApiModel(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) { return ValidateSignatureAlgorithmAndSigningKeys(modelState, samlUpParty) && ValidateLogout(modelState, samlUpParty); }