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
|
|
|
namespace \SimpleSAML\Module\casserver\Cas\Ticket; |
|
|
|
|
25
|
|
|
|
26
|
|
|
class MemCacheTicketStore extends TicketStore |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
private $prefix = ''; |
29
|
|
|
|
30
|
|
|
public function __construct(\SimpleSAML\Configuration $config) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
parent::__construct($config); |
33
|
|
|
|
34
|
|
|
$storeConfig = $config->getValue('ticketstore'); |
35
|
|
|
|
36
|
|
|
if (array_key_exists('prefix', $storeConfig)) { |
37
|
|
|
$this->prefix = $storeConfig['prefix']; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $ticketId string |
43
|
|
|
* @return array|null |
44
|
|
|
*/ |
45
|
|
|
public function getTicket($ticketId) |
46
|
|
|
{ |
47
|
|
|
$scopedTicketId = $this->scopeTicketId($ticketId); |
48
|
|
|
|
49
|
|
|
return \SimpleSAML\Memcache::get($scopedTicketId); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function addTicket(array $ticket) |
53
|
|
|
{ |
54
|
|
|
$scopedTicketId = $this->scopeTicketId($ticket['id']); |
55
|
|
|
|
56
|
|
|
\SimpleSAML\Memcache::set($scopedTicketId, $ticket, $ticket['validBefore']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $ticketId string |
61
|
|
|
*/ |
62
|
|
|
public function deleteTicket($ticketId) |
63
|
|
|
{ |
64
|
|
|
$scopedTicketId = $this->scopeTicketId($ticketId); |
65
|
|
|
|
66
|
|
|
\SimpleSAML\Memcache::delete($scopedTicketId); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $ticketId string |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
private function scopeTicketId($ticketId) |
74
|
|
|
{ |
75
|
|
|
return $this->prefix.'.'.$ticketId; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|