[BUGFIX] rsaauth BackendFactory does not unset backend
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Classes / Backend / BackendFactory.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Backend;
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 factory for the RSA backends.
28 *
29 * @author Dmitry Dulepov <dmitry@typo3.org>
30 */
31 class BackendFactory {
32
33 /**
34 * A list of all available backends. Currently this list cannot be extended.
35 * This is for security reasons to avoid inserting some dummy backend to
36 * the list.
37 *
38 * @var array
39 */
40 static protected $availableBackends = array(
41 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_php_backend.php:TYPO3\\CMS\\Rsaauth\\Backend\\PhpBackend',
42 'EXT:rsaauth/sv1/backends/class.tx_rsaauth_cmdline_backend.php:TYPO3\\CMS\\Rsaauth\\Backend\\CommandLineBackend'
43 );
44
45 /**
46 * A flag that tells if the factory is initialized. This is to prevent
47 * continious creation of backends in case if none of them is available.
48 *
49 * @var boolean
50 */
51 static protected $initialized = FALSE;
52
53 /**
54 * A selected backend. This member is set in the getBackend() function. It
55 * will not be an abstract backend as shown below but a real class, which is
56 * derieved from the tx_rsaauth_abstract_backend.
57 *
58 * @var \TYPO3\CMS\Rsaauth\Backend\AbstractBackend
59 */
60 static protected $selectedBackend = NULL;
61
62 /**
63 * Obtains a backend. This function will return a non-abstract class, which
64 * is derieved from the tx_rsaauth_abstract_backend. Applications should
65 * not use any methods that are not declared in the tx_rsaauth_abstract_backend.
66 *
67 * @return \TYPO3\CMS\Rsaauth\Backend\AbstractBackend A backend
68 */
69 static public function getBackend() {
70 if (!self::$initialized) {
71 // Backend does not exist yet. Create it.
72 foreach (self::$availableBackends as $backend) {
73 $backendObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($backend);
74 // Check that it is derieved from the proper base class
75 if ($backendObject instanceof \TYPO3\CMS\Rsaauth\Backend\AbstractBackend) {
76 /** @var $backendObject \TYPO3\CMS\Rsaauth\Backend\AbstractBackend */
77 if ($backendObject->isAvailable()) {
78 // The backend is available, save it and stop the loop
79 self::$selectedBackend = $backendObject;
80 self::$initialized = TRUE;
81 break;
82 }
83 // Attempt to force destruction of the object
84 unset($backendObject);
85 }
86 }
87 }
88 return self::$selectedBackend;
89 }
90
91 }
92
93
94 ?>