Skip to content

Commit 440128c

Browse files
committed
PR feedback. Return null instead of throwing an exception
1 parent 1947555 commit 440128c

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Assertion.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public Saml2Assertion(Saml2NameIdentifier issuer)
6464

6565
/// <summary>
6666
/// Gets or sets the <see cref="Signature"/> on the Assertion.
67+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
6768
/// </summary>
68-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
6969
public Signature Signature
7070
{
7171
get
7272
{
7373
if (Encrypted)
74-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Signature))));
74+
return null;
7575

7676
return _signature;
7777
}
@@ -82,14 +82,14 @@ public Signature Signature
8282
/// Gets or sets additional information related to the assertion that assists processing in certain
8383
/// situations but which may be ignored by applications that do not understand the
8484
/// advice or do not wish to make use of it. [Saml2Core, 2.3.3]
85+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
8586
/// </summary>
86-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
8787
public Saml2Advice Advice
8888
{
8989
get
9090
{
9191
if (Encrypted)
92-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Advice))));
92+
return null;
9393

9494
return _advice;
9595
}
@@ -99,14 +99,14 @@ public Saml2Advice Advice
9999
/// <summary>
100100
/// Gets or sets conditions that must be evaluated when assessing the validity of and/or
101101
/// when using the assertion. [Saml2Core 2.3.3]
102+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
102103
/// </summary>
103-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
104104
public Saml2Conditions Conditions
105105
{
106106
get
107107
{
108108
if (Encrypted)
109-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Conditions))));
109+
return null;
110110

111111
return _conditions;
112112
}
@@ -115,15 +115,15 @@ public Saml2Conditions Conditions
115115

116116
/// <summary>
117117
/// Gets or sets the <see cref="Saml2Id"/> identifier for this assertion. [Saml2Core, 2.3.3]
118+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
118119
/// </summary>
119-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
120120
/// <exception cref="ArgumentNullException">if 'value' if null.</exception>
121121
public Saml2Id Id
122122
{
123123
get
124124
{
125125
if (Encrypted)
126-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Id))));
126+
return null;
127127

128128
return _id;
129129
}
@@ -132,15 +132,15 @@ public Saml2Id Id
132132

133133
/// <summary>
134134
/// Gets or sets the time instant of issue in UTC. [Saml2Core, 2.3.3]
135+
/// Returns <see cref="DateTime.MinValue"/> if the <see cref="Saml2Assertion"/> is encrypted.
135136
/// </summary>
136-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
137137
/// <exception cref="ArgumentNullException">if 'value' if null.</exception>
138138
public DateTime IssueInstant
139139
{
140140
get
141141
{
142142
if (Encrypted)
143-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(IssueInstant))));
143+
return DateTime.MinValue;
144144

145145
return _issueInstant;
146146
}
@@ -155,15 +155,15 @@ public DateTime IssueInstant
155155

156156
/// <summary>
157157
/// Gets or sets the <see cref="Saml2NameIdentifier"/> as the authority that is making the claim(s) in the assertion. [Saml2Core, 2.3.3]
158+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
158159
/// </summary>
159-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
160160
/// <exception cref="ArgumentNullException">if 'value' if null.</exception>
161161
public Saml2NameIdentifier Issuer
162162
{
163163
get
164164
{
165165
if (Encrypted)
166-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Issuer))));
166+
return null;
167167

168168
return _issuer;
169169
}
@@ -172,14 +172,14 @@ public Saml2NameIdentifier Issuer
172172

173173
/// <summary>
174174
/// Gets or sets the a PrefixList to use when there is a need to include InclusiveNamespaces writing token.
175+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
175176
/// </summary>
176-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
177177
public string InclusiveNamespacesPrefixList
178178
{
179179
get
180180
{
181181
if (Encrypted)
182-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(InclusiveNamespacesPrefixList))));
182+
return null;
183183

184184
return _inclusiveNamespacesPrefixList;
185185
}
@@ -188,14 +188,14 @@ public string InclusiveNamespacesPrefixList
188188

189189
/// <summary>
190190
/// Gets or sets the <see cref="SigningCredentials"/> used by the issuer to protect the integrity of the assertion.
191+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
191192
/// </summary>
192-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
193193
public SigningCredentials SigningCredentials
194194
{
195195
get
196196
{
197197
if (Encrypted)
198-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(SigningCredentials))));
198+
return null;
199199

200200
return _signingCredentials;
201201
}
@@ -204,14 +204,14 @@ public SigningCredentials SigningCredentials
204204

205205
/// <summary>
206206
/// Gets or sets the <see cref="Saml2Subject"/> of the statement(s) in the assertion. [Saml2Core, 2.3.3]
207+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
207208
/// </summary>
208-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
209209
public Saml2Subject Subject
210210
{
211211
get
212212
{
213213
if (Encrypted)
214-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Subject))));
214+
return null;
215215

216216
return _subject;
217217
}
@@ -221,14 +221,14 @@ public Saml2Subject Subject
221221

