ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
sspmod_saml_IdP_SAML2 Class Reference
+ Collaboration diagram for sspmod_saml_IdP_SAML2:

Static Public Member Functions

static sendResponse (array $state)
 Send a response to the SP. More...
 
static handleAuthError (SimpleSAML_Error_Exception $exception, array $state)
 Handle authentication error. More...
 
static receiveAuthnRequest (SimpleSAML_IdP $idp)
 Receive an authentication request. More...
 
static sendLogoutRequest (SimpleSAML_IdP $idp, array $association, $relayState)
 Send a logout request to a given association. More...
 
static sendLogoutResponse (SimpleSAML_IdP $idp, array $state)
 Send a logout response. More...
 
static receiveLogoutMessage (SimpleSAML_IdP $idp)
 Receive a logout message. More...
 
static getLogoutURL (SimpleSAML_IdP $idp, array $association, $relayState)
 Retrieve a logout URL for a given logout association. More...
 
static getAssociationConfig (SimpleSAML_IdP $idp, array $association)
 Retrieve the metadata for the given SP association. More...
 

Static Private Member Functions

static getAssertionConsumerService (array $supportedBindings, SimpleSAML_Configuration $spMetadata, $AssertionConsumerServiceURL, $ProtocolBinding, $AssertionConsumerServiceIndex)
 Find SP AssertionConsumerService based on parameter in AuthnRequest. More...
 
static generateNameIdValue (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, array &$state)
 Calculate the NameID value that should be used. More...
 
static encodeAttributes (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, array $attributes)
 Helper function for encoding attributes. More...
 
static getAttributeNameFormat (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata)
 Determine which NameFormat we should use for attributes. More...
 
static buildAssertion (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, array &$state)
 Build an assertion based on information in the metadata. More...
 
static encryptAssertion (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, \SAML2\Assertion $assertion)
 Encrypt an assertion. More...
 
static buildLogoutRequest (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, array $association, $relayState)
 Build a logout request based on information in the metadata. More...
 
static buildResponse (SimpleSAML_Configuration $idpMetadata, SimpleSAML_Configuration $spMetadata, $consumerURL)
 Build a authentication response based on information in the metadata. More...
 

Detailed Description

Definition at line 11 of file SAML2.php.

Member Function Documentation

◆ buildAssertion()

static sspmod_saml_IdP_SAML2::buildAssertion ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
array $state 
)
staticprivate

Build an assertion based on information in the metadata.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
array&$stateThe state array with information about the request.
Returns
The assertion.
Exceptions
SimpleSAML_Error_ExceptionIn case an error occurs when creating a holder-of-key assertion.

Definition at line 845 of file SAML2.php.

References $_SERVER, $assertionLifetime, $attributeNameFormat, $attributes, $config, $encryptNameId, $nameId, $nameIdFormat, $nameIdValue, $sc, sspmod_saml_Message\addSign(), array, SAML2\Constants\CM_BEARER, SAML2\Constants\CM_HOK, SimpleSAML\Utils\Random\generateID(), SimpleSAML_Configuration\getBoolean(), sspmod_saml_Message\getEncryptionKey(), SimpleSAML_Configuration\getInstance(), SimpleSAML_Configuration\getInteger(), SimpleSAML_Configuration\getString(), SAML2\Constants\NAMEID_TRANSIENT, SubjectConfirmationData, time, and SimpleSAML\Logger\warning().

