|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the tiqr project. |
|
4
|
|
|
* |
|
5
|
|
|
* The tiqr project aims to provide an open implementation for |
|
6
|
|
|
* authentication using mobile devices. It was initiated by |
|
7
|
|
|
* SURFnet and developed by Egeniq. |
|
8
|
|
|
* |
|
9
|
|
|
* More information: http://www.tiqr.org |
|
10
|
|
|
* |
|
11
|
|
|
* @author Ivo Jansch <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @package tiqr |
|
14
|
|
|
* |
|
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class implementing a factory to retrieve user secrets. |
|
22
|
|
|
* |
|
23
|
|
|
* @author lineke |
|
24
|
|
|
*/ |
|
25
|
|
|
class Tiqr_UserSecretStorage |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Get a secret storage of a certain type (default: 'file') |
|
29
|
|
|
* |
|
30
|
|
|
* @param String $type The type of storage to create. Supported |
|
31
|
|
|
* types are 'file', 'ldap', 'pdo' or 'oathservice'. |
|
32
|
|
|
* @param array $options The options to pass to the storage |
|
33
|
|
|
* instance. See the documentation |
|
34
|
|
|
* in the UserSecretStorage/ subdirectory for |
|
35
|
|
|
* options per type. |
|
36
|
|
|
* |
|
37
|
|
|
* @return Tiqr_UserSecretStorage_Interface |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function getSecretStorage($type="file", $options=array()) |
|
40
|
|
|
{ |
|
41
|
|
|
switch ($type) { |
|
42
|
|
|
case "file": |
|
43
|
|
|
require_once("Tiqr/UserSecretStorage/File.php"); |
|
44
|
|
|
$instance = new Tiqr_UserSecretStorage_File($options); |
|
45
|
|
|
break; |
|
46
|
|
|
case "ldap": |
|
47
|
|
|
require_once("Tiqr/UserSecretStorage/Ldap.php"); |
|
48
|
|
|
$instance = new Tiqr_UserSecretStorage_Ldap($options); |
|
49
|
|
|
break; |
|
50
|
|
|
case "pdo": |
|
51
|
|
|
require_once("Tiqr/UserSecretStorage/Pdo.php"); |
|
52
|
|
|
$instance = new Tiqr_UserSecretStorage_Pdo($options); |
|
53
|
|
|
break; |
|
54
|
|
|
case "oathserviceclient": |
|
55
|
|
|
require_once("Tiqr/UserSecretStorage/OathServiceClient.php"); |
|
56
|
|
|
$instance = new Tiqr_UserSecretStorage_OathServiceClient($options); |
|
57
|
|
|
break; |
|
58
|
|
|
default: |
|
59
|
|
|
if (!isset($type)) { |
|
60
|
|
|
throw new Exception('Class name not set'); |
|
61
|
|
|
} elseif (!class_exists($type)) { |
|
62
|
|
|
throw new Exception('Class not found: ' . var_export($type, TRUE)); |
|
63
|
|
|
} |
|
64
|
|
|
$instance = new $type($options); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $instance; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|