Skip to content

Commit

Permalink
feat: add SPID metadata entityType (SPID Notice n.19 v.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
damikael committed May 17, 2023
1 parent 18e3162 commit 62be9c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
57 changes: 57 additions & 0 deletions setup/simplesamlphp/saml2/src/SAML2/XML/md/ContactPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class ContactPerson
*/
private $contactType;

/**
* The entity type. (Avviso SPID n.19 v.4)
*
* @var string
*/
private $entityType;
private $entityTypeNS;

/**
* Extensions on this element.
*
Expand Down Expand Up @@ -93,6 +101,15 @@ public function __construct(DOMElement $xml = null)
}
$this->setContactType($xml->getAttribute('contactType'));

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

$this->setExtensions(Extensions::getList($xml));

$this->setCompany(self::getStringElement($xml, 'Company'));
Expand Down Expand Up @@ -163,6 +180,25 @@ public function getContactType() : string
return $this->contactType;
}

/**
* Collect the value of the entityType
*
* @return string
*/
public function getEntityType() : string
{
return $this->entityType;
}

/**
* Collect the value of the entityTypeNS
*
* @return string
*/
public function getEntityTypeNS() : string
{
return $this->entityTypeNS;
}

/**
* Set the value of the contactType-property
Expand All @@ -175,6 +211,23 @@ public function setContactType(string $contactType) : void
$this->contactType = $contactType;
}

/**
* Set the value of the entityType
*
* @param string $entityType
* @return void
*/
public function setEntityType(string $entityType, string $ns=null) : void
{
if($ns!=null && $ns!='') {
$this->entityType = $ns.':'.$entityType;
$this->entityTypeNS = $ns;
} else {
$this->entityType = $entityType;
$this->entityTypeNS = null;
}
}


/**
* Collect the value of the Company-property
Expand Down Expand Up @@ -403,6 +456,10 @@ public function toXML(DOMElement $parent) : DOMElement

$e->setAttribute('contactType', $this->getContactType());

if ($this->entityType != null) {
$e->setAttribute($this->entityTypeNS . ($this->entityTypeNS? ':' : '') . 'entityType', $this->getEntityType());
}

foreach ($this->getContactPersonAttributes() as $attr => $val) {
$e->setAttribute($attr, $val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,10 @@ public function addContact($type, $details)
$e = new \SAML2\XML\md\ContactPerson();
$e->setContactType($type);

if(isset($details['spidEntityType'])) {
$e->setEntityType($details['spidEntityType'], 'spid');
}

$eexts = array();
$ext_dom = \SAML2\DOMDocumentFactory::create();

Expand Down Expand Up @@ -897,7 +901,7 @@ public function addContact($type, $details)
$eexts[] = new \SAML2\XML\Chunk($ext_elem);
}
}

$e->setExtensions($eexts);

if (!empty($details['attributes'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Metadata
*/
public static $VALID_CONTACT_OPTIONS = [
'contactType',
'spidEntityType',
'emailAddress',
'givenName',
'surName',
Expand Down

0 comments on commit 62be9c6

Please sign in to comment.