849  {
850  assert('isset($state["Attributes"])');
851  assert('isset($state["saml:ConsumerURL"])');
852 
853  $now = time();
854 
855  $signAssertion = $spMetadata->getBoolean('saml20.sign.assertion', null);
856  if ($signAssertion === null) {
857  $signAssertion = $idpMetadata->getBoolean('saml20.sign.assertion', true);
858  }
859 
861 
862  $a = new \SAML2\Assertion();
863  if ($signAssertion) {
864  sspmod_saml_Message::addSign($idpMetadata, $spMetadata, $a);
865  }
866 
867  $a->setIssuer($idpMetadata->getString('entityid'));
868  $a->setValidAudiences(array($spMetadata->getString('entityid')));
869 
870  $a->setNotBefore($now - 30);
871 
872  $assertionLifetime = $spMetadata->getInteger('assertion.lifetime', null);
873  if ($assertionLifetime === null) {
874  $assertionLifetime = $idpMetadata->getInteger('assertion.lifetime', 300);
875  }
876  $a->setNotOnOrAfter($now + $assertionLifetime);
877 
878  if (isset($state['saml:AuthnContextClassRef'])) {
879  $a->setAuthnContext($state['saml:AuthnContextClassRef']);
880  } else {
881  $a->setAuthnContext(\SAML2\Constants::AC_PASSWORD);
882  }
883 
884  $sessionStart = $now;
885  if (isset($state['AuthnInstant'])) {
886  $a->setAuthnInstant($state['AuthnInstant']);
887  $sessionStart = $state['AuthnInstant'];
888  }
889 
890  $sessionLifetime = $config->getInteger('session.duration', 8 * 60 * 60);
891  $a->setSessionNotOnOrAfter($sessionStart + $sessionLifetime);
892 
893  $a->setSessionIndex(SimpleSAML\Utils\Random::generateID());
894 
895  $sc = new \SAML2\XML\saml\SubjectConfirmation();
896  $sc->SubjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData();
897  $sc->SubjectConfirmationData->NotOnOrAfter = $now + $assertionLifetime;
898  $sc->SubjectConfirmationData->Recipient = $state['saml:ConsumerURL'];
899  $sc->SubjectConfirmationData->InResponseTo = $state['saml:RequestId'];
900 
901  // ProtcolBinding of SP's <AuthnRequest> overwrites IdP hosted metadata configuration
902  $hokAssertion = null;
903  if ($state['saml:Binding'] === \SAML2\Constants::BINDING_HOK_SSO) {
904  $hokAssertion = true;
905  }
906  if ($hokAssertion === null) {
907  $hokAssertion = $idpMetadata->getBoolean('saml20.hok.assertion', false);
908  }
909 
910  if ($hokAssertion) {
911  // Holder-of-Key
912  $sc->Method = \SAML2\Constants::CM_HOK;
913  if (\SimpleSAML\Utils\HTTP::isHTTPS()) {
914  if (isset($_SERVER['SSL_CLIENT_CERT']) && !empty($_SERVER['SSL_CLIENT_CERT'])) {
915  // extract certificate data (if this is a certificate)
916  $clientCert = $_SERVER['SSL_CLIENT_CERT'];
917  $pattern = '/^-----BEGIN CERTIFICATE-----([^-]*)^-----END CERTIFICATE-----/m';
918  if (preg_match($pattern, $clientCert, $matches)) {
919  // we have a client certificate from the browser which we add to the HoK assertion
920  $x509Certificate = new \SAML2\XML\ds\X509Certificate();
921  $x509Certificate->certificate = str_replace(array("\r", "\n", " "), '', $matches[1]);
922 
923  $x509Data = new \SAML2\XML\ds\X509Data();
924  $x509Data->data[] = $x509Certificate;
925 
926  $keyInfo = new \SAML2\XML\ds\KeyInfo();
927  $keyInfo->info[] = $x509Data;
928 
929  $sc->SubjectConfirmationData->info[] = $keyInfo;
930  } else {
931  throw new SimpleSAML_Error_Exception(
932  'Error creating HoK assertion: No valid client certificate provided during TLS handshake '.
933  'with IdP'
934  );
935  }
936  } else {
937  throw new SimpleSAML_Error_Exception(
938  'Error creating HoK assertion: No client certificate provided during TLS handshake with IdP'
939  );
940  }
941  } else {
942  throw new SimpleSAML_Error_Exception(
943  'Error creating HoK assertion: No HTTPS connection to IdP, but required for Holder-of-Key SSO'
944  );
945  }
946  } else {
947  // Bearer
949  }
950  $a->setSubjectConfirmation(array($sc));
951 
952  // add attributes
953  if ($spMetadata->getBoolean('simplesaml.attributes', true)) {
954  $attributeNameFormat = self::getAttributeNameFormat($idpMetadata, $spMetadata);
955  $a->setAttributeNameFormat($attributeNameFormat);
956  $attributes = self::encodeAttributes($idpMetadata, $spMetadata, $state['Attributes']);
957  $a->setAttributes($attributes);
958  }
959 
960  // generate the NameID for the assertion
961  if (isset($state['saml:NameIDFormat'])) {
962  $nameIdFormat = $state['saml:NameIDFormat'];
963  } else {
964  $nameIdFormat = null;
965  }
966 
967  if ($nameIdFormat === null || !isset($state['saml:NameID'][$nameIdFormat])) {
968  // either not set in request, or not set to a format we supply. Fall back to old generation method
969  $nameIdFormat = $spMetadata->getString('NameIDFormat', null);
970  if ($nameIdFormat === null) {
971  $nameIdFormat = $idpMetadata->getString('NameIDFormat', \SAML2\Constants::NAMEID_TRANSIENT);
972  }
973  }
974 
975  if (isset($state['saml:NameID'][$nameIdFormat])) {
976  $nameId = $state['saml:NameID'][$nameIdFormat];
977  $nameId->Format = $nameIdFormat;
978  } else {
979  $spNameQualifier = $spMetadata->getString('SPNameQualifier', null);
980  if ($spNameQualifier === null) {
981  $spNameQualifier = $spMetadata->getString('entityid');
982  }
983 
984  if ($nameIdFormat === \SAML2\Constants::NAMEID_TRANSIENT) {
985  // generate a random id
987  } else {
988  /* this code will end up generating either a fixed assigned id (via nameid.attribute)
989  or random id if not assigned/configured */
990  $nameIdValue = self::generateNameIdValue($idpMetadata, $spMetadata, $state);
991  if ($nameIdValue === null) {
992  SimpleSAML\Logger::warning('Falling back to transient NameID.');
993  $nameIdFormat = \SAML2\Constants::NAMEID_TRANSIENT;
995  }
996  }
997 
998  $nameId = new \SAML2\XML\saml\NameID();
999  $nameId->Format = $nameIdFormat;
1000  $nameId->value = $nameIdValue;
1001  $nameId->SPNameQualifier = $spNameQualifier;
1002  }
1003 
1004  $state['saml:idp:NameID'] = $nameId;
1005 
1006  $a->setNameId($nameId);
1007 
1008  $encryptNameId = $spMetadata->getBoolean('nameid.encryption', null);
1009  if ($encryptNameId === null) {
1010  $encryptNameId = $idpMetadata->getBoolean('nameid.encryption', false);
1011  }
1012  if ($encryptNameId) {
1013  $a->encryptNameId(sspmod_saml_Message::getEncryptionKey($spMetadata));
1014  }
1015 
1016  return $a;
1017  }
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$assertionLifetime
$sc SubjectConfirmationData
const CM_HOK
Holder-of-Key subject confirmation method.
Definition: Constants.php:60
$nameIdFormat
$attributes
$nameIdValue
$nameId
Definition: saml2-acs.php:138
$encryptNameId
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Attribute-related utility methods.
static warning($string)
Definition: Logger.php:179
const CM_BEARER
Bearer subject confirmation method.
Definition: Constants.php:55
$attributeNameFormat
static addSign(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata, \SAML2\SignedElement $element)
Add signature key and sender certificate to an element (Message or Assertion).
Definition: Message.php:20
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
Create styles array
The data for the language used.
const NAMEID_TRANSIENT
Transient NameID format.
Definition: Constants.php:195
getInteger($name, $default=self::REQUIRED_OPTION)
This function retrieves an integer configuration option.
static getEncryptionKey(SimpleSAML_Configuration $metadata)
Retrieve the encryption key for the given entity.
Definition: Message.php:829
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:

◆ buildLogoutRequest()

static sspmod_saml_IdP_SAML2::buildLogoutRequest ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
array  $association,
  $relayState 
)
staticprivate

Build a logout request based on information in the metadata.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
array$associationThe SP association.
string | null$relayStateAn id that should be carried across the logout.
Returns
The corresponding SAML2 logout response.

Definition at line 1088 of file SAML2.php.

References $assertionLifetime, $encryptNameId, $lr, $relayState, sspmod_saml_Message\buildLogoutRequest(), SimpleSAML_Configuration\getBoolean(), sspmod_saml_Message\getEncryptionKey(), SimpleSAML_Configuration\getInteger(), and time.

1093  {
1094 
1095  $lr = sspmod_saml_Message::buildLogoutRequest($idpMetadata, $spMetadata);
1096  $lr->setRelayState($relayState);
1097  $lr->setSessionIndex($association['saml:SessionIndex']);
1098  $lr->setNameId($association['saml:NameID']);
1099 
1100  $assertionLifetime = $spMetadata->getInteger('assertion.lifetime', null);
1101  if ($assertionLifetime === null) {
1102  $assertionLifetime = $idpMetadata->getInteger('assertion.lifetime', 300);
1103  }
1104  $lr->setNotOnOrAfter(time() + $assertionLifetime);
1105 
1106  $encryptNameId = $spMetadata->getBoolean('nameid.encryption', null);
1107  if ($encryptNameId === null) {
1108  $encryptNameId = $idpMetadata->getBoolean('nameid.encryption', false);
1109  }
1110  if ($encryptNameId) {
1111  $lr->encryptNameId(sspmod_saml_Message::getEncryptionKey($spMetadata));
1112  }
1113 
1114  return $lr;
1115  }
$assertionLifetime
static buildLogoutRequest(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata)
Build a logout request based on information in the metadata.
Definition: Message.php:501
$encryptNameId
$relayState
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
getInteger($name, $default=self::REQUIRED_OPTION)
This function retrieves an integer configuration option.
static getEncryptionKey(SimpleSAML_Configuration $metadata)
Retrieve the encryption key for the given entity.
Definition: Message.php:829
if(!isset($associations[$assocId])) $association
$lr
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:

◆ buildResponse()

static sspmod_saml_IdP_SAML2::buildResponse ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
  $consumerURL 
)
staticprivate

Build a authentication response based on information in the metadata.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
string$consumerURLThe Destination URL of the response.
Returns
The SAML2 response corresponding to the given data.

Definition at line 1127 of file SAML2.php.

References $r, sspmod_saml_Message\addSign(), SimpleSAML_Configuration\getBoolean(), and SimpleSAML_Configuration\getString().

