You are here

public function SAML2_Assertion::decryptAttributes in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

Decrypt the assertion attributes.

Parameters

XMLSecurityKey $key:

array $blacklist:

Throws

Exception

File

includes/Assertion.php, line 572

Class

SAML2_Assertion

Code

public function decryptAttributes(XMLSecurityKey $key, array $blacklist = array()) {
  if ($this->encryptedAttribute === NULL) {
    return;
  }
  $firstAttribute = TRUE;
  $attributes = $this->encryptedAttribute;
  foreach ($attributes as $attributeEnc) {

    /*Decrypt node <EncryptedAttribute>*/
    $attribute = Utilities::decryptElement($attributeEnc
      ->getElementsByTagName('EncryptedData')
      ->item(0), $key, $blacklist);
    if (!$attribute
      ->hasAttribute('Name')) {
      throw new Exception('Missing name on <saml:Attribute> element.');
    }
    $name = $attribute
      ->getAttribute('Name');
    if ($attribute
      ->hasAttribute('NameFormat')) {
      $nameFormat = $attribute
        ->getAttribute('NameFormat');
    }
    else {
      $nameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified';
    }
    if ($firstAttribute) {
      $this->nameFormat = $nameFormat;
      $firstAttribute = FALSE;
    }
    else {
      if ($this->nameFormat !== $nameFormat) {
        $this->nameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified';
      }
    }
    if (!array_key_exists($name, $this->attributes)) {
      $this->attributes[$name] = array();
    }
    $values = Utilities::xpQuery($attribute, './saml_assertion:AttributeValue');
    foreach ($values as $value) {
      $this->attributes[$name][] = trim($value->textContent);
    }
  }
}