You are here

function saml_sp__get_metadata in SAML Service Provider 7.3

Same name and namespace in other branches
  1. 8.3 saml_sp.module \saml_sp__get_metadata()
  2. 8.2 saml_sp.module \saml_sp__get_metadata()
  3. 7.8 saml_sp.module \saml_sp__get_metadata()
  4. 7.2 saml_sp.module \saml_sp__get_metadata()
  5. 4.x saml_sp.module \saml_sp__get_metadata()
  6. 3.x saml_sp.module \saml_sp__get_metadata()

load the settings and get the metadata

1 call to saml_sp__get_metadata()
saml_sp__admin_config in ./saml_sp.admin.inc
configure this SAML Service Provider
1 string reference to 'saml_sp__get_metadata'
saml_sp_menu in ./saml_sp.module
Implements hook_menu().

File

./saml_sp.module, line 590
SAML Service Provider

Code

function saml_sp__get_metadata($idp, $output_page = FALSE) {
  if (empty($idp)) {

    // no $idp was given, we will try to see if there is a default one set
    if (module_exists('saml_sp_drupal_login')) {
      $idp_selection = variable_get('saml_sp_drupal_login__idp', '');
    }
    else {
      $idp_selection = variable_get('saml_sp__idp_selection', '');
    }
    $idp = saml_sp_idp_load($idp_selection);
    if (empty($idp)) {

      // there is also no default $idp set
      if ($output_page) {

        // so return a page not found
        drupal_not_found();
        return;
      }
      else {
        throw new Exception('No Default IdP defined.');

        // return FALSE
        return FALSE;
      }
    }
  }
  $settings = saml_sp__get_settings($idp);
  if (empty($settings)) {
    return array(
      t('Settings could not be loaded and metadata couldn\'t be generated.'),
    );
  }
  $auth = new saml_sp_Auth($settings);
  $settings = $auth
    ->getSettings();
  $metadata = $settings
    ->getSPMetadata();
  $errors = $settings
    ->validateMetadata($metadata);
  if (empty($errors)) {
    if ($output_page) {
      drupal_add_http_header('Content-Type', 'text/xml');
      print $metadata;
    }
    else {
      return $metadata;
    }
  }
  else {
    return array(
      $metadata,
      $errors,
    );
  }
}