1131  {
1132 
1133  $signResponse = $spMetadata->getBoolean('saml20.sign.response', null);
1134  if ($signResponse === null) {
1135  $signResponse = $idpMetadata->getBoolean('saml20.sign.response', true);
1136  }
1137 
1138  $r = new \SAML2\Response();
1139 
1140  $r->setIssuer($idpMetadata->getString('entityid'));
1141  $r->setDestination($consumerURL);
1142 
1143  if ($signResponse) {
1144  sspmod_saml_Message::addSign($idpMetadata, $spMetadata, $r);
1145  }
1146 
1147  return $r;
1148  }
$r
Definition: example_031.php:79
static addSign(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata, \SAML2\SignedElement $element)
Add signature key and sender certificate to an element (Message or Assertion).
Definition: Message.php:20
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
+ Here is the call graph for this function:

◆ encodeAttributes()

static sspmod_saml_IdP_SAML2::encodeAttributes ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
array  $attributes 
)
staticprivate

Helper function for encoding attributes.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
array$attributesThe attributes of the user.
Returns
array The encoded attributes.
Exceptions
SimpleSAML_Error_ExceptionIn case an unsupported encoding is specified by configuration.

Definition at line 723 of file SAML2.php.

References $name, $ret, array, SAML2\DOMDocumentFactory\fromString(), SimpleSAML_Configuration\getArray(), SimpleSAML_Configuration\getBoolean(), and string.

727  {
728 
729  $base64Attributes = $spMetadata->getBoolean('base64attributes', null);
730  if ($base64Attributes === null) {
731  $base64Attributes = $idpMetadata->getBoolean('base64attributes', false);
732  }
733 
734  if ($base64Attributes) {
735  $defaultEncoding = 'base64';
736  } else {
737  $defaultEncoding = 'string';
738  }
739 
740  $srcEncodings = $idpMetadata->getArray('attributeencodings', array());
741  $dstEncodings = $spMetadata->getArray('attributeencodings', array());
742 
743  /*
744  * Merge the two encoding arrays. Encodings specified in the target metadata
745  * takes precedence over the source metadata.
746  */
747  $encodings = array_merge($srcEncodings, $dstEncodings);
748 
749  $ret = array();
750  foreach ($attributes as $name => $values) {
751  $ret[$name] = array();
752  if (array_key_exists($name, $encodings)) {
753  $encoding = $encodings[$name];
754  } else {
755  $encoding = $defaultEncoding;
756  }
757 
758  foreach ($values as $value) {
759  // allow null values
760  if ($value === null) {
761  $ret[$name][] = $value;
762  continue;
763  }
764 
765  $attrval = $value;
766  if ($value instanceof DOMNodeList) {
767  $attrval = new \SAML2\XML\saml\AttributeValue($value->item(0)->parentNode);
768  }
769 
770  switch ($encoding) {
771  case 'string':
772  $value = (string) $attrval;
773  break;
774  case 'base64':
775  $value = base64_encode((string) $attrval);
776  break;
777  case 'raw':
778  if (is_string($value)) {
779  $doc = \SAML2\DOMDocumentFactory::fromString('<root>'.$value.'</root>');
780  $value = $doc->firstChild->childNodes;
781  }
782  assert('$value instanceof DOMNodeList || $value instanceof \SAML2\XML\saml\NameID');
783  break;
784  default:
785  throw new SimpleSAML_Error_Exception('Invalid encoding for attribute '.
786  var_export($name, true).': '.var_export($encoding, true));
787  }
788  $ret[$name][] = $value;
789  }
790  }
791 
792  return $ret;
793  }
Add rich text string
getArray($name, $default=self::REQUIRED_OPTION)
This function retrieves an array configuration option.
$attributes
if($format !==null) $name
Definition: metadata.php:146
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
+ Here is the call graph for this function:

◆ encryptAssertion()

static sspmod_saml_IdP_SAML2::encryptAssertion ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
\SAML2\Assertion  $assertion 
)
staticprivate

Encrypt an assertion.

This function takes in a and encrypts it if encryption of assertions are enabled in the metadata.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
\SAML2\Assertion$assertionThe assertion we are encrypting.
Returns
| The assertion.
Exceptions
SimpleSAML_Error_ExceptionIn case the encryption key type is not supported.

Definition at line 1034 of file SAML2.php.

References $key, $keys, array, SimpleSAML_Configuration\getBoolean(), SimpleSAML_Configuration\getPublicKeys(), and SimpleSAML_Configuration\getString().

1038  {
1039 
1040  $encryptAssertion = $spMetadata->getBoolean('assertion.encryption', null);
1041  if ($encryptAssertion === null) {
1042  $encryptAssertion = $idpMetadata->getBoolean('assertion.encryption', false);
1043  }
1044  if (!$encryptAssertion) {
1045  // we are _not_ encrypting this assertion, and are therefore done
1046  return $assertion;
1047  }
1048 
1049 
1050  $sharedKey = $spMetadata->getString('sharedkey', null);
1051  if ($sharedKey !== null) {
1052  $key = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
1053  $key->loadKey($sharedKey);
1054  } else {
1055  $keys = $spMetadata->getPublicKeys('encryption', true);
1056  $key = $keys[0];
1057  switch ($key['type']) {
1058  case 'X509Certificate':
1059  $pemKey = "-----BEGIN CERTIFICATE-----\n".
1060  chunk_split($key['X509Certificate'], 64).
1061  "-----END CERTIFICATE-----\n";
1062  break;
1063  default:
1064  throw new SimpleSAML_Error_Exception('Unsupported encryption key type: '.$key['type']);
1065  }
1066 
1067  // extract the public key from the certificate for encryption
1068  $key = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type' => 'public'));
1069  $key->loadKey($pemKey);
1070  }
1071 
1072  $ea = new \SAML2\EncryptedAssertion();
1073  $ea->setAssertion($assertion, $key);
1074  return $ea;
1075  }
$keys
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
Create styles array
The data for the language used.
getPublicKeys($use=null, $required=false, $prefix='')
Get public key from metadata.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ generateNameIdValue()

static sspmod_saml_IdP_SAML2::generateNameIdValue ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata,
array $state 
)
staticprivate

Calculate the NameID value that should be used.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$dstMetadataThe metadata of the SP.
array&$stateThe authentication state of the user.
Returns
string The NameID value.

Definition at line 671 of file SAML2.php.

References $attributes, $idpEntityId, $spEntityId, SimpleSAML\Logger\error(), SimpleSAML\Utils\Config\getSecretSalt(), SimpleSAML_Configuration\getString(), and GuzzleHttp\Psr7\hash().

