1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: dsmrt |
5
|
|
|
* Date: 3/9/18 |
6
|
|
|
* Time: 2:48 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\saml\core\controllers\cp\view; |
10
|
|
|
|
11
|
|
|
use flipbox\saml\core\AbstractPlugin; |
12
|
|
|
use flipbox\saml\core\records\ProviderInterface; |
13
|
|
|
use flipbox\saml\core\Saml; |
14
|
|
|
use flipbox\saml\core\traits\EnsureSamlPlugin; |
15
|
|
|
use flipbox\saml\core\controllers\AbstractController as BaseController; |
16
|
|
|
use flipbox\saml\core\web\assets\bundles\SamlCore; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class AbstractController |
20
|
|
|
* @package flipbox\saml\core\controllers\cp\view |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractController extends BaseController |
23
|
|
|
{ |
24
|
|
|
use EnsureSamlPlugin; |
25
|
|
|
|
26
|
|
|
const TEMPLATE_INDEX = DIRECTORY_SEPARATOR . '_cp'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @throws \yii\base\InvalidConfigException |
30
|
|
|
*/ |
31
|
|
|
public function init() |
32
|
|
|
{ |
33
|
|
|
parent::init(); |
34
|
|
|
\Craft::$app->view->registerAssetBundle( |
35
|
|
|
SamlCore::class |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
abstract protected function getProviderRecord(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
protected function getTemplateIndex() |
48
|
|
|
{ |
49
|
|
|
return Saml::getTemplateRootKey( |
50
|
|
|
$this->getSamlPlugin() |
|
|
|
|
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function getBaseVariables() |
58
|
|
|
{ |
59
|
|
|
$variables = [ |
60
|
|
|
'title' => $this->getSamlPlugin()->name, |
|
|
|
|
61
|
|
|
'pluginHandle' => $this->getSamlPlugin()->getHandle(), |
62
|
|
|
'pluginVariable' => $this->getSamlPlugin()->getPluginVariableHandle(), |
63
|
|
|
'ownEntityId' => $this->getSamlPlugin()->getSettings()->getEntityId(), |
64
|
|
|
'settings' => $this->getSamlPlugin()->getSettings(), |
65
|
|
|
|
66
|
|
|
// Set the "Continue Editing" URL |
67
|
|
|
'continueEditingUrl' => $this->getBaseCpPath(), |
68
|
|
|
'baseActionPath' => $this->getBaseCpPath(), |
69
|
|
|
'baseCpPath' => $this->getBaseCpPath(), |
70
|
|
|
'templateIndex' => $this->getTemplateIndex(), |
71
|
|
|
'ownProvider' => $ownProvider = $this->getSamlPlugin()->getProvider()->findOwn(), |
72
|
|
|
|
73
|
|
|
'actions' => [], |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$variables['selectedSubnavItem'] = $this->getSubNavKey(); |
77
|
|
|
|
78
|
|
|
/** @var ProviderInterface $ownProvider */ |
79
|
|
|
if ($ownProvider) { |
80
|
|
|
$variables = array_merge( |
81
|
|
|
$this->addUrls($ownProvider), |
82
|
|
|
$variables |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $variables; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return null|string |
91
|
|
|
*/ |
92
|
|
|
protected function getSubNavKey() |
93
|
|
|
{ |
94
|
|
|
$request = \Craft::$app->request; |
95
|
|
|
|
96
|
|
|
$key = null; |
97
|
|
|
$path = implode( |
98
|
|
|
'/', |
99
|
|
|
[ |
100
|
|
|
$request->getSegment(2), |
101
|
|
|
$request->getSegment(3), |
102
|
|
|
$request->getSegment(4), |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
if (preg_match('#^/+$#', $path)) { |
107
|
|
|
$key = 'saml.setup'; |
108
|
|
|
} elseif (preg_match('#metadata/my-provider/#', $path)) { |
109
|
|
|
$key = 'saml.myProvider'; |
110
|
|
|
} elseif (preg_match('#metadata/+$#', $path)) { |
111
|
|
|
$key = 'saml.providers'; |
112
|
|
|
} elseif (preg_match('#keychain/+$#', $path)) { |
113
|
|
|
$key = 'saml.keychain'; |
114
|
|
|
} elseif (preg_match('#settings/+$#', $path)) { |
115
|
|
|
$key = 'saml.settings'; |
116
|
|
|
} |
117
|
|
|
return $key; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
protected function getBaseCpPath(): string |
124
|
|
|
{ |
125
|
|
|
return $this->getSamlPlugin()->getHandle(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param ProviderInterface $provider |
130
|
|
|
* @param array $variables |
|
|
|
|
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
protected function addUrls(ProviderInterface $provider) |
134
|
|
|
{ |
135
|
|
|
|
136
|
|
|
$variables = []; |
137
|
|
|
$variables['assertionConsumerServices'] = null; |
138
|
|
|
$variables['singleLogoutServices'] = null; |
139
|
|
|
$variables['singleSignOnServices'] = null; |
140
|
|
|
|
141
|
|
|
if (! $provider->getMetadataModel()) { |
142
|
|
|
return $variables; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** @var AbstractPlugin $plugin */ |
146
|
|
|
$plugin = $this->getSamlPlugin(); |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Add SP URLs |
150
|
|
|
*/ |
151
|
|
|
if ($provider->getType() === $plugin::SP) { |
152
|
|
|
foreach ($provider-> |
153
|
|
|
getMetadataModel()-> |
154
|
|
|
getFirstSpSsoDescriptor()-> |
155
|
|
|
getAllSingleLogoutServices() as $singleLogoutService) { |
156
|
|
|
$variables['singleLogoutServices'][$singleLogoutService->getBinding()] = |
157
|
|
|
$singleLogoutService->getResponseLocation(); |
158
|
|
|
} |
159
|
|
|
foreach ($provider->getMetadataModel()-> |
160
|
|
|
getFirstSpSsoDescriptor()-> |
161
|
|
|
getAllAssertionConsumerServices() as $assertionConsumerService) { |
162
|
|
|
$variables['assertionConsumerServices'][$assertionConsumerService->getBinding()] = |
163
|
|
|
$assertionConsumerService->getLocation(); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Add IDP URLs |
169
|
|
|
*/ |
170
|
|
|
if ($provider->getType() === $plugin::IDP) { |
171
|
|
|
foreach ($provider->getMetadataModel()-> |
172
|
|
|
getFirstIdpSsoDescriptor()-> |
173
|
|
|
getAllSingleLogoutServices() as $singleLogoutService) { |
174
|
|
|
$variables['singleLogoutServices'][$singleLogoutService->getBinding()] = |
175
|
|
|
$singleLogoutService->getLocation(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
foreach ($provider->getMetadataModel()-> |
179
|
|
|
getFirstIdpSsoDescriptor()-> |
180
|
|
|
getAllSingleSignOnServices() as $signOnService) { |
181
|
|
|
$variables['singleSignOnServices'][$signOnService->getBinding()] = $signOnService->getLocation(); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $variables; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param $type |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
protected function getTitle($type) |
194
|
|
|
{ |
195
|
|
|
/** @var AbstractPlugin $plugin */ |
196
|
|
|
$plugin = $this->getSamlPlugin(); |
197
|
|
|
return $type === $plugin::SP ? 'Service Provider (SP)' : 'Identity Provider (IDP)'; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: