8805a8c41a1b7f4a6887e58bd9162e988b5c7da2
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Storage / SessionStorage.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Storage;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Dmitry Dulepov <dmitry@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This class contains a session-based storage for private keys. This storage
28 * is not secure enough because its implementation stores keys completely in the
29 * PHP sessions. PHP sessions usually store data in the file system and it is
30 * easy to extract. This storage is useful only as an example. It is better to
31 * use "split" storage for keys.
32 *
33 * @author Dmitry Dulepov <dmitry@typo3.org>
34 */
35 class SessionStorage extends \TYPO3\CMS\Rsaauth\Storage\AbstractStorage {
36
37 /**
38 * Creates an instance of this class. It checks and initializes PHP
39 * sessions if necessary.
40 *
41 * @return void
42 */
43 public function __construct() {
44 if (!isset($_SESSION) || !is_array($_SESSION)) {
45 session_start();
46 }
47 }
48
49 /**
50 * Obtains key from the session
51 *
52 * @return string The key or NULL
53 * @see \TYPO3\CMS\Rsaauth\Storage\AbstractStorage::get()
54 */
55 public function get() {
56 return isset($_SESSION['tx_rsaauth_key']) ? $_SESSION['tx_rsaauth_key'] : NULL;
57 }
58
59 /**
60 * Puts key to the session
61 *
62 * @param string $key The key
63 * @see \TYPO3\CMS\Rsaauth\Storage\AbstractStorage::put()
64 */
65 public function put($key) {
66 $_SESSION['tx_rsaauth_key'] = $key;
67 }
68
69 }