675  {
676 
677  $attribute = $spMetadata->getString('simplesaml.nameidattribute', null);
678  if ($attribute === null) {
679  $attribute = $idpMetadata->getString('simplesaml.nameidattribute', null);
680  if ($attribute === null) {
681  if (!isset($state['UserID'])) {
682  SimpleSAML\Logger::error('Unable to generate NameID. Check the userid.attribute option.');
683  return null;
684  }
685  $attributeValue = $state['UserID'];
686  $idpEntityId = $idpMetadata->getString('entityid');
687  $spEntityId = $spMetadata->getString('entityid');
688 
690 
691  $uidData = 'uidhashbase'.$secretSalt;
692  $uidData .= strlen($idpEntityId).':'.$idpEntityId;
693  $uidData .= strlen($spEntityId).':'.$spEntityId;
694  $uidData .= strlen($attributeValue).':'.$attributeValue;
695  $uidData .= $secretSalt;
696 
697  return hash('sha1', $uidData);
698  }
699  }
700 
701  $attributes = $state['Attributes'];
702  if (!array_key_exists($attribute, $attributes)) {
703  SimpleSAML\Logger::error('Unable to add NameID: Missing '.var_export($attribute, true).
704  ' in the attributes of the user.');
705  return null;
706  }
707 
708  return $attributes[$attribute][0];
709  }
$idpEntityId
Definition: prp.php:12
$spEntityId
static getSecretSalt()
Retrieve the secret salt.
Definition: Config.php:49
$attributes
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static error($string)
Definition: Logger.php:168
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
+ Here is the call graph for this function:

◆ getAssertionConsumerService()

static sspmod_saml_IdP_SAML2::getAssertionConsumerService ( array  $supportedBindings,
SimpleSAML_Configuration  $spMetadata,
  $AssertionConsumerServiceURL,
  $ProtocolBinding,
  $AssertionConsumerServiceIndex 
)
staticprivate

Find SP AssertionConsumerService based on parameter in AuthnRequest.

Parameters
array$supportedBindingsThe bindings we allow for the response.
SimpleSAML_Configuration$spMetadataThe metadata for the SP.
string | NULL$AssertionConsumerServiceURLAssertionConsumerServiceURL from request.
string | NULL$ProtocolBindingProtocolBinding from request.
int | NULL$AssertionConsumerServiceIndexAssertionConsumerServiceIndex from request.
Returns
array Array with the Location and Binding we should use for the response.

Definition at line 162 of file SAML2.php.

References SimpleSAML_Configuration\getDefaultEndpoint(), SimpleSAML_Configuration\getEndpoints(), and SimpleSAML\Logger\warning().

168  {
169  assert('is_string($AssertionConsumerServiceURL) || is_null($AssertionConsumerServiceURL)');
170  assert('is_string($ProtocolBinding) || is_null($ProtocolBinding)');
171  assert('is_int($AssertionConsumerServiceIndex) || is_null($AssertionConsumerServiceIndex)');
172 
173  /* We want to pick the best matching endpoint in the case where for example
174  * only the ProtocolBinding is given. We therefore pick endpoints with the
175  * following priority:
176  * 1. isDefault="true"
177  * 2. isDefault unset
178  * 3. isDefault="false"
179  */
180  $firstNotFalse = null;
181  $firstFalse = null;
182  foreach ($spMetadata->getEndpoints('AssertionConsumerService') as $ep) {
183  if ($AssertionConsumerServiceURL !== null && $ep['Location'] !== $AssertionConsumerServiceURL) {
184  continue;
185  }
186  if ($ProtocolBinding !== null && $ep['Binding'] !== $ProtocolBinding) {
187  continue;
188  }
189  if ($AssertionConsumerServiceIndex !== null && $ep['index'] !== $AssertionConsumerServiceIndex) {
190  continue;
191  }
192 
193  if (!in_array($ep['Binding'], $supportedBindings, true)) {
194  /* The endpoint has an unsupported binding. */
195  continue;
196  }
197 
198  // we have an endpoint that matches all our requirements. Check if it is the best one
199 
200  if (array_key_exists('isDefault', $ep)) {
201  if ($ep['isDefault'] === true) {
202  // this is the first matching endpoint with isDefault set to true
203  return $ep;
204  }
205  // isDefault is set to FALSE, but the endpoint is still usable
206  if ($firstFalse === null) {
207  // this is the first endpoint that we can use
208  $firstFalse = $ep;
209  }
210  } else {
211  if ($firstNotFalse === null) {
212  // this is the first endpoint without isDefault set
213  $firstNotFalse = $ep;
214  }
215  }
216  }
217 
218  if ($firstNotFalse !== null) {
219  return $firstNotFalse;
220  } elseif ($firstFalse !== null) {
221  return $firstFalse;
222  }
223 
224  SimpleSAML\Logger::warning('Authentication request specifies invalid AssertionConsumerService:');
225  if ($AssertionConsumerServiceURL !== null) {
226  SimpleSAML\Logger::warning('AssertionConsumerServiceURL: '.var_export($AssertionConsumerServiceURL, true));
227  }
228  if ($ProtocolBinding !== null) {
229  SimpleSAML\Logger::warning('ProtocolBinding: '.var_export($ProtocolBinding, true));
230  }
231  if ($AssertionConsumerServiceIndex !== null) {
233  'AssertionConsumerServiceIndex: '.var_export($AssertionConsumerServiceIndex, true)
234  );
235  }
236 
237  // we have no good endpoints. Our last resort is to just use the default endpoint
238  return $spMetadata->getDefaultEndpoint('AssertionConsumerService', $supportedBindings);
239  }
getEndpoints($endpointType)
Helper function for dealing with metadata endpoints.
getDefaultEndpoint($endpointType, array $bindings=null, $default=self::REQUIRED_OPTION)
Find the default endpoint of the given type.
static warning($string)
Definition: Logger.php:179
+ Here is the call graph for this function:

◆ getAssociationConfig()

static sspmod_saml_IdP_SAML2::getAssociationConfig ( SimpleSAML_IdP  $idp,
array  $association 
)
static

Retrieve the metadata for the given SP association.

Parameters
SimpleSAML_IdP$idpThe IdP the association belongs to.
array$associationThe SP association.
Returns
SimpleSAML_Configuration Configuration object for the SP metadata.

Definition at line 651 of file SAML2.php.

References $metadata, array, SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), and SimpleSAML_Configuration\loadFromArray().

652  {
654  try {
655  return $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
656  } catch (Exception $e) {
657  return SimpleSAML_Configuration::loadFromArray(array(), 'Unknown SAML 2 entity.');
658  }
659  }
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
$metadata['__DYNAMIC:1__']
Create styles array
The data for the language used.
if(!isset($associations[$assocId])) $association
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
+ Here is the call graph for this function:

◆ getAttributeNameFormat()

static sspmod_saml_IdP_SAML2::getAttributeNameFormat ( SimpleSAML_Configuration  $idpMetadata,
SimpleSAML_Configuration  $spMetadata 
)
staticprivate

Determine which NameFormat we should use for attributes.

Parameters
SimpleSAML_Configuration$idpMetadataThe metadata of the IdP.
SimpleSAML_Configuration$spMetadataThe metadata of the SP.
Returns
string The NameFormat.

Definition at line 804 of file SAML2.php.

References $attributeNameFormat, and SimpleSAML_Configuration\getString().

807  {
808 
809  // try SP metadata first
810  $attributeNameFormat = $spMetadata->getString('attributes.NameFormat', null);
811  if ($attributeNameFormat !== null) {
812  return $attributeNameFormat;
813  }
814  $attributeNameFormat = $spMetadata->getString('AttributeNameFormat', null);
815  if ($attributeNameFormat !== null) {
816  return $attributeNameFormat;
817  }
818 
819  // look in IdP metadata
820  $attributeNameFormat = $idpMetadata->getString('attributes.NameFormat', null);
821  if ($attributeNameFormat !== null) {
822  return $attributeNameFormat;
823  }
824  $attributeNameFormat = $idpMetadata->getString('AttributeNameFormat', null);
825  if ($attributeNameFormat !== null) {
826  return $attributeNameFormat;
827  }
828 
829  // default
830  return 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic';
831  }
$attributeNameFormat
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
+ Here is the call graph for this function:

