1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\module\cdc\Auth\Process; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Auth; |
8
|
|
|
use SimpleSAML\Error; |
9
|
|
|
use SimpleSAML\Logger; |
10
|
|
|
use SimpleSAML\Module; |
11
|
|
|
use SimpleSAML\Module\cdc\Client; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Filter for setting the SAML 2 common domain cookie. |
15
|
|
|
* |
16
|
|
|
* @package SimpleSAMLphp |
17
|
|
|
*/ |
18
|
|
|
class CDC extends Auth\ProcessingFilter |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Our CDC domain. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private string $domain; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Our CDC client. |
29
|
|
|
* |
30
|
|
|
* @var \SimpleSAML\Module\cdc\Client |
31
|
|
|
*/ |
32
|
|
|
private Client $client; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initialize this filter. |
37
|
|
|
* |
38
|
|
|
* @param array $config Configuration information about this filter. |
39
|
|
|
* @param mixed $reserved For future use. |
40
|
|
|
*/ |
41
|
|
|
public function __construct(array $config, $reserved) |
42
|
|
|
{ |
43
|
|
|
parent::__construct($config, $reserved); |
44
|
|
|
|
45
|
|
|
if (!isset($config['domain'])) { |
46
|
|
|
throw new Error\Exception('Missing domain option in cdc:CDC filter.'); |
47
|
|
|
} |
48
|
|
|
$this->domain = (string) $config['domain']; |
49
|
|
|
|
50
|
|
|
$this->client = new \SimpleSAML\Module\cdc\Client($this->domain); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Redirect to page setting CDC. |
56
|
|
|
* |
57
|
|
|
* @param array &$state The request state. |
58
|
|
|
*/ |
59
|
|
|
public function process(array &$state): void |
60
|
|
|
{ |
61
|
|
|
if (!isset($state['Source']['entityid'])) { |
62
|
|
|
Logger::warning('saml:CDC: Could not find IdP entityID.'); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Save state and build request |
67
|
|
|
$id = Auth\State::saveState($state, 'cdc:resume'); |
68
|
|
|
|
69
|
|
|
$returnTo = Module::getModuleURL('cdc/resume.php', ['domain' => $this->domain]); |
70
|
|
|
|
71
|
|
|
$params = [ |
72
|
|
|
'id' => $id, |
73
|
|
|
'entityID' => $state['Source']['entityid'], |
74
|
|
|
]; |
75
|
|
|
$this->client->sendRequest($returnTo, 'append', $params); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|