You are here

public static function Utilities::upload_metadata in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

2 calls to Utilities::upload_metadata()
miniorange_saml_fetch_metadata in ./miniorange_saml_idp_setup.inc
miniorange_saml_upload_file in ./miniorange_saml_idp_setup.inc

File

includes/Utilities.php, line 572

Class

Utilities
This file is part of miniOrange SAML plugin.

Code

public static function upload_metadata($file) {
  $b_url = Utilities::miniorange_get_baseURL();
  require_once drupal_get_path('module', 'miniorange_saml') . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'MetadataReader.php';
  $document = new DOMDocument();
  if (empty($file)) {
    drupal_set_message(t('Please provide a valid metadata url.'), 'error');
    return;
  }
  else {
    if ($file[0] != '<') {
      drupal_set_message(t('Please provide a valid metadata file.'), 'error');
      return;
    }
  }
  $document
    ->loadXML($file);
  restore_error_handler();
  $first_child = $document->firstChild;
  if (!empty($first_child)) {

    /**
     * Check if IDP name is stored or not.
     */
    if (empty(variable_get('miniorange_saml_idp_name'))) {
      variable_set('miniorange_saml_idp_name', 'Identity Provider');
    }
    $metadata = new IDPMetadataReader($document);
    $identity_providers = $metadata
      ->getIdentityProviders();
    if (empty($identity_providers)) {
      drupal_set_message(t('Please provide a valid metadata file.'), 'error');
      return;
    }
    foreach ($identity_providers as $key => $idp) {
      $saml_login_url = $idp
        ->getLoginURL('HTTP-Redirect');
      if (empty($saml_login_url)) {
        $saml_login_url = $idp
          ->getLoginURL('HTTP-POST');
      }
      $saml_issuer = $idp
        ->getEntityID();
      $saml_x509_certificate = $idp
        ->getSigningCertificate();
      $sp_issuer = $b_url;
      variable_set('miniorange_saml_sp_issuer', $sp_issuer);
      variable_set('miniorange_saml_idp_issuer', $saml_issuer);
      variable_set('miniorange_saml_idp_login_url', $saml_login_url);
      variable_set('miniorange_saml_idp_x509_certificate', $saml_x509_certificate[0]);
    }
    drupal_set_message(t('Identity Provider Configuration successfully saved.'));
    return;
  }
  else {
    drupal_set_message(t('Please provide a valid metadata file.'), 'error');
    return;
  }
}