◆ getLogoutURL()

static sspmod_saml_IdP_SAML2::getLogoutURL ( SimpleSAML_IdP  $idp,
array  $association,
  $relayState 
)
static

Retrieve a logout URL for a given logout association.

Parameters
SimpleSAML_IdP$idpThe IdP we are sending a logout request from.
array$associationThe association that should be terminated.
string | NULL$relayStateAn id that should be carried across the logout.
Returns
string The logout URL.

Definition at line 611 of file SAML2.php.

References $binding, $bindings, $dst, $idpMetadata, $lr, $metadata, $params, $relayState, $spMetadata, array, SimpleSAML_IdP\getConfig(), SimpleSAML_IdP\getId(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), SimpleSAML\Module\getModuleURL(), and SimpleSAML\Logger\info().

612  {
613  assert('is_string($relayState) || is_null($relayState)');
614 
615  SimpleSAML\Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
616 
618  $idpMetadata = $idp->getConfig();
619  $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
620 
621  $bindings = array(
622  \SAML2\Constants::BINDING_HTTP_REDIRECT,
623  \SAML2\Constants::BINDING_HTTP_POST
624  );
625  $dst = $spMetadata->getEndpointPrioritizedByBinding('SingleLogoutService', $bindings);
626 
627  if ($dst['Binding'] === \SAML2\Constants::BINDING_HTTP_POST) {
628  $params = array('association' => $association['id'], 'idp' => $idp->getId());
629  if ($relayState !== null) {
630  $params['RelayState'] = $relayState;
631  }
632  return SimpleSAML\Module::getModuleURL('core/idp/logout-iframe-post.php', $params);
633  }
634 
635  $lr = self::buildLogoutRequest($idpMetadata, $spMetadata, $association, $relayState);
636  $lr->setDestination($dst['Location']);
637 
638  $binding = new \SAML2\HTTPRedirect();
639  return $binding->getRedirectURL($lr);
640  }
$params
Definition: disable.php:11
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
$dst
$spMetadata
$metadata['__DYNAMIC:1__']
$bindings
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
static info($string)
Definition: Logger.php:201
$relayState
getConfig()
Retrieve the configuration for this IdP.
Definition: IdP.php:165
Create styles array
The data for the language used.
getId()
Retrieve the ID of this IdP.
Definition: IdP.php:118
if(!isset($associations[$assocId])) $association
$lr
$idpMetadata
$binding
+ Here is the call graph for this function:

◆ handleAuthError()

static sspmod_saml_IdP_SAML2::handleAuthError ( SimpleSAML_Error_Exception  $exception,
array  $state 
)
static

Handle authentication error.

SimpleSAML_Error_Exception $exception The exception.

Parameters
array$stateThe error state.

Definition at line 96 of file SAML2.php.

References $binding, $error, $idp, $idpMetadata, $relayState, $spEntityId, $spMetadata, array, sspmod_saml_Error\fromException(), SAML2\Binding\getBinding(), SimpleSAML_IdP\getByState(), SimpleSAML_Configuration\loadFromArray(), SimpleSAML_Stats\log(), SimpleSAML_Error_Exception\log(), and SimpleSAML\Logger\warning().

97  {
98  assert('isset($state["SPMetadata"])');
99  assert('isset($state["saml:ConsumerURL"])');
100  assert('array_key_exists("saml:RequestId", $state)'); // Can be NULL.
101  assert('array_key_exists("saml:RelayState", $state)'); // Can be NULL.
102 
103  $spMetadata = $state["SPMetadata"];
104  $spEntityId = $spMetadata['entityid'];
106  $spMetadata,
107  '$metadata['.var_export($spEntityId, true).']'
108  );
109 
110  $requestId = $state['saml:RequestId'];
111  $relayState = $state['saml:RelayState'];
112  $consumerURL = $state['saml:ConsumerURL'];
113  $protocolBinding = $state['saml:Binding'];
114 
116 
117  $idpMetadata = $idp->getConfig();
118 
120 
121  SimpleSAML\Logger::warning("Returning error to SP with entity ID '".var_export($spEntityId, true)."'.");
122  $exception->log(SimpleSAML\Logger::WARNING);
123 
124  $ar = self::buildResponse($idpMetadata, $spMetadata, $consumerURL);
125  $ar->setInResponseTo($requestId);
126  $ar->setRelayState($relayState);
127 
128  $status = array(
129  'Code' => $error->getStatus(),
130  'SubCode' => $error->getSubStatus(),
131  'Message' => $error->getStatusMessage(),
132  );
133  $ar->setStatus($status);
134 
135  $statsData = array(
136  'spEntityID' => $spEntityId,
137  'idpEntityID' => $idpMetadata->getString('entityid'),
138  'protocol' => 'saml2',
139  'error' => $status,
140  );
141  if (isset($state['saml:AuthnRequestReceivedAt'])) {
142  $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt'];
143  }
144  SimpleSAML_Stats::log('saml:idp:Response:error', $statsData);
145 
146  $binding = \SAML2\Binding::getBinding($protocolBinding);
147  $binding->send($ar);
148  }
static getByState(array &$state)
Retrieve the IdP "owning" the state.
Definition: IdP.php:152
log($default_level)
Print the exception to the log, by default with log level error.
Definition: Exception.php:236
static getBinding($urn)
Retrieve a binding with the given URN.
Definition: Binding.php:28
$spEntityId
$spMetadata
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$error
Definition: Error.php:17
Attribute-related utility methods.
$relayState
static warning($string)
Definition: Logger.php:179
Create styles array
The data for the language used.
static fromException(Exception $exception)
Create a SAML2 error from an exception.
Definition: Error.php:101
$idp
Definition: prp.php:13
$idpMetadata
$binding
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

◆ receiveAuthnRequest()

static sspmod_saml_IdP_SAML2::receiveAuthnRequest ( SimpleSAML_IdP  $idp)
static

Receive an authentication request.

Parameters
SimpleSAML_IdP$idpThe IdP we are receiving it for.
Exceptions
SimpleSAML_Error_BadRequestIn case an error occurs when trying to receive the request.

Definition at line 248 of file SAML2.php.

References $binding, $forceAuthn, $idpMetadata, $isPassive, $metadata, $relayState, $spEntityId, $spMetadata, $state, array, SAML2\Constants\BINDING_HOK_SSO, SAML2\Constants\BINDING_HTTP_ARTIFACT, SimpleSAML\Utils\HTTP\checkSessionCookie(), SimpleSAML_Auth_State\EXCEPTION_HANDLER_FUNC, SimpleSAML_IdP\getConfig(), SAML2\Binding\getCurrentBinding(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), SimpleSAML_IdP\handleAuthenticationRequest(), SimpleSAML\Logger\info(), SimpleSAML_Stats\log(), SimpleSAML_Auth_State\RESTART, string, time, and sspmod_saml_Message\validateMessage().

