Skip to content

Commit

Permalink
Fix CIE Metadata
Browse files Browse the repository at this point in the history
Fix CIE Metadata
  • Loading branch information
damikael authored Sep 25, 2023
2 parents 76ccaf6 + c1608bb commit 1e096cb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
17 changes: 10 additions & 7 deletions setup/config/authsources_cie_private.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@
'telephoneNumber' => {{ORGANIZATIONTELEPHONENUMBER}},
'extensions' =>
array (
'Private' => NULL,
'VATNumber' => {{ORGANIZATIONCODE}},
'FiscalCode' => {{ORGANIZATIONFISCALCODE}},
'NACE2Code' => {{ORGANIZATIONNACE2CODE}},
'Municipality' => {{ORGANIZATIONMUNICIPALITY}},
'Province' => {{ORGANIZATIONPROVINCE}},
'Country' => {{ORGANIZATIONCOUNTRY}},
'ns' => 'cie:https://www.cartaidentita.interno.gov.it/saml-extensions',
'elements' => array(
'cie:Private' => NULL,
'cie:VATNumber' => {{ORGANIZATIONCODE}},
'cie:FiscalCode' => {{ORGANIZATIONFISCALCODE}},
'cie:NACE2Code' => {{ORGANIZATIONNACE2CODE}},
'cie:Municipality' => {{ORGANIZATIONMUNICIPALITY}},
'cie:Province' => {{ORGANIZATIONPROVINCE}},
'cie:Country' => {{ORGANIZATIONCOUNTRY}},
)
),
),
)
Expand Down
13 changes: 8 additions & 5 deletions setup/config/authsources_cie_public.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@
'telephoneNumber' => {{ORGANIZATIONTELEPHONENUMBER}},
'extensions' =>
array (
'Public' => NULL,
'IPACode' => {{ORGANIZATIONCODE}},
'Municipality' => {{ORGANIZATIONMUNICIPALITY}},
'Province' => {{ORGANIZATIONPROVINCE}},
'Country' => {{ORGANIZATIONCOUNTRY}},
'ns' => 'cie:https://www.cartaidentita.interno.gov.it/saml-extensions',
'elements' => array(
'cie:Public' => NULL,
'cie:IPACode' => {{ORGANIZATIONCODE}},
'cie:Municipality' => {{ORGANIZATIONMUNICIPALITY}},
'cie:Province' => {{ORGANIZATIONPROVINCE}},
'cie:Country' => {{ORGANIZATIONCOUNTRY}},
)
),
),
)
Expand Down
18 changes: 16 additions & 2 deletions setup/simplesamlphp/saml2/src/SAML2/XML/md/ContactPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ public function __construct(DOMElement $xml = null)
$this->setContactType($xml->getAttribute('contactType'));

if ($xml->hasAttribute('entityType')) {
// SPID Entity Type (Avviso SPID n.19 v.4)
// SPID Entity Type (Avviso SPID n.19 v.4)
if(substr($xml->getAttribute('entityType'), 0, 5)=='spid:') {
$this->setEntityType($xml->getAttribute('entityType'), 'spid:https://spid.gov.it/saml-extensions');

} else if(substr($xml->getAttribute('entityType'), 0, 4)=='cie:') {
$this->setEntityType($xml->getAttribute('entityType'), 'cie:https://www.cartaidentita.interno.gov.it/saml-extensions');

} else {
$this->setEntityType($xml->getAttribute('entityType'));
}
Expand Down Expand Up @@ -452,7 +456,17 @@ public function toXML(DOMElement $parent) : DOMElement
$e->setAttribute('contactType', $this->getContactType());

if ($this->entityType != null) {
$attribute = ($this->entityTypeNS=='spid:https://spid.gov.it/saml-extensions')? 'spid:entityType' : 'entityType';

if($this->entityTypeNS=='spid:https://spid.gov.it/saml-extensions') {
$attribute = 'spid:entityType';

} else if($this->entityTypeNS=='cie:https://www.cartaidentita.interno.gov.it/saml-extensions') {
$attribute = 'cie:entityType';

} else {
$attribute = 'entityType';
}

$e->setAttribute($attribute, $this->entityType);
}

Expand Down
10 changes: 10 additions & 0 deletions setup/simplesamlphp/saml2/src/SAML2/XML/md/EntityDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function __construct(DOMElement $xml = null)
$this->ns['spid'] = $xml->getAttribute('xmlns:spid');
}

// get cie namespace if exists
if($xml->hasAttribute('xmlns:cie')) {
$this->ns['cie'] = $xml->getAttribute('xmlns:cie');
}

if (!$xml->hasAttribute('entityID')) {
throw new \Exception('Missing required attribute entityID on EntityDescriptor.');
}
Expand Down Expand Up @@ -506,6 +511,11 @@ public function toXML(DOMElement $parent = null) : DOMElement
$e->setAttribute('xmlns:spid', $this->ns['spid']);
}

// set cie namespace if exists
if ($this->ns['cie'] !== null) {
$e->setAttribute('xmlns:cie', $this->ns['cie']);
}

$e->setAttribute('entityID', $this->entityID);

if ($this->ID !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ public function addContact($type, $details)
$e = new \SAML2\XML\md\ContactPerson();
$e->setContactType($type);

// OLD
if(isset($details['spidEntityType'])) {
$this->entityDescriptor->setNamespace('spid', 'https://spid.gov.it/saml-extensions');
$e->setEntityType('spid:'.$details['spidEntityType'], 'spid:https://spid.gov.it/saml-extensions');
Expand Down Expand Up @@ -897,8 +898,11 @@ public function addContact($type, $details)

if (isset($details['extensions'])) {
$ns = $details['extensions']['ns'];
if(substr($ns, 0, 5)=='spid:') {
$this->entityDescriptor->setNamespace('spid', 'https://spid.gov.it/saml-extensions');

if($ns!=null) {
$nsval = explode(':', $ns, 2);
if(count($nsval)!=2) throw new \Exception('ns must be of type ns:val');
$this->entityDescriptor->setNamespace($nsval[0], $nsval[1]);
}

foreach($details['extensions']['elements'] as $e_key => $e_val) {
Expand Down

0 comments on commit 1e096cb

Please sign in to comment.