@@ -456,6 +456,129 @@ public void Saml2Response_GetClaims_CorrectSignedResponseMessage_WithAuthnContex
456
456
authMethodClaim . Value . Should ( ) . Be ( "urn:somespecialvalue" ) ;
457
457
}
458
458
459
+ [ TestMethod ]
460
+ public void Saml2Response_GetClaims_BadAuthnContext_IgnoredWhenConfigured ( )
461
+ {
462
+ var response =
463
+ @"<?xml version=""1.0"" encoding=""UTF-8""?>
464
+ <saml2p:Response xmlns:saml2p=""urn:oasis:names:tc:SAML:2.0:protocol""
465
+ xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
466
+ ID = """ + MethodBase . GetCurrentMethod ( ) . Name + @""" Version=""2.0"" IssueInstant=""2013-01-01T00:00:00Z"">
467
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
468
+ <saml2p:Status>
469
+ <saml2p:StatusCode Value=""urn:oasis:names:tc:SAML:2.0:status:Success"" />
470
+ </saml2p:Status>
471
+ <saml2:Assertion xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
472
+ Version=""2.0"" ID=""" + MethodBase . GetCurrentMethod ( ) . Name + @"_Assertion1""
473
+ IssueInstant=""2013-09-25T00:00:00Z"">
474
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
475
+ <saml2:Subject>
476
+ <saml2:NameID>AuthenticatedSomeone</saml2:NameID>
477
+ <saml2:SubjectConfirmation Method=""urn:oasis:names:tc:SAML:2.0:cm:bearer"" />
478
+ </saml2:Subject>
479
+ <saml2:Conditions NotOnOrAfter=""2100-01-01T00:00:00Z"" />
480
+ <saml2:AuthnStatement AuthnInstant=""2013-09-25T00:00:00Z"" SessionIndex=""17"" >
481
+ <saml2:AuthnContext>
482
+ <saml2:AuthnContextClassRef>badvalue</saml2:AuthnContextClassRef>
483
+ </saml2:AuthnContext>
484
+ </saml2:AuthnStatement>
485
+ </saml2:Assertion>
486
+ </saml2p:Response>" ;
487
+
488
+ var signedResponse = SignedXmlHelper . SignXml ( response ) ;
489
+
490
+ var options = StubFactory . CreateOptions ( ) ;
491
+ options . SPOptions . Compatibility . IgnoreAuthenticationContextInResponse = true ;
492
+ var result = Saml2Response . Read ( signedResponse ) . GetClaims ( options ) ;
493
+
494
+ var authMethodClaim = result . Single ( ) . Claims . SingleOrDefault ( c => c . Type == ClaimTypes . AuthenticationMethod ) ;
495
+ authMethodClaim . Should ( ) . BeNull ( "the authentication method claim should not be generated" ) ;
496
+
497
+ var nameidClaim = result . Single ( ) . Claims . SingleOrDefault ( c => c . Type == ClaimTypes . NameIdentifier ) ;
498
+ nameidClaim . Should ( ) . NotBeNull ( "the subject nameid claim should be generated" ) ;
499
+ nameidClaim . Value . Should ( ) . Be ( "AuthenticatedSomeone" ) ;
500
+ }
501
+
502
+ [ TestMethod ]
503
+ public void Saml2Response_GetClaims_HandlerWithNullOptions_AuthnContextGeneratesClaims ( )
504
+ {
505
+ var response =
506
+ @"<?xml version=""1.0"" encoding=""UTF-8""?>
507
+ <saml2p:Response xmlns:saml2p=""urn:oasis:names:tc:SAML:2.0:protocol""
508
+ xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
509
+ ID = """ + MethodBase . GetCurrentMethod ( ) . Name + @""" Version=""2.0"" IssueInstant=""2013-01-01T00:00:00Z"">
510
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
511
+ <saml2p:Status>
512
+ <saml2p:StatusCode Value=""urn:oasis:names:tc:SAML:2.0:status:Success"" />
513
+ </saml2p:Status>
514
+ <saml2:Assertion xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
515
+ Version=""2.0"" ID=""" + MethodBase . GetCurrentMethod ( ) . Name + @"_Assertion1""
516
+ IssueInstant=""2013-09-25T00:00:00Z"">
517
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
518
+ <saml2:Subject>
519
+ <saml2:NameID>SomeOne</saml2:NameID>
520
+ <saml2:SubjectConfirmation Method=""urn:oasis:names:tc:SAML:2.0:cm:bearer"" />
521
+ </saml2:Subject>
522
+ <saml2:Conditions NotOnOrAfter=""2100-01-01T00:00:00Z"" />
523
+ <saml2:AuthnStatement AuthnInstant=""2013-09-25T00:00:00Z"" SessionIndex=""17"" >
524
+ <saml2:AuthnContext>
525
+ <saml2:AuthnContextClassRef>urn:somespecialvalue</saml2:AuthnContextClassRef>
526
+ </saml2:AuthnContext>
527
+ </saml2:AuthnStatement>
528
+ </saml2:Assertion>
529
+ </saml2p:Response>" ;
530
+
531
+ var signedResponse = SignedXmlHelper . SignXml ( response ) ;
532
+
533
+ var options = Options . FromConfiguration ;
534
+ options . SPOptions . Saml2PSecurityTokenHandler = new Saml2PSecurityTokenHandler ( ) ;
535
+ var result = Saml2Response . Read ( signedResponse ) . GetClaims ( options ) ;
536
+
537
+ var authMethodClaim = result . Single ( ) . Claims . SingleOrDefault ( c => c . Type == ClaimTypes . AuthenticationMethod ) ;
538
+ authMethodClaim . Should ( ) . NotBeNull ( "the authentication method claim should be generated" ) ;
539
+ authMethodClaim . Value . Should ( ) . Be ( "urn:somespecialvalue" ) ;
540
+ }
541
+
542
+ [ TestMethod ]
543
+ public void Saml2Response_GetClaims_OptionsWithNullCompatibility_AuthnContextGeneratesClaims ( )
544
+ {
545
+ var response =
546
+ @"<?xml version=""1.0"" encoding=""UTF-8""?>
547
+ <saml2p:Response xmlns:saml2p=""urn:oasis:names:tc:SAML:2.0:protocol""
548
+ xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
549
+ ID = """ + MethodBase . GetCurrentMethod ( ) . Name + @""" Version=""2.0"" IssueInstant=""2013-01-01T00:00:00Z"">
550
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
551
+ <saml2p:Status>
552
+ <saml2p:StatusCode Value=""urn:oasis:names:tc:SAML:2.0:status:Success"" />
553
+ </saml2p:Status>
554
+ <saml2:Assertion xmlns:saml2=""urn:oasis:names:tc:SAML:2.0:assertion""
555
+ Version=""2.0"" ID=""" + MethodBase . GetCurrentMethod ( ) . Name + @"_Assertion1""
556
+ IssueInstant=""2013-09-25T00:00:00Z"">
557
+ <saml2:Issuer>https://idp.example.com</saml2:Issuer>
558
+ <saml2:Subject>
559
+ <saml2:NameID>SomeOne</saml2:NameID>
560
+ <saml2:SubjectConfirmation Method=""urn:oasis:names:tc:SAML:2.0:cm:bearer"" />
561
+ </saml2:Subject>
562
+ <saml2:Conditions NotOnOrAfter=""2100-01-01T00:00:00Z"" />
563
+ <saml2:AuthnStatement AuthnInstant=""2013-09-25T00:00:00Z"" SessionIndex=""17"" >
564
+ <saml2:AuthnContext>
565
+ <saml2:AuthnContextClassRef>urn:somespecialvalue</saml2:AuthnContextClassRef>
566
+ </saml2:AuthnContext>
567
+ </saml2:AuthnStatement>
568
+ </saml2:Assertion>
569
+ </saml2p:Response>" ;
570
+
571
+ var signedResponse = SignedXmlHelper . SignXml ( response ) ;
572
+
573
+ var options = StubFactory . CreateOptions ( ) ;
574
+ options . SPOptions . Compatibility = null ;
575
+ var result = Saml2Response . Read ( signedResponse ) . GetClaims ( options ) ;
576
+
577
+ var authMethodClaim = result . Single ( ) . Claims . SingleOrDefault ( c => c . Type == ClaimTypes . AuthenticationMethod ) ;
578
+ authMethodClaim . Should ( ) . NotBeNull ( "the authentication method claim should be generated" ) ;
579
+ authMethodClaim . Value . Should ( ) . Be ( "urn:somespecialvalue" ) ;
580
+ }
581
+
459
582
[ TestMethod ]
460
583
public void Saml2Response_GetClaims_SessionIndexButNoNameId ( )
461
584
{
@@ -1008,7 +1131,7 @@ public void Saml2Response_GetClaims_CorrectEncryptedSingleAssertion_OAEP()
1008
1131
}
1009
1132
1010
1133
[ TestMethod ]
1011
- public void Saml2Response_GetClaims_CorrectEncryptedSingleAssertion_UsingWIF ( )
1134
+ public void Saml2Response_GetClaims_CorrectEncryptedSingleAssertion_UsingMSIdentityModel ( )
1012
1135
{
1013
1136
var response =
1014
1137
@"<saml2p:Response xmlns:saml2p=""urn:oasis:names:tc:SAML:2.0:protocol""
@@ -1027,7 +1150,7 @@ public void Saml2Response_GetClaims_CorrectEncryptedSingleAssertion_UsingWIF()
1027
1150
assertion . Conditions = new Saml2Conditions { NotOnOrAfter = new DateTime ( 2100 , 1 , 1 ) } ;
1028
1151
1029
1152
var token = new Saml2SecurityToken ( assertion ) ;
1030
- var handler = new Saml2PSecurityTokenHandler ( ) ;
1153
+ var handler = new Saml2SecurityTokenHandler ( ) ;
1031
1154
1032
1155
var signingKey = new X509SecurityKey ( SignedXmlHelper . TestCert ) ;
1033
1156
var signingCreds = new SigningCredentials ( signingKey ,
0 commit comments