249  {
250 
252  $idpMetadata = $idp->getConfig();
253 
254  $supportedBindings = array(\SAML2\Constants::BINDING_HTTP_POST);
255  if ($idpMetadata->getBoolean('saml20.sendartifact', false)) {
256  $supportedBindings[] = \SAML2\Constants::BINDING_HTTP_ARTIFACT;
257  }
258  if ($idpMetadata->getBoolean('saml20.hok.assertion', false)) {
259  $supportedBindings[] = \SAML2\Constants::BINDING_HOK_SSO;
260  }
261 
262  if (isset($_REQUEST['spentityid'])) {
263  /* IdP initiated authentication. */
264 
265  if (isset($_REQUEST['cookieTime'])) {
266  $cookieTime = (int) $_REQUEST['cookieTime'];
267  if ($cookieTime + 5 > time()) {
268  /*
269  * Less than five seconds has passed since we were
270  * here the last time. Cookies are probably disabled.
271  */
272  \SimpleSAML\Utils\HTTP::checkSessionCookie(\SimpleSAML\Utils\HTTP::getSelfURL());
273  }
274  }
275 
276  $spEntityId = (string) $_REQUEST['spentityid'];
277  $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
278 
279  if (isset($_REQUEST['RelayState'])) {
280  $relayState = (string) $_REQUEST['RelayState'];
281  } else {
282  $relayState = null;
283  }
284 
285  if (isset($_REQUEST['binding'])) {
286  $protocolBinding = (string) $_REQUEST['binding'];
287  } else {
288  $protocolBinding = null;
289  }
290 
291  if (isset($_REQUEST['NameIDFormat'])) {
292  $nameIDFormat = (string) $_REQUEST['NameIDFormat'];
293  } else {
294  $nameIDFormat = null;
295  }
296 
297  $requestId = null;
298  $IDPList = array();
299  $ProxyCount = null;
300  $RequesterID = null;
301  $forceAuthn = false;
302  $isPassive = false;
303  $consumerURL = null;
304  $consumerIndex = null;
305  $extensions = null;
306  $allowCreate = true;
307  $authnContext = null;
308 
309  $idpInit = true;
310 
312  'SAML2.0 - IdP.SSOService: IdP initiated authentication: '.var_export($spEntityId, true)
313  );
314  } else {
316  $request = $binding->receive();
317 
318  if (!($request instanceof \SAML2\AuthnRequest)) {
319  throw new SimpleSAML_Error_BadRequest(
320  'Message received on authentication request endpoint wasn\'t an authentication request.'
321  );
322  }
323 
324  $spEntityId = $request->getIssuer();
325  if ($spEntityId === null) {
326  throw new SimpleSAML_Error_BadRequest(
327  'Received message on authentication request endpoint without issuer.'
328  );
329  }
330  $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
331 
333 
334  $relayState = $request->getRelayState();
335 
336  $requestId = $request->getId();
337  $IDPList = $request->getIDPList();
338  $ProxyCount = $request->getProxyCount();
339  if ($ProxyCount !== null) {
340  $ProxyCount--;
341  }
342  $RequesterID = $request->getRequesterID();
343  $forceAuthn = $request->getForceAuthn();
344  $isPassive = $request->getIsPassive();
345  $consumerURL = $request->getAssertionConsumerServiceURL();
346  $protocolBinding = $request->getProtocolBinding();
347  $consumerIndex = $request->getAssertionConsumerServiceIndex();
348  $extensions = $request->getExtensions();
349  $authnContext = $request->getRequestedAuthnContext();
350 
351  $nameIdPolicy = $request->getNameIdPolicy();
352  if (isset($nameIdPolicy['Format'])) {
353  $nameIDFormat = $nameIdPolicy['Format'];
354  } else {
355  $nameIDFormat = null;
356  }
357  if (isset($nameIdPolicy['AllowCreate'])) {
358  $allowCreate = $nameIdPolicy['AllowCreate'];
359  } else {
360  $allowCreate = false;
361  }
362 
363  $idpInit = false;
364 
366  'SAML2.0 - IdP.SSOService: incoming authentication request: '.var_export($spEntityId, true)
367  );
368  }
369 
370  SimpleSAML_Stats::log('saml:idp:AuthnRequest', array(
371  'spEntityID' => $spEntityId,
372  'idpEntityID' => $idpMetadata->getString('entityid'),
373  'forceAuthn' => $forceAuthn,
374  'isPassive' => $isPassive,
375  'protocol' => 'saml2',
376  'idpInit' => $idpInit,
377  ));
378 
379  $acsEndpoint = self::getAssertionConsumerService(
380  $supportedBindings,
381  $spMetadata,
382  $consumerURL,
383  $protocolBinding,
384  $consumerIndex
385  );
386 
387  $IDPList = array_unique(array_merge($IDPList, $spMetadata->getArrayizeString('IDPList', array())));
388  if ($ProxyCount === null) {
389  $ProxyCount = $spMetadata->getInteger('ProxyCount', null);
390  }
391 
392  if (!$forceAuthn) {
393  $forceAuthn = $spMetadata->getBoolean('ForceAuthn', false);
394  }
395 
396  $sessionLostParams = array(
397  'spentityid' => $spEntityId,
398  'cookieTime' => time(),
399  );
400  if ($relayState !== null) {
401  $sessionLostParams['RelayState'] = $relayState;
402  }
403 
404  $sessionLostURL = \SimpleSAML\Utils\HTTP::addURLParameters(
405  \SimpleSAML\Utils\HTTP::getSelfURLNoQuery(),
406  $sessionLostParams
407  );
408 
409  $state = array(
410  'Responder' => array('sspmod_saml_IdP_SAML2', 'sendResponse'),
411  SimpleSAML_Auth_State::EXCEPTION_HANDLER_FUNC => array('sspmod_saml_IdP_SAML2', 'handleAuthError'),
412  SimpleSAML_Auth_State::RESTART => $sessionLostURL,
413 
414  'SPMetadata' => $spMetadata->toArray(),
415  'saml:RelayState' => $relayState,
416  'saml:RequestId' => $requestId,
417  'saml:IDPList' => $IDPList,
418  'saml:ProxyCount' => $ProxyCount,
419  'saml:RequesterID' => $RequesterID,
420  'ForceAuthn' => $forceAuthn,
421  'isPassive' => $isPassive,
422  'saml:ConsumerURL' => $acsEndpoint['Location'],
423  'saml:Binding' => $acsEndpoint['Binding'],
424  'saml:NameIDFormat' => $nameIDFormat,
425  'saml:AllowCreate' => $allowCreate,
426  'saml:Extensions' => $extensions,
427  'saml:AuthnRequestReceivedAt' => microtime(true),
428  'saml:RequestedAuthnContext' => $authnContext,
429  );
430 
432  }
const BINDING_HOK_SSO
The URN for the Holder-of-Key Web Browser SSO Profile binding.
Definition: Constants.php:50
handleAuthenticationRequest(array &$state)
Process authentication requests.
Definition: IdP.php:384
Add rich text string
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
static validateMessage(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata, \SAML2\Message $message)
Check signature on a SAML2 message if enabled.
Definition: Message.php:246
const RESTART
The index in the state array which contains the restart URL.
Definition: State.php:57
$forceAuthn
Definition: login.php:17
$spEntityId
static getCurrentBinding()
Guess the current binding.
Definition: Binding.php:62
$spMetadata
$isPassive
Definition: login.php:18
$metadata['__DYNAMIC:1__']
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Attribute-related utility methods.
static info($string)
Definition: Logger.php:201
$relayState
const EXCEPTION_HANDLER_FUNC
The index in the state array which contains the exception handler function.
Definition: State.php:69
getConfig()
Retrieve the configuration for this IdP.
Definition: IdP.php:165
const BINDING_HTTP_ARTIFACT
The URN for the HTTP-ARTIFACT binding.
Definition: Constants.php:35
Create styles array
The data for the language used.
$idpMetadata
static checkSessionCookie($retryURL=null)
Check for session cookie, and show missing-cookie page if it is missing.
Definition: HTTP.php:287
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$binding
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

