Skip to content

Commit

Permalink
Merge pull request #100 from italia/feature/issue-84-comparison
Browse files Browse the repository at this point in the history
implement `RequestedAuthnContext/@Comparison` customization and close #84
  • Loading branch information
simevo authored Jan 26, 2020
2 parents 5b353fd + f3062e9 commit 7bf942c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ $settings = array(
'sp_entityid' => SP_BASE_URL, // preferred: https protocol, no trailing slash, example: https://sp.example.com/
'sp_key_file' => '/path/to/sp.key',
'sp_cert_file' => '/path/to/sp.crt',
'sp_comparison' => 'exact', // one of: "exact", "minimum", "better" or "maximum"
'sp_assertionconsumerservice' => [
// order is important ! the 0-base index in this array will be used as ID in the calls
SP_BASE_URL . '/acs',
Expand Down Expand Up @@ -274,7 +275,7 @@ A Docker-based demo application is available at [https://github.com/simevo/spid-
|`AssertionConsumerServiceIndex` customization||
|`AttributeConsumingServiceIndex` customization||
|`AuthnContextClassRef` (SPID level) customization||
|`RequestedAuthnContext/@Comparison` customization||
|`RequestedAuthnContext/@Comparison` customization||
|`RelayState` customization (1.2.2)||
|**Response/Assertion parsing**||
|verification of `Signature` value (if any)||
Expand Down
1 change: 1 addition & 0 deletions src/Spid/Interfaces/SAMLInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SAMLInterface
// 'sp_entityid' => SP_BASE_URL, // preferred: https, no trailing slash, example: https://sp.example.com/
// 'sp_key_file' => '/path/to/sp.key',
// 'sp_cert_file' => '/path/to/sp.crt',
// 'sp_comparison' => 'exact', // one of: 'exact', 'minimum', 'better', 'maximum'
// 'sp_assertionconsumerservice' => [
// // order is important ! the 0-base index in this array will be used as ID in the calls
// SP_BASE_URL . '/acs',
Expand Down
9 changes: 7 additions & 2 deletions src/Spid/Saml/Out/AuthnRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public function generateXml()
$assertID = $this->idp->assertID;
$attrID = $this->idp->attrID;
$level = $this->idp->level;
$force = $level > 1 ? "true" : "false";
if (isset($this->idp->sp->settings['sp_comparison'])) {
$comparison = $this->idp->sp->settings['sp_comparison'];
} else {
$comparison = "exact";
}
$force = ($level > 1 || $comparison == "minimum") ? "true" : "false";

$authnRequestXml = <<<XML
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Expand All @@ -33,7 +38,7 @@ public function generateXml()
NameQualifier="$entityId"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">$entityId</saml:Issuer>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" />
<samlp:RequestedAuthnContext Comparison="exact">
<samlp:RequestedAuthnContext Comparison="$comparison">
<saml:AuthnContextClassRef>https://www.spid.gov.it/SpidL$level</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>
Expand Down
10 changes: 10 additions & 0 deletions src/Spid/Saml/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Settings
'sp_entityid' => self::REQUIRED,
'sp_key_file' => self::REQUIRED,
'sp_cert_file' => self::REQUIRED,
'sp_comparison' => self::NOT_REQUIRED,
'sp_assertionconsumerservice' => self::REQUIRED,
'sp_singlelogoutservice' => self::REQUIRED,
'sp_attributeconsumingservice' => self::NOT_REQUIRED,
Expand Down Expand Up @@ -236,5 +237,14 @@ private static function checkSettingsValues($settings)
throw new \InvalidArgumentException('accepted_clock_skew_seconds should be at most 300 seconds');
}
}
if (isset($settings['sp_comparison'])) {
if (strcasecmp($settings['sp_comparison'], "exact") != 0 &&
strcasecmp($settings['sp_comparison'], "minimum") != 0 &&
strcasecmp($settings['sp_comparison'], "better") != 0 &&
strcasecmp($settings['sp_comparison'], "maximum") != 0) {
throw new \InvalidArgumentException('sp_comparison value should be one of:' .
'"exact", "minimum", "better" or "maximum"');
}
}
}
}
8 changes: 8 additions & 0 deletions tests/SpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public function testSettingsWithInvalidSPEntityid()
new Italia\Spid\Sp($settings);
}

public function testSettingsWithInvalidComparison()
{
$settings = self::$settings;
$this->expectException(InvalidArgumentException::class);
$settings['sp_comparison'] = "invalid";
new Italia\Spid\Sp($settings);
}

public function testSettingsWithInvalidSpACS()
{
$settings = self::$settings;
Expand Down

0 comments on commit 7bf942c

Please sign in to comment.