-
Notifications
You must be signed in to change notification settings - Fork 413
/
SecurityTokenException.cs
132 lines (116 loc) · 4.63 KB
/
SecurityTokenException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Diagnostics;
using System.Runtime.Serialization;
#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER
using Microsoft.IdentityModel.Logging;
#endif
#if !NET8_0_OR_GREATER
using System.Text;
#endif
namespace Microsoft.IdentityModel.Tokens
{
/// <summary>
/// Represents a security token exception.
/// </summary>
[Serializable]
public class SecurityTokenException : Exception
{
[NonSerialized]
private string _stackTrace;
/// <summary>
/// Initializes a new instance of the <see cref="SecurityTokenException"/> class.
/// </summary>
public SecurityTokenException()
: base()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SecurityTokenException"/> class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public SecurityTokenException(string message)
: base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SecurityTokenException"/> class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The <see cref="Exception"/> that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
public SecurityTokenException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SecurityTokenException"/> class.
/// </summary>
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
protected SecurityTokenException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
/// <summary>
/// Gets the stack trace that is captured when the exception is created.
/// </summary>
public override string StackTrace
{
get
{
if (_stackTrace == null)
{
if (ValidationError == null)
return base.StackTrace;
#if NET8_0_OR_GREATER
_stackTrace = new StackTrace(ValidationError.StackFrames).ToString();
#else
StringBuilder sb = new();
foreach (StackFrame frame in ValidationError.StackFrames)
{
sb.Append(frame.ToString());
sb.Append(Environment.NewLine);
}
_stackTrace = sb.ToString();
#endif
}
return _stackTrace;
}
}
/// <summary>
/// Gets or sets the source of the exception.
/// </summary>
public override string Source
{
get => base.Source;
set => base.Source = value;
}
internal ValidationError ValidationError
{
get; set;
}
#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER
/// <summary>
/// When overridden in a derived class, sets the System.Runtime.Serialization.SerializationInfo
/// with information about the exception.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">thrown if <paramref name="info"/> is null.</exception>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw LogHelper.LogArgumentNullException(nameof(info));
base.GetObjectData(info, context);
}
#endif
}
}