◆ receiveLogoutMessage()

static sspmod_saml_IdP_SAML2::receiveLogoutMessage ( SimpleSAML_IdP  $idp)
static

Receive a logout message.

Parameters
SimpleSAML_IdP$idpThe IdP we are receiving it for.
Exceptions
SimpleSAML_Error_BadRequestIn case an error occurs while trying to receive the logout message.

Definition at line 536 of file SAML2.php.

References $assocId, $binding, $idpMetadata, $message, $metadata, $relayState, $spEntityId, $spMetadata, $state, array, SimpleSAML_IdP\getConfig(), SAML2\Binding\getCurrentBinding(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), sspmod_saml_Message\getResponseError(), SimpleSAML_IdP\handleLogoutRequest(), SimpleSAML_IdP\handleLogoutResponse(), SimpleSAML\Logger\info(), SimpleSAML_Stats\log(), SimpleSAML\Logger\stats(), sspmod_saml_Message\validateMessage(), and SimpleSAML\Logger\warning().

537  {
538 
540  $message = $binding->receive();
541 
542  $spEntityId = $message->getIssuer();
543  if ($spEntityId === null) {
544  /* Without an issuer we have no way to respond to the message. */
545  throw new SimpleSAML_Error_BadRequest('Received message on logout endpoint without issuer.');
546  }
547 
549  $idpMetadata = $idp->getConfig();
550  $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
551 
553 
554  if ($message instanceof \SAML2\LogoutResponse) {
555  SimpleSAML\Logger::info('Received SAML 2.0 LogoutResponse from: '.var_export($spEntityId, true));
556  $statsData = array(
557  'spEntityID' => $spEntityId,
558  'idpEntityID' => $idpMetadata->getString('entityid'),
559  );
560  if (!$message->isSuccess()) {
561  $statsData['error'] = $message->getStatus();
562  }
563  SimpleSAML_Stats::log('saml:idp:LogoutResponse:recv', $statsData);
564 
565  $relayState = $message->getRelayState();
566 
567  if (!$message->isSuccess()) {
569  SimpleSAML\Logger::warning('Unsuccessful logout. Status was: '.$logoutError);
570  } else {
571  $logoutError = null;
572  }
573 
574  $assocId = 'saml:'.$spEntityId;
575 
576  $idp->handleLogoutResponse($assocId, $relayState, $logoutError);
577  } elseif ($message instanceof \SAML2\LogoutRequest) {
578  SimpleSAML\Logger::info('Received SAML 2.0 LogoutRequest from: '.var_export($spEntityId, true));
579  SimpleSAML_Stats::log('saml:idp:LogoutRequest:recv', array(
580  'spEntityID' => $spEntityId,
581  'idpEntityID' => $idpMetadata->getString('entityid'),
582  ));
583 
584  $spStatsId = $spMetadata->getString('core:statistics-id', $spEntityId);
585  SimpleSAML\Logger::stats('saml20-idp-SLO spinit '.$spStatsId.' '.$idpMetadata->getString('entityid'));
586 
587  $state = array(
588  'Responder' => array('sspmod_saml_IdP_SAML2', 'sendLogoutResponse'),
589  'saml:SPEntityId' => $spEntityId,
590  'saml:RelayState' => $message->getRelayState(),
591  'saml:RequestId' => $message->getId(),
592  );
593 
594  $assocId = 'saml:'.$spEntityId;
595  $idp->handleLogoutRequest($state, $assocId);
596  } else {
597  throw new SimpleSAML_Error_BadRequest('Unknown message received on logout endpoint: '.get_class($message));
598  }
599  }
handleLogoutRequest(array &$state, $assocId)
Process a logout request.
Definition: IdP.php:479
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
static validateMessage(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata, \SAML2\Message $message)
Check signature on a SAML2 message if enabled.
Definition: Message.php:246
$spEntityId
static getCurrentBinding()
Guess the current binding.
Definition: Binding.php:62
$spMetadata
$metadata['__DYNAMIC:1__']
handleLogoutResponse($assocId, $relayState, SimpleSAML_Error_Exception $error=null)
Process a logout response.
Definition: IdP.php:514
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static stats($string)
Definition: Logger.php:224
static info($string)
Definition: Logger.php:201
catch(Exception $e) $message
$relayState
static warning($string)
Definition: Logger.php:179
getConfig()
Retrieve the configuration for this IdP.
Definition: IdP.php:165
Create styles array
The data for the language used.
static getResponseError(\SAML2\StatusResponse $response)
Retrieve the status code of a response as a sspmod_saml_Error.
Definition: Message.php:417
$idpMetadata
if(!isset($_REQUEST['association'])) $assocId
$binding
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

◆ sendLogoutRequest()

static sspmod_saml_IdP_SAML2::sendLogoutRequest ( SimpleSAML_IdP  $idp,
array  $association,
  $relayState 
)
static

Send a logout request to a given association.

Parameters
SimpleSAML_IdP$idpThe IdP we are sending a logout request from.
array$associationThe association that should be terminated.
string | NULL$relayStateAn id that should be carried across the logout.

Definition at line 442 of file SAML2.php.

References $binding, $dst, $idpMetadata, $lr, $metadata, $relayState, $spMetadata, array, SAML2\Binding\getBinding(), SimpleSAML_IdP\getConfig(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), SimpleSAML\Logger\info(), and SimpleSAML_Stats\log().

443  {
444  assert('is_string($relayState) || is_null($relayState)');
445 
446  SimpleSAML\Logger::info('Sending SAML 2.0 LogoutRequest to: '.var_export($association['saml:entityID'], true));
447 
449  $idpMetadata = $idp->getConfig();
450  $spMetadata = $metadata->getMetaDataConfig($association['saml:entityID'], 'saml20-sp-remote');
451 
452  SimpleSAML_Stats::log('saml:idp:LogoutRequest:sent', array(
453  'spEntityID' => $association['saml:entityID'],
454  'idpEntityID' => $idpMetadata->getString('entityid'),
455  ));
456 
457  $dst = $spMetadata->getEndpointPrioritizedByBinding(
458  'SingleLogoutService',
459  array(
460  \SAML2\Constants::BINDING_HTTP_REDIRECT,
461  \SAML2\Constants::BINDING_HTTP_POST
462  )
463  );
465  $lr = self::buildLogoutRequest($idpMetadata, $spMetadata, $association, $relayState);
466  $lr->setDestination($dst['Location']);
467 
468  $binding->send($lr);
469  }
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
$dst
static getBinding($urn)
Retrieve a binding with the given URN.
Definition: Binding.php:28
$spMetadata
$metadata['__DYNAMIC:1__']
static info($string)
Definition: Logger.php:201
$relayState
getConfig()
Retrieve the configuration for this IdP.
Definition: IdP.php:165
Create styles array
The data for the language used.
if(!isset($associations[$assocId])) $association
$lr
$idpMetadata
$binding
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

