示例#1
0
        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;
        }
示例#2
0
        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);
        }
示例#3
0
 public bool ValidateSignatureAlgorithm(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) => ValidateSignatureAlgorithm(modelState, nameof(samlUpParty.SignatureAlgorithm), samlUpParty.SignatureAlgorithm);
示例#4
0
 private bool ValidateSignatureAlgorithmAndSigningKeys(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty)
 {
     return ValidateSignatureAlgorithm(modelState, nameof(samlUpParty.SignatureAlgorithm), samlUpParty.SignatureAlgorithm) &&
         ValidateSigningKeys(modelState, nameof(samlUpParty.Keys), samlUpParty.Keys);
 }
示例#5
0
 public bool ValidateApiModel(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty)
 {
     return ValidateSignatureAlgorithmAndSigningKeys(modelState, samlUpParty) && 
         ValidateLogout(modelState, samlUpParty);
 }