@@ -35,24 +35,26 @@ class RequestedAuthnContextSelector extends AbstractSourceSelector
3535 */
3636 public const SOURCESID = '\SimpleSAML\Module\core\Auth\Source\RequestedAuthnContextSelector.SourceId ' ;
3737
38+
3839 /**
3940 * @var string The default authentication source to use when no RequestedAuthnContext is passed
4041 * @psalm-suppress PropertyNotSetInConstructor
4142 */
4243 protected string $ defaultSource ;
4344
4445 /**
45- * @var array<int, array> An array of AuthnContexts, indexed by its weight (higher = better) .
46+ * @var array<int, array> An array of AuthnContexts, indexed by a numeric key .
4647 * Each entry is in the format of:
47- * `weight ` => [`identifier` => 'identifier', `source` => 'source']
48+ * `loa ` => [`identifier` => 'identifier', `source` => 'source']
4849 *
4950 * i.e.:
5051 *
51- * '10' => [
52+ * 10 => [
5253 * 'identifier' => 'urn:x-simplesamlphp:loa1',
5354 * 'source' => 'exampleauth',
5455 * ],
55- * '20' => [
56+ *
57+ * 20 => [
5658 * 'identifier' => 'urn:x-simplesamlphp:loa2',
5759 * 'source' => 'exampleauth-mfa',
5860 * ]
@@ -73,19 +75,25 @@ public function __construct(array $info, array $config)
7375
7476 Assert::keyExists ($ config , 'contexts ' );
7577 Assert::keyExists ($ config ['contexts ' ], 'default ' );
76- Assert::stringNotEmpty ($ config ['contexts ' ]['default ' ]);
77- $ this ->defaultSource = $ config ['contexts ' ]['default ' ];
78- unset($ config ['contexts ' ]['default ' ]);
78+
79+ if (!is_array ($ config ['contexts ' ]['default ' ])) {
80+ Assert::stringNotEmpty ($ config ['contexts ' ]['default ' ]);
81+ $ this ->defaultSource = $ config ['contexts ' ]['default ' ];
82+ unset($ config ['contexts ' ]['default ' ]);
83+ }
7984
8085 foreach ($ config ['contexts ' ] as $ key => $ context ) {
81- Assert::natural ($ key );
86+ ($ key !== 'default ' ) && Assert::natural ($ key );
87+
8288 if (!array_key_exists ('identifier ' , $ context )) {
8389 throw new Exception (sprintf ("Incomplete context '%d' due to missing `identifier` key. " , $ key ));
8490 } elseif (!array_key_exists ('source ' , $ context )) {
8591 throw new Exception (sprintf ("Incomplete context '%d' due to missing `source` key. " , $ key ));
86- } else {
87- $ this ->contexts [$ key ] = $ context ;
8892 }
93+
94+ Assert::stringNotEmpty ($ context ['identifier ' ]);
95+ Assert::stringNotEmpty ($ context ['source ' ]);
96+ $ this ->contexts [$ key ] = $ context ;
8997 }
9098 }
9199
@@ -103,6 +111,12 @@ protected function selectAuthSource(array &$state): string
103111 Logger::info (
104112 "core:RequestedAuthnContextSelector: no RequestedAuthnContext provided; selecting default authsource "
105113 );
114+
115+ if (array_key_exists ('default ' , $ this ->contexts )) {
116+ $ state ['saml:AuthnContextClassRef ' ] = $ this ->contexts ['default ' ]['identifier ' ];
117+ return $ this ->contexts ['default ' ]['source ' ];
118+ }
119+
106120 return $ this ->defaultSource ;
107121 }
108122
0 commit comments