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