private bool ValidateLogout(ModelStateDictionary modelState, Api.SamlDownParty samlDownParty) { var isValid = true; try { if (!samlDownParty.LoggedOutUrl.IsNullOrWhiteSpace()) { if (samlDownParty.LogoutBinding == null) { throw new Exception("Logout binding is required."); } } else { samlDownParty.SingleLogoutUrl = null; samlDownParty.LogoutBinding = null; } } catch (Exception ex) { isValid = false; logger.Warning(ex); modelState.TryAddModelError(nameof(samlDownParty.LogoutBinding).ToCamelCase(), ex.Message); } return isValid; }
private bool ValidateMetadataNameIdFormats(ModelStateDictionary modelState, Api.SamlDownParty samlDownParty) { var isValid = true; try { if (samlDownParty.MetadataNameIdFormats?.Count > 0) { foreach (var nameIdFormat in samlDownParty.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(samlDownParty.MetadataNameIdFormats).ToCamelCase(), ex.Message); } return(isValid); }
public bool ValidateSignatureAlgorithm(ModelStateDictionary modelState, Api.SamlDownParty samlDownParty) => ValidateSignatureAlgorithm(modelState, nameof(samlDownParty.SignatureAlgorithm), samlDownParty.SignatureAlgorithm);
private bool ValidateSignatureAlgorithmAndSigningKeys(ModelStateDictionary modelState, Api.SamlDownParty samlDownParty) { return ValidateSignatureAlgorithm(modelState, nameof(samlDownParty.SignatureAlgorithm), samlDownParty.SignatureAlgorithm) && ValidateSigningKeys(modelState, nameof(samlDownParty.Keys), samlDownParty.Keys); }
public bool ValidateApiModel(ModelStateDictionary modelState, Api.SamlDownParty samlDownParty) { return ValidateSignatureAlgorithmAndSigningKeys(modelState, samlDownParty) && ValidateLogout(modelState, samlDownParty); }