1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* simpleSAMLphp-casserver is a CAS 1.0 and 2.0 compliant CAS server in the form of a simpleSAMLphp module |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2013 Bjorn R. Jensen |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
declare(strict_types=1); |
25
|
|
|
|
26
|
|
|
namespace SimpleSAML\Module\casserver\Cas\Ticket; |
27
|
|
|
|
28
|
|
|
use SimpleSAML\Configuration; |
29
|
|
|
use SimpleSAML\Memcache; |
30
|
|
|
|
31
|
|
|
class MemCacheTicketStore extends TicketStore |
32
|
|
|
{ |
33
|
|
|
/** @var string $prefix */ |
34
|
|
|
private string $prefix = ''; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param \SimpleSAML\Configuration $config |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Configuration $config) |
41
|
|
|
{ |
42
|
|
|
parent::__construct($config); |
43
|
|
|
|
44
|
|
|
$storeConfig = $config->getOptionalValue('ticketstore', []); |
45
|
|
|
|
46
|
|
|
if (array_key_exists('prefix', $storeConfig)) { |
47
|
|
|
$this->prefix = $storeConfig['prefix']; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $ticketId |
54
|
|
|
* @return array|null |
55
|
|
|
*/ |
56
|
|
|
public function getTicket(string $ticketId): ?array |
57
|
|
|
{ |
58
|
|
|
$scopedTicketId = $this->scopeTicketId($ticketId); |
59
|
|
|
|
60
|
|
|
return Memcache::get($scopedTicketId); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param array $ticket |
66
|
|
|
*/ |
67
|
|
|
public function addTicket(array $ticket): void |
68
|
|
|
{ |
69
|
|
|
$scopedTicketId = $this->scopeTicketId($ticket['id']); |
70
|
|
|
|
71
|
|
|
Memcache::set($scopedTicketId, $ticket, $ticket['validBefore']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $ticketId |
77
|
|
|
*/ |
78
|
|
|
public function deleteTicket(string $ticketId): void |
79
|
|
|
{ |
80
|
|
|
$scopedTicketId = $this->scopeTicketId($ticketId); |
81
|
|
|
|
82
|
|
|
Memcache::delete($scopedTicketId); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $ticketId |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
private function scopeTicketId(string $ticketId): string |
91
|
|
|
{ |
92
|
|
|
return $this->prefix . '.' . $ticketId; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|