222222
/// <summary>
223223
/// Gets the <see cref="Saml2Statement"/>(s) regarding the subject.
224+
/// Returns <c>null</c> if the <see cref="Saml2Assertion"/> is encrypted.
224225
/// </summary>
225-
/// <exception cref="Saml2SecurityTokenEncryptedAssertionException"> If this assertion is encrypted.</exception>
226226
public ICollection<Saml2Statement> Statements
227227
{
228228
get
229229
{
230230
if (Encrypted)
231-
throw LogExceptionMessage(new Saml2SecurityTokenEncryptedAssertionException(FormatInvariant(LogMessages.IDX13608, nameof(Statements))));
231+
return null;
232232

233233
return _statements;
234234
}

test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SecurityTokenHandlerTests.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,96 +1069,84 @@ public static TheoryData<Saml2TheoryData> AccessEncryptedAssertionTheoryData
10691069
{
10701070
First = true,
10711071
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1072-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Advice" } },
1073-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Advice'"),
1072+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Advice" }, { "AssertionPropertyExpectedValue", null } },
10741073
TestId = "EncryptedAssertion_Access_Advice",
10751074
});
10761075

10771076
theoryData.Add(new Saml2TheoryData
10781077
{
10791078
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1080-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Conditions" } },
1081-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Conditions'"),
1079+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Conditions" }, { "AssertionPropertyExpectedValue", null } },
10821080
TestId = "EncryptedAssertion_Access_Conditions",
10831081
});
10841082

10851083
theoryData.Add(new Saml2TheoryData
10861084
{
10871085
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1088-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Id" } },
1089-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Id'"),
1086+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Id" }, { "AssertionPropertyExpectedValue", null } },
10901087
TestId = "EncryptedAssertion_Access_Id",
10911088
});
10921089

10931090
theoryData.Add(new Saml2TheoryData
10941091
{
10951092
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1096-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "IssueInstant" } },
1097-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'IssueInstant'"),
1093+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "IssueInstant" }, { "AssertionPropertyExpectedValue", DateTime.MinValue } },
10981094
TestId = "EncryptedAssertion_Access_IssueInstantConditions",
10991095
});
11001096

11011097
theoryData.Add(new Saml2TheoryData
11021098
{
11031099
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1104-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Issuer" } },
1105-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Issuer'"),
1100+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Issuer" }, { "AssertionPropertyExpectedValue", null } },
11061101
TestId = "EncryptedAssertion_Access_Issuer",
11071102
});
11081103

11091104
theoryData.Add(new Saml2TheoryData
11101105
{
11111106
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1112-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "InclusiveNamespacesPrefixList" } },
1113-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'InclusiveNamespacesPrefixList'"),
1107+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "InclusiveNamespacesPrefixList" }, { "AssertionPropertyExpectedValue", null } },
11141108
TestId = "EncryptedAssertion_Access_InclusiveNamespacesPrefixList",
11151109
});
11161110

11171111
theoryData.Add(new Saml2TheoryData
11181112
{
11191113
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1120-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "SigningCredentials" } },
1121-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'SigningCredentials'"),
1114+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "SigningCredentials" }, { "AssertionPropertyExpectedValue", null } },
11221115
TestId = "EncryptedAssertion_Access_SigningCredentials",
11231116
});
11241117

11251118
theoryData.Add(new Saml2TheoryData
11261119
{
11271120
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1128-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Subject" } },
1129-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Subject'"),
1121+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Subject" }, { "AssertionPropertyExpectedValue", null } },
11301122
TestId = "EncryptedAssertion_Access_Subject",
11311123
});
11321124

11331125
theoryData.Add(new Saml2TheoryData
11341126
{
11351127
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1136-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Statements" } },
1137-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Statements'"),
1128+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Statements" }, { "AssertionPropertyExpectedValue", null } },
11381129
TestId = "EncryptedAssertion_Access_Statements",
11391130
});
11401131

11411132
theoryData.Add(new Saml2TheoryData
11421133
{
11431134
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
1144-
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Signature" } },
1145-
ExpectedException = new ExpectedException(typeof(Saml2SecurityTokenEncryptedAssertionException), "IDX13608: Saml2Assertion is encrypted. Unable to get 'Signature'"),
1135+
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Signature" }, { "AssertionPropertyExpectedValue", null } },
11461136
TestId = "EncryptedAssertion_Access_Signature",
11471137
});
11481138

11491139
theoryData.Add(new Saml2TheoryData
11501140
{
11511141
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
11521142
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "Version" }, { "AssertionPropertyExpectedValue", "2.0" } },
1153-
ExpectedException = ExpectedException.NoExceptionExpected,
11541143
TestId = "EncryptedAssertion_Access_Version",
11551144
});
11561145

11571146
theoryData.Add(new Saml2TheoryData
11581147
{
11591148
Token = ReferenceTokens.Saml2Token_EncryptedAssertion_SessionKey_Valid,
11601149
PropertyBag = new Dictionary<string, object> { { "AssertionPropertyName", "EncryptingCredentials" }, { "AssertionPropertyExpectedValue", null} },
1161-
ExpectedException = ExpectedException.NoExceptionExpected,
11621150
TestId = "EncryptedAssertion_Access_EncryptingCredentials",
11631151
});
11641152

0 commit comments

Comments
 (0)