SimpleSAML_Configuration::getEndpoints PHP Method

getEndpoints() public method

Helper function for dealing with metadata endpoints.
public getEndpoints ( string $endpointType ) : array
$endpointType string The endpoint type.
return array Array of endpoints of the given type.
    public function getEndpoints($endpointType)
    {
        assert('is_string($endpointType)');
        $loc = $this->location . '[' . var_export($endpointType, true) . ']:';
        if (!array_key_exists($endpointType, $this->configuration)) {
            // no endpoints of the given type
            return array();
        }
        $eps = $this->configuration[$endpointType];
        if (is_string($eps)) {
            // for backwards-compatibility
            $eps = array($eps);
        } elseif (!is_array($eps)) {
            throw new Exception($loc . ': Expected array or string.');
        }
        foreach ($eps as $i => &$ep) {
            $iloc = $loc . '[' . var_export($i, true) . ']';
            if (is_string($ep)) {
                // for backwards-compatibility
                $ep = array('Location' => $ep, 'Binding' => $this->getDefaultBinding($endpointType));
                $responseLocation = $this->getString($endpointType . 'Response', null);
                if ($responseLocation !== null) {
                    $ep['ResponseLocation'] = $responseLocation;
                }
            } elseif (!is_array($ep)) {
                throw new Exception($iloc . ': Expected a string or an array.');
            }
            if (!array_key_exists('Location', $ep)) {
                throw new Exception($iloc . ': Missing Location.');
            }
            if (!is_string($ep['Location'])) {
                throw new Exception($iloc . ': Location must be a string.');
            }
            if (!array_key_exists('Binding', $ep)) {
                throw new Exception($iloc . ': Missing Binding.');
            }
            if (!is_string($ep['Binding'])) {
                throw new Exception($iloc . ': Binding must be a string.');
            }
            if (array_key_exists('ResponseLocation', $ep)) {
                if (!is_string($ep['ResponseLocation'])) {
                    throw new Exception($iloc . ': ResponseLocation must be a string.');
                }
            }
            if (array_key_exists('index', $ep)) {
                if (!is_int($ep['index'])) {
                    throw new Exception($iloc . ': index must be an integer.');
                }
            }
        }
        return $eps;
    }

Usage Example

コード例 #1
0
ファイル: SAML2.php プロジェクト: rediris-es/simplesamlphp
 /**
  * Find SP AssertionConsumerService based on parameter in AuthnRequest.
  *
  * @param array $supportedBindings  The bindings we allow for the response.
  * @param SimpleSAML_Configuration $spMetadata  The metadata for the SP.
  * @param string|NULL $AssertionConsumerServiceURL  AssertionConsumerServiceURL from request.
  * @param string|NULL $ProtocolBinding  ProtocolBinding from request.
  * @param int|NULL $AssertionConsumerServiceIndex  AssertionConsumerServiceIndex from request.
  * @return array  Array with the Location and Binding we should use for the response.
  */
 public static function getAssertionConsumerService(array $supportedBindings, SimpleSAML_Configuration $spMetadata, $AssertionConsumerServiceURL, $ProtocolBinding, $AssertionConsumerServiceIndex)
 {
     assert('is_string($AssertionConsumerServiceURL) || is_null($AssertionConsumerServiceURL)');
     assert('is_string($ProtocolBinding) || is_null($ProtocolBinding)');
     assert('is_int($AssertionConsumerServiceIndex) || is_null($AssertionConsumerServiceIndex)');
     /* We want to pick the best matching endpoint in the case where for example
      * only the ProtocolBinding is given. We therefore pick endpoints with the
      * following priority:
      *  1. isDefault="true"
      *  2. isDefault unset
      *  3. isDefault="false"
      */
     $firstNotFalse = NULL;
     $firstFalse = NULL;
     foreach ($spMetadata->getEndpoints('AssertionConsumerService') as $ep) {
         if ($AssertionConsumerServiceURL !== NULL && $ep['Location'] !== $AssertionConsumerServiceURL) {
             continue;
         }
         if ($ProtocolBinding !== NULL && $ep['Binding'] !== $ProtocolBinding) {
             continue;
         }
         if ($AssertionConsumerServiceIndex !== NULL && $ep['index'] !== $AssertionConsumerServiceIndex) {
             continue;
         }
         if (!in_array($ep['Binding'], $supportedBindings, TRUE)) {
             /* The endpoint has an unsupported binding. */
             continue;
         }
         /* We have an endpoint that matches all our requirements. Check if it is the best one. */
         if (array_key_exists('isDefault', $ep)) {
             if ($ep['isDefault'] === TRUE) {
                 /* This is the first matching endpoint with isDefault set to TRUE. */
                 return $ep;
             }
             /* isDefault is set to FALSE, but the endpoint is still useable. */
             if ($firstFalse === NULL) {
                 /* This is the first endpoint that we can use. */
                 $firstFalse = $ep;
             }
         } else {
             if ($firstNotFalse === NULL) {
                 /* This is the first endpoint without isDefault set. */
                 $firstNotFalse = $ep;
             }
         }
     }
     if ($firstNotFalse !== NULL) {
         return $firstNotFalse;
     } elseif ($firstFalse !== NULL) {
         return $firstFalse;
     }
     SimpleSAML_Logger::warning('Authentication request specifies invalid AssertionConsumerService:');
     if ($AssertionConsumerServiceURL !== NULL) {
         SimpleSAML_Logger::warning('AssertionConsumerServiceURL: ' . var_export($AssertionConsumerServiceURL, TRUE));
     }
     if ($ProtocolBinding !== NULL) {
         SimpleSAML_Logger::warning('ProtocolBinding: ' . var_export($ProtocolBinding, TRUE));
     }
     if ($AssertionConsumerServiceIndex !== NULL) {
         SimpleSAML_Logger::warning('AssertionConsumerServiceIndex: ' . var_export($AssertionConsumerServiceIndex, TRUE));
     }
     /* We have no good endpoints. Our last resort is to just use the default endpoint. */
     return $spMetadata->getDefaultEndpoint('AssertionConsumerService', $supportedBindings);
 }