PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Session / SessionInitializer.php
matomo / app / core / Session Last commit date
SaveHandler 1 month ago SessionAuth.php 4 months ago SessionFingerprint.php 2 weeks ago SessionInitializer.php 1 year ago SessionNamespace.php 1 year ago
SessionInitializer.php
89 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Session;
10
11 use Exception;
12 use Piwik\Access;
13 use Piwik\Auth as AuthInterface;
14 use Piwik\AuthResult;
15 use Piwik\Piwik;
16 use Piwik\Session;
17 /**
18 * Initializes authenticated sessions using an Auth implementation.
19 */
20 class SessionInitializer
21 {
22 /**
23 * Authenticates the user and, if successful, initializes an authenticated session.
24 *
25 * @param \Piwik\Auth $auth The Auth implementation to use.
26 * @throws Exception If authentication fails or the user is not allowed to login for some reason.
27 */
28 public function initSession(AuthInterface $auth)
29 {
30 $this->regenerateSessionId();
31 $authResult = $this->doAuthenticateSession($auth);
32 if (!$authResult->wasAuthenticationSuccessful()) {
33 Piwik::postEvent('Login.authenticate.failed', array($auth->getLogin()));
34 $this->processFailedSession();
35 } else {
36 Piwik::postEvent('Login.authenticate.successful', array($auth->getLogin()));
37 $this->processSuccessfulSession($authResult);
38 }
39 }
40 /**
41 * Authenticates the user.
42 *
43 * Derived classes can override this method to customize authentication logic or impose
44 * extra requirements on the user trying to login.
45 *
46 * @param AuthInterface $auth The Auth implementation to use when authenticating.
47 * @return AuthResult
48 */
49 protected function doAuthenticateSession(AuthInterface $auth)
50 {
51 Piwik::postEvent('Login.authenticate', array($auth->getLogin()));
52 return $auth->authenticate();
53 }
54 /**
55 * Executed when the session could not authenticate.
56 *
57 * @throws Exception always.
58 */
59 protected function processFailedSession()
60 {
61 throw new Exception(Piwik::translate('Login_LoginPasswordNotCorrect'));
62 }
63 /**
64 * Executed when the session was successfully authenticated.
65 *
66 * @param AuthResult $authResult The successful authentication result.
67 */
68 protected function processSuccessfulSession(AuthResult $authResult)
69 {
70 $sessionIdentifier = new \Piwik\Session\SessionFingerprint();
71 $sessionIdentifier->initialize($authResult->getIdentity(), $authResult->getTokenAuth(), $this->isRemembered());
72 // reload access
73 Access::getInstance()->reloadAccess();
74 /**
75 * @ignore
76 */
77 Piwik::postEvent('Login.authenticate.processSuccessfulSession.end', array($authResult->getIdentity()));
78 }
79 protected function regenerateSessionId()
80 {
81 Session::regenerateId();
82 }
83 private function isRemembered()
84 {
85 $cookieParams = session_get_cookie_params();
86 return $cookieParams['lifetime'] > 0;
87 }
88 }
89