-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginShibboleth.php
executable file
·98 lines (87 loc) · 2.54 KB
/
LoginShibboleth.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Piwik - Open source web analytics.
*
* @link http://piwik.org
*
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
*
* @package LoginShibboleth
**/
namespace Piwik\Plugins\LoginShibboleth;
use Exception;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
use Piwik\Plugins\Login\Login;
/**
*
*/
class LoginShibboleth extends \Piwik\Plugin
{
/**
* @see Piwik_Plugin::getListHooksRegistered
*/
public function getListHooksRegistered()
{
$hooks = array(
'Request.initAuthenticationObject' => 'initAuthenticationObject',
'User.isNotAuthorized' => 'noAccess',
'API.Request.authenticate' => 'ApiRequestAuthenticate',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
);
return $hooks;
}
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = 'plugins/Login/javascripts/login.js';
}
/**
* Deactivate default Login module, as both cannot be activated together.
*/
public function activate()
{
if (Manager::getInstance()->isPluginActivated('Login') == true) {
Manager::getInstance()->deactivatePlugin('Login');
}
}
/**
* Activate default Login module, as one of them is needed to access Piwik.
*/
public function deactivate()
{
if (Manager::getInstance()->isPluginActivated('Login') == false) {
Manager::getInstance()->activatePlugin('Login');
}
}
/**
* Redirects to Login form with error message.
* Listens to User.isNotAuthorized hook.
*/
public function noAccess(Exception $exception)
{
$exceptionMessage = $exception->getMessage();
echo FrontController::getInstance()->dispatch('LoginShibboleth', 'login', array($exceptionMessage));
}
/**
* Set login name and autehntication token for authentication request.
* Listens to API.Request.authenticate hook.
*/
public function ApiRequestAuthenticate($tokenAuth)
{
\Piwik\Registry::get('auth')->setLogin($login = null);
\Piwik\Registry::get('auth')->setTokenAuth($tokenAuth);
}
/**
* Initializes the authentication object.
* Listens to Request.initAuthenticationObject hook.
*/
public function initAuthenticationObject($activateCookieAuth = false)
{
$auth = new LoginShibbolethAuth();
\Piwik\Registry::set('auth', $auth);
Login::initAuthenticationFromCookie($auth, $activateCookieAuth);
}
}