Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public bool ValidateSignatureAlgorithm(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty) => ValidateSignatureAlgorithm(modelState, nameof(samlUpParty.SignatureAlgorithm), samlUpParty.SignatureAlgorithm);
Exemplo n.º 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);
 }
Exemplo n.º 5
0
 public bool ValidateApiModel(ModelStateDictionary modelState, Api.SamlUpParty samlUpParty)
 {
     return ValidateSignatureAlgorithmAndSigningKeys(modelState, samlUpParty) && 
         ValidateLogout(modelState, samlUpParty);
 }