1818use SimpleSAML \SAML2 \Constants as C ;
1919use SimpleSAML \SAML2 \Exception \ArrayValidationException ;
2020use SimpleSAML \SAML2 \XML \md \ContactPerson ;
21- use SimpleSAML \SAML2 \XML \saml \{AttributeValue , Issuer , NameID , SubjectConfirmation , SubjectConfirmationData };
21+ use SimpleSAML \SAML2 \XML \saml \{AttributeValue , Audience , Issuer , NameID , SubjectConfirmation , SubjectConfirmationData };
22+ use SimpleSAML \SAML2 \XML \saml \{AuthenticatingAuthority , AuthnContext , AuthnContextClassRef }; // AuthnContext
2223use SimpleSAML \SAML2 \XML \samlp \{Status , StatusCode , StatusMessage }; // Status
2324use SimpleSAML \XML \DOMDocumentFactory ;
2425use SimpleSAML \XMLSecurity \XML \ds \{X509Certificate , X509Data , KeyInfo };
2526use Symfony \Bridge \PsrHttpMessage \Factory \{HttpFoundationFactory , PsrHttpFactory };
2627use Symfony \Component \HttpFoundation \{Request , Response };
2728
2829use function array_key_exists ;
30+ use function array_map ;
2931use function array_merge ;
3032use function array_pop ;
3133use function array_unique ;
@@ -86,10 +88,6 @@ public static function sendResponse(array $state): Response
8688
8789 $ assertion = self ::buildAssertion ($ idpMetadata , $ spMetadata , $ state );
8890
89- if (isset ($ state ['saml:AuthenticatingAuthority ' ])) {
90- $ assertion ->setAuthenticatingAuthority ($ state ['saml:AuthenticatingAuthority ' ]);
91- }
92-
9391 // create the session association (for logout)
9492 $ association = [
9593 'id ' => 'saml: ' . $ spEntityId ,
@@ -1171,8 +1169,9 @@ private static function buildAssertion(
11711169 $ issuer ->setFormat (C::NAMEID_ENTITY );
11721170 $ a ->setIssuer ($ issuer );
11731171
1174- $ audience = array_merge ([$ spMetadata ->getString ('entityid ' )], $ spMetadata ->getOptionalArray ('audience ' , []));
1175- $ a ->setValidAudiences ($ audience );
1172+ $ audiences = array_merge ([$ spMetadata ->getString ('entityid ' )], $ spMetadata ->getOptionalArray ('audience ' , []));
1173+ $ audiences = array_map (fn ($ audience ): Audience => new Audience ($ audience ), $ audiences );
1174+ $ a ->setValidAudiences ($ audiences );
11761175
11771176 $ a ->setNotBefore ($ now - 30 );
11781177
@@ -1184,16 +1183,28 @@ private static function buildAssertion(
11841183
11851184 $ passAuthnContextClassRef = $ config ->getOptionalBoolean ('proxymode.passAuthnContextClassRef ' , false );
11861185 if (isset ($ state ['saml:AuthnContextClassRef ' ])) {
1187- $ a -> setAuthnContextClassRef ( $ state ['saml:AuthnContextClassRef ' ]) ;
1186+ $ classRef = $ state ['saml:AuthnContextClassRef ' ];
11881187 } elseif ($ passAuthnContextClassRef && isset ($ state ['saml:sp:AuthnContext ' ])) {
11891188 // AuthnContext has been set by the upper IdP in front of the proxy, pass it back to the SP behind the proxy
1190- $ a ->setAuthnContextClassRef ($ state ['saml:sp:AuthnContext ' ]);
1191- } elseif ($ httpUtils ->isHTTPS ()) {
1192- $ a ->setAuthnContextClassRef (C::AC_PASSWORD_PROTECTED_TRANSPORT );
1189+ $ classRef = $ state ['saml:sp:AuthnContext ' ];
11931190 } else {
1194- $ a ->setAuthnContextClassRef (C::AC_PASSWORD );
1191+ $ classRef = $ httpUtils ->isHTTPS () ? C::AC_PASSWORD_PROTECTED_TRANSPORT : C::AC_PASSWORD ;
1192+ }
1193+
1194+ $ authorities = [];
1195+ if (isset ($ state ['saml:AuthenticatingAuthority ' ])) {
1196+ $ authorities [] = new AuthenticatingAuthority ($ state ['saml:AuthenticatingAuthority ' ]);
11951197 }
11961198
1199+ $ a ->setAuthnContext (
1200+ new AuthnContext (
1201+ authnContextClassRef: new AuthnContextClassRef ($ classRef ),
1202+ authnContextDecl: null ,
1203+ authnContextDeclRef: null ,
1204+ authenticatingAuthorities: $ authorities ,
1205+ )
1206+ );
1207+
11971208 $ sessionStart = $ now ;
11981209 if (isset ($ state ['AuthnInstant ' ])) {
11991210 $ a ->setAuthnInstant ($ state ['AuthnInstant ' ]);
0 commit comments