◆ sendLogoutResponse()

static sspmod_saml_IdP_SAML2::sendLogoutResponse ( SimpleSAML_IdP  $idp,
array  $state 
)
static

Send a logout response.

Parameters
SimpleSAML_IdP$idpThe IdP we are sending a logout request from.
array&$stateThe logout state array.

Definition at line 478 of file SAML2.php.

References $binding, $dst, $idpMetadata, $lr, $metadata, $spEntityId, $spMetadata, array, sspmod_saml_Message\buildLogoutResponse(), SimpleSAML\Logger\debug(), SAML2\Binding\getBinding(), SimpleSAML_IdP\getConfig(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), SimpleSAML\Logger\info(), and SimpleSAML_Stats\log().

479  {
480  assert('isset($state["saml:SPEntityId"])');
481  assert('isset($state["saml:RequestId"])');
482  assert('array_key_exists("saml:RelayState", $state)'); // Can be NULL.
483 
484  $spEntityId = $state['saml:SPEntityId'];
485 
487  $idpMetadata = $idp->getConfig();
488  $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
489 
491  $lr->setInResponseTo($state['saml:RequestId']);
492  $lr->setRelayState($state['saml:RelayState']);
493 
494  if (isset($state['core:Failed']) && $state['core:Failed']) {
495  $partial = true;
496  $lr->setStatus(array(
497  'Code' => \SAML2\Constants::STATUS_SUCCESS,
498  'SubCode' => \SAML2\Constants::STATUS_PARTIAL_LOGOUT,
499  ));
500  SimpleSAML\Logger::info('Sending logout response for partial logout to SP '.var_export($spEntityId, true));
501  } else {
502  $partial = false;
503  SimpleSAML\Logger::debug('Sending logout response to SP '.var_export($spEntityId, true));
504  }
505 
506  SimpleSAML_Stats::log('saml:idp:LogoutResponse:sent', array(
507  'spEntityID' => $spEntityId,
508  'idpEntityID' => $idpMetadata->getString('entityid'),
509  'partial' => $partial
510  ));
511  $dst = $spMetadata->getEndpointPrioritizedByBinding(
512  'SingleLogoutService',
513  array(
514  \SAML2\Constants::BINDING_HTTP_REDIRECT,
515  \SAML2\Constants::BINDING_HTTP_POST
516  )
517  );
519  if (isset($dst['ResponseLocation'])) {
520  $dst = $dst['ResponseLocation'];
521  } else {
522  $dst = $dst['Location'];
523  }
524  $lr->setDestination($dst);
525 
526  $binding->send($lr);
527  }
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
$dst
static getBinding($urn)
Retrieve a binding with the given URN.
Definition: Binding.php:28
static debug($string)
Definition: Logger.php:213
$spEntityId
$spMetadata
$metadata['__DYNAMIC:1__']
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static info($string)
Definition: Logger.php:201
getConfig()
Retrieve the configuration for this IdP.
Definition: IdP.php:165
Create styles array
The data for the language used.
$lr
$idpMetadata
$binding
static buildLogoutResponse(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata)
Build a logout response based on information in the metadata.
Definition: Message.php:521
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

◆ sendResponse()

static sspmod_saml_IdP_SAML2::sendResponse ( array  $state)
static

Send a response to the SP.

Parameters
array$stateThe authentication state.

Definition at line 19 of file SAML2.php.

References $association, $binding, $idp, $idpMetadata, $relayState, $spEntityId, $spMetadata, array, SAML2\Binding\getBinding(), SimpleSAML_IdP\getByState(), SimpleSAML\Logger\info(), SimpleSAML_Configuration\loadFromArray(), and SimpleSAML_Stats\log().

20  {
21  assert('isset($state["Attributes"])');
22  assert('isset($state["SPMetadata"])');
23  assert('isset($state["saml:ConsumerURL"])');
24  assert('array_key_exists("saml:RequestId", $state)'); // Can be NULL
25  assert('array_key_exists("saml:RelayState", $state)'); // Can be NULL.
26 
27  $spMetadata = $state["SPMetadata"];
28  $spEntityId = $spMetadata['entityid'];
31  '$metadata['.var_export($spEntityId, true).']'
32  );
33 
34  SimpleSAML\Logger::info('Sending SAML 2.0 Response to '.var_export($spEntityId, true));
35 
36  $requestId = $state['saml:RequestId'];
37  $relayState = $state['saml:RelayState'];
38  $consumerURL = $state['saml:ConsumerURL'];
39  $protocolBinding = $state['saml:Binding'];
40 
42 
43  $idpMetadata = $idp->getConfig();
44 
45  $assertion = self::buildAssertion($idpMetadata, $spMetadata, $state);
46 
47  if (isset($state['saml:AuthenticatingAuthority'])) {
48  $assertion->setAuthenticatingAuthority($state['saml:AuthenticatingAuthority']);
49  }
50 
51  // create the session association (for logout)
53  'id' => 'saml:'.$spEntityId,
54  'Handler' => 'sspmod_saml_IdP_SAML2',
55  'Expires' => $assertion->getSessionNotOnOrAfter(),
56  'saml:entityID' => $spEntityId,
57  'saml:NameID' => $state['saml:idp:NameID'],
58  'saml:SessionIndex' => $assertion->getSessionIndex(),
59  );
60 
61  // maybe encrypt the assertion
62  $assertion = self::encryptAssertion($idpMetadata, $spMetadata, $assertion);
63 
64  // create the response
65  $ar = self::buildResponse($idpMetadata, $spMetadata, $consumerURL);
66  $ar->setInResponseTo($requestId);
67  $ar->setRelayState($relayState);
68  $ar->setAssertions(array($assertion));
69 
70  // register the session association with the IdP
71  $idp->addAssociation($association);
72 
73  $statsData = array(
74  'spEntityID' => $spEntityId,
75  'idpEntityID' => $idpMetadata->getString('entityid'),
76  'protocol' => 'saml2',
77  );
78  if (isset($state['saml:AuthnRequestReceivedAt'])) {
79  $statsData['logintime'] = microtime(true) - $state['saml:AuthnRequestReceivedAt'];
80  }
81  SimpleSAML_Stats::log('saml:idp:Response', $statsData);
82 
83  // send the response
84  $binding = \SAML2\Binding::getBinding($protocolBinding);
85  $binding->send($ar);
86  }
static getByState(array &$state)
Retrieve the IdP "owning" the state.
Definition: IdP.php:152
static getBinding($urn)
Retrieve a binding with the given URN.
Definition: Binding.php:28
$spEntityId
$spMetadata
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static info($string)
Definition: Logger.php:201
$relayState
Create styles array
The data for the language used.
if(!isset($associations[$assocId])) $association
$idp
Definition: prp.php:13
$idpMetadata
$binding
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: