metadata.php 834 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once '../../main/inc/global.inc.php';
  4. $pluginKeycloak = api_get_plugin_setting('keycloak', 'tool_enable') === 'true';
  5. if (!$pluginKeycloak) {
  6. api_not_allowed(true);
  7. }
  8. /**
  9. * SAML Metadata view.
  10. */
  11. require_once 'settings.php';
  12. try {
  13. // Now we only validate SP settings
  14. $settings = new \OneLogin\Saml2\Settings($settingsInfo, true);
  15. $metadata = $settings->getSPMetadata();
  16. $errors = $settings->validateMetadata($metadata);
  17. if (empty($errors)) {
  18. header('Content-Type: text/xml');
  19. echo $metadata;
  20. } else {
  21. throw new OneLogin\Saml2\Error(
  22. 'Invalid SP metadata: '.implode(', ', $errors),
  23. OneLogin\Saml2\Error::METADATA_SP_INVALID
  24. );
  25. }
  26. } catch (Exception $e) {
  27. echo $e->getMessage();
  28. }