1<?php 2/** 3 * ADFS SAML authentication plugin 4 * 5 * @author Andreas Gohr <gohr@cosmocode.de> 6 */ 7class action_plugin_adfs extends DokuWiki_Action_Plugin 8{ 9 10 /** @inheritdoc */ 11 public function register(Doku_Event_Handler $controller) 12 { 13 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_request'); 14 $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_loginform'); 15 } 16 17 /** 18 * Send the Federation Metadata about this Service Provider 19 * 20 * @param Doku_Event $event 21 * @param mixed $param 22 */ 23 public function handle_request(Doku_Event $event, $param) 24 { 25 $act = act_clean($event->data); 26 if ($act != 'adfs') return; 27 $event->preventDefault(); 28 $event->stopPropagation(); 29 30 /** @var helper_plugin_adfs $hlp */ 31 $hlp = plugin_load('helper', 'adfs'); 32 $saml = $hlp->getSamlLib(); 33 34 try { 35 header('Content-Type: application/samlmetadata+xml'); 36 header('Content-Disposition: attachment; filename="saml-metadata.xml"'); 37 $xml = $saml->getSettings()->getSPMetadata(); 38 echo $xml; 39 exit(); 40 } catch (Exception $e) { 41 die(hsc($e->getMessage())); 42 } 43 } 44 45 /** 46 * Disable the login forma and instead use a link to trigger login 47 * 48 * @param Doku_Event $event 49 * @param $param 50 */ 51 public function handle_loginform(Doku_Event $event, $param) 52 { 53 global $ID; 54 global $conf; 55 if ($conf['authtype'] != 'adfs') return; 56 57 $event->data = new Doku_Form(array()); 58 $event->data->addElement('<a href="' . wl($ID, array('do' => 'login')) . '">Login here</a>'); 59 } 60 61} 62