|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony framework. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* This source file is subject to the MIT license that is bundled |
|
|
9 |
* with this source code in the file LICENSE. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Security\Http\Session; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
|
15 |
use Symfony\Component\HttpFoundation\Request; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* The default session strategy implementation. |
|
|
19 |
* |
|
|
20 |
* Supports the following strategies: |
|
|
21 |
* NONE: the session is not changed |
|
|
22 |
* MIGRATE: the session id is updated, attributes are kept |
|
|
23 |
* INVALIDATE: the session id is updated, attributes are lost |
|
|
24 |
* |
|
|
25 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
26 |
*/ |
|
|
27 |
class SessionAuthenticationStrategy implements SessionAuthenticationStrategyInterface |
|
|
28 |
{ |
|
|
29 |
const NONE = 'none'; |
|
|
30 |
const MIGRATE = 'migrate'; |
|
|
31 |
const INVALIDATE = 'invalidate'; |
|
|
32 |
|
|
|
33 |
private $strategy; |
|
|
34 |
|
|
|
35 |
public function __construct($strategy) |
|
|
36 |
{ |
|
|
37 |
$this->strategy = $strategy; |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
/** |
|
|
41 |
* {@inheritDoc} |
|
|
42 |
*/ |
|
|
43 |
public function onAuthentication(Request $request, TokenInterface $token) |
|
|
44 |
{ |
|
|
45 |
switch ($this->strategy) { |
|
|
46 |
case self::NONE: |
|
|
47 |
return; |
|
|
48 |
|
|
|
49 |
case self::MIGRATE: |
|
|
50 |
$request->getSession()->migrate(); |
|
|
51 |
|
|
|
52 |
return; |
|
|
53 |
|
|
|
54 |
case self::INVALIDATE: |
|
|
55 |
$request->getSession()->invalidate(); |
|
|
56 |
|
|
|
57 |
return; |
|
|
58 |
|
|
|
59 |
default: |
|
|
60 |
throw new \RuntimeException(sprintf('Invalid session authentication strategy "%s"', $this->strategy)); |
|
|
61 |
} |
|
|
62 |
} |
|
|
63 |
} |