Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of IDX13300 and IDX13107 #1458

Merged
merged 5 commits into from
Jun 23, 2020

Conversation

keegan-caruso
Copy link
Contributor

fixes #1455

@@ -122,7 +122,7 @@ public Uri DeclarationReference
set
{
if (value != null && !value.IsAbsoluteUri)
throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(value), value)));
throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(DeclarationReference), value)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keegan-caruso could you fix up the difference between ClassReference and DeclarationReference where ClassReference throws ArgumentNullException when value == null. I would vote for differentiating null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentschmaltz I'm happy to normalize the two. I am wondering if this goes back to the Saml2Core spec. Section 2.7.2.2 calls out both as being optional. That seems to imply neither throw on null. This looks safe as all access to this field checks for null conditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keegan-caruso in rethinking this, the ctors seem to be fine. Given the spec.
The issue seems to be that the ctors try and set a null value to the property.

It's OK that the value is null, but the reason we throw when setting the property is that seems to indicate a programming error.

So, perhaps the error is the constructor trying to set a null value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea. It also fixes #1457

@keegan-caruso keegan-caruso linked an issue Jun 18, 2020 that may be closed by this pull request
@@ -73,8 +73,14 @@ public Saml2AuthenticationContext(Uri classReference)
/// <param name="declarationReference">The declaration reference of the authentication context.</param>
public Saml2AuthenticationContext(Uri classReference, Uri declarationReference)
{
ClassReference = classReference;
DeclarationReference = declarationReference;
// Class and declaration reference are optional, so don't try and set the respective properties if
Copy link
Member

@brentschmaltz brentschmaltz Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend a slightly different pattern.
We have three ctors.
Check the parameters as we did before, but call a private method to initialize where we know the parameters were checked.
Otherwise we are not helping devs by helping them catch programming errors.

Here is an example here where we know in the private method we checked parameters in the public methods.

private string CreateTokenPrivate(JObject payload, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials, string compressionAlgorithm, IDictionary<string, object> additionalHeaderClaims)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a slightly different approach, but hopefully captured the spirit of what your feedback was addressing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, looks good.

@keegan-caruso keegan-caruso force-pushed the keegancaruso/fix-idx13300-idx13107-usage branch from cd3f50f to 17b0655 Compare June 22, 2020 16:24
@@ -659,7 +659,10 @@ protected virtual Saml2AuthenticationContext ReadAuthenticationContext(XmlDictio
reader.ReadStartElement(Saml2Constants.Elements.AuthnContextDeclRef, Saml2Constants.Namespace);

// Now we have enough data to create the object
var authnContext = new Saml2AuthenticationContext(classRef, declRef);
var authnContext = new Saml2AuthenticationContext(classRef);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to keep the behavior the same. Previously, classRef was always passed in and always validated as non-null. declRef was allowed to be null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@brentschmaltz
Copy link
Member

:shipit:

@keegan-caruso keegan-caruso merged commit 0567929 into dev Jun 23, 2020
@keegan-caruso keegan-caruso deleted the keegancaruso/fix-idx13300-idx13107-usage branch June 23, 2020 21:33
@brentschmaltz brentschmaltz added this to the 6.7.0 milestone Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should AuthnContextClassRef be required? Usage of IDX13300 and IDX13107 is incorrect
2 participants