Skip to content

Commit 7d41f06

Browse files
committed
Merge pull request SAML-Toolkits#83 from stevewest/master
Allows the RequestedAuthnContext Comparison attribute to be set via config
2 parents 97441d9 + a3f7cec commit 7d41f06

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

advanced_settings_example.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@
4848

4949
// Authentication context.
5050
// Set to false and no AuthContext will be sent in the AuthNRequest,
51-
// Set true or don't present thi parameter and you will get an AuthContext 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport'
51+
// Set true or don't present this parameter and you will get an AuthContext 'exact' 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport'
5252
// Set an array with the possible auth context values: array ('urn:oasis:names:tc:SAML:2.0:ac:classes:Password', 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509'),
5353
'requestedAuthnContext' => true,
5454

55+
// Allows the authn comparison parameter to be set, defaults to 'exact' if
56+
// the setting is not present.
57+
'requestedAuthnContextComparison' => 'exact',
58+
5559
// Indicates if the SP will validate all received xmls.
5660
// (In order to validate the xml, 'strict' and 'wantXMLValidation' must be true).
5761
'wantXMLValidation' => true,

lib/Saml2/AuthnRequest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OneLogin_Saml2_AuthnRequest
3030
*
3131
* @param OneLogin_Saml2_Settings $settings Settings
3232
* @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
33-
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
33+
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
3434
*/
3535
public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = false, $isPassive = false)
3636
{
@@ -42,7 +42,7 @@ public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = fal
4242

4343
$id = OneLogin_Saml2_Utils::generateUniqueID();
4444
$issueInstant = OneLogin_Saml2_Utils::parseTime2SAML(time());
45-
45+
4646
$nameIDPolicyFormat = $spData['NameIDFormat'];
4747
if (isset($security['wantNameIdEncrypted']) && $security['wantNameIdEncrypted']) {
4848
$nameIDPolicyFormat = OneLogin_Saml2_Constants::NAMEID_ENCRYPTED;
@@ -59,7 +59,7 @@ public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = fal
5959
}
6060
if (isset($organizationData[$lang]['displayname']) && !empty($organizationData[$lang]['displayname'])) {
6161
$providerNameStr = <<<PROVIDERNAME
62-
ProviderName="{$organizationData[$lang]['displayname']}"
62+
ProviderName="{$organizationData[$lang]['displayname']}"
6363
PROVIDERNAME;
6464
}
6565
}
@@ -82,14 +82,20 @@ public function __construct(OneLogin_Saml2_Settings $settings, $forceAuthn = fal
8282

8383
$requestedAuthnStr = '';
8484
if (isset($security['requestedAuthnContext']) && $security['requestedAuthnContext'] !== false) {
85+
86+
$authnComparison = 'exact';
87+
if (isset($security['requestedAuthnContextComparison'])) {
88+
$authnComparison = $security['requestedAuthnContextComparison'];
89+
}
90+
8591
if ($security['requestedAuthnContext'] === true) {
8692
$requestedAuthnStr = <<<REQUESTEDAUTHN
87-
<samlp:RequestedAuthnContext Comparison="exact">
93+
<samlp:RequestedAuthnContext Comparison="$authnComparison">
8894
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
8995
</samlp:RequestedAuthnContext>
9096
REQUESTEDAUTHN;
9197
} else {
92-
$requestedAuthnStr .= " <samlp:RequestedAuthnContext Comparison=\"exact\">\n";
98+
$requestedAuthnStr .= " <samlp:RequestedAuthnContext Comparison=\"$authnComparison\">\n";
9399
foreach ($security['requestedAuthnContext'] as $contextValue) {
94100
$requestedAuthnStr .= " <saml:AuthnContextClassRef>".$contextValue."</saml:AuthnContextClassRef>\n";
95101
}

tests/src/OneLogin/Saml2/AuthnRequestTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function setUp()
2020
}
2121

2222
/**
23-
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
23+
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
2424
* The creation of a deflated SAML Request
2525
*
2626
* @covers OneLogin_Saml2_AuthnRequest
@@ -40,7 +40,7 @@ public function testCreateDeflatedSAMLRequestURLParameter()
4040
}
4141

4242
/**
43-
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
43+
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
4444
* The creation of a deflated SAML Request with AuthNContext
4545
*
4646
* @covers OneLogin_Saml2_AuthnRequest
@@ -86,10 +86,18 @@ public function testAuthNContext()
8686
$this->assertNotContains('<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>', $request4);
8787
$this->assertContains('<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>', $request4);
8888
$this->assertContains('<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:X509</saml:AuthnContextClassRef>', $request4);
89+
90+
$settingsInfo['security']['requestedAuthnContextComparison'] = 'minimum';
91+
$settings5 = new OneLogin_Saml2_Settings($settingsInfo);
92+
$authnRequest5 = new OneLogin_Saml2_AuthnRequest($settings5);
93+
$encodedRequest5 = $authnRequest5->getRequest();
94+
$decoded5 = base64_decode($encodedRequest5);
95+
$request5 = gzinflate($decoded5);
96+
$this->assertContains('<samlp:RequestedAuthnContext Comparison="minimum">', $request5);
8997
}
9098

9199
/**
92-
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
100+
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
93101
* The creation of a deflated SAML Request with ForceAuthn
94102
*
95103
* @covers OneLogin_Saml2_AuthnRequest
@@ -120,7 +128,7 @@ public function testForceAuthN()
120128
}
121129

122130
/**
123-
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
131+
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
124132
* The creation of a deflated SAML Request with isPassive
125133
*
126134
* @covers OneLogin_Saml2_AuthnRequest
@@ -151,7 +159,7 @@ public function testIsPassive()
151159
}
152160

153161
/**
154-
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
162+
* Tests the OneLogin_Saml2_AuthnRequest Constructor.
155163
* The creation of a deflated SAML Request
156164
*
157165
* @covers OneLogin_Saml2_AuthnRequest

0 commit comments

Comments
 (0)