1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\Config; |
4
|
|
|
|
5
|
|
|
use AerialShip\LightSaml\Bindings; |
6
|
|
|
use AerialShip\LightSaml\Meta\SpMeta; |
7
|
|
|
use AerialShip\LightSaml\NameIDPolicy; |
8
|
|
|
|
9
|
|
|
class SpMetaConfigProvider implements SpMetaProviderInterface |
10
|
|
|
{ |
11
|
|
|
/** @var SpMeta */ |
12
|
|
|
protected $spMeta; |
13
|
|
|
|
14
|
|
|
|
15
|
6 |
|
public function __construct(array $config) |
16
|
|
|
{ |
17
|
6 |
|
if (!isset($config['name_id_format'])) { |
18
|
4 |
|
$config['name_id_format'] = NameIDPolicy::PERSISTENT; |
19
|
4 |
|
} |
20
|
6 |
|
if (!array_key_exists('binding', $config)) { |
21
|
4 |
|
$config['binding'] = array(); |
22
|
4 |
|
} |
23
|
6 |
|
if (!isset($config['binding']['authn_request'])) { |
24
|
4 |
|
$config['binding']['authn_request'] = Bindings::SAML2_HTTP_POST; |
25
|
4 |
|
} |
26
|
6 |
|
if (!isset($config['binding']['response'])) { |
27
|
6 |
|
$config['binding']['response'] = Bindings::SAML2_HTTP_POST; |
28
|
6 |
|
} |
29
|
6 |
|
if (!isset($config['binding']['logout_request'])) { |
30
|
4 |
|
$config['binding']['logout_request'] = Bindings::SAML2_HTTP_POST; |
31
|
4 |
|
} |
32
|
|
|
|
33
|
6 |
|
$this->spMeta = new SpMeta(); |
34
|
6 |
|
$this->spMeta->setNameIdFormat($this->resolveNameIDFormat($config['name_id_format'])); |
35
|
6 |
|
$this->spMeta->setAuthnRequestBinding($this->resolveBinding($config['binding']['authn_request'])); |
36
|
6 |
|
$this->spMeta->setResponseBinding($this->resolveBinding($config['binding']['response'])); |
37
|
6 |
|
$this->spMeta->setLogoutRequestBinding($this->resolveBinding($config['binding']['logout_request'])); |
38
|
6 |
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return SpMeta |
44
|
|
|
*/ |
45
|
5 |
|
public function getSpMeta() |
46
|
|
|
{ |
47
|
5 |
|
return $this->spMeta; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $value |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
6 |
|
protected function resolveNameIDFormat($value) |
56
|
|
|
{ |
57
|
|
|
switch ($value) { |
58
|
6 |
|
case 'persistent': |
59
|
1 |
|
$result = NameIDPolicy::PERSISTENT; |
60
|
1 |
|
break; |
61
|
5 |
|
case 'transient': |
62
|
1 |
|
$result = NameIDPolicy::TRANSIENT; |
63
|
1 |
|
break; |
64
|
4 |
|
default: |
65
|
4 |
|
$result = $value; |
66
|
4 |
|
} |
67
|
6 |
|
return $result; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $value |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
6 |
|
protected function resolveBinding($value) |
75
|
|
|
{ |
76
|
|
|
switch ($value) { |
77
|
6 |
|
case 'post': |
78
|
1 |
|
$result = Bindings::SAML2_HTTP_POST; |
79
|
1 |
|
break; |
80
|
6 |
|
case 'redirect': |
81
|
1 |
|
$result = Bindings::SAML2_HTTP_REDIRECT; |
82
|
1 |
|
break; |
83
|
6 |
|
default: |
84
|
6 |
|
$result = $value; |
85
|
6 |
|
} |
86
|
6 |
|
return $result; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|