1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace flipbox\saml\core\controllers\cp\view\metadata; |
8
|
|
|
|
9
|
|
|
use Craft; |
10
|
|
|
use craft\helpers\UrlHelper; |
11
|
|
|
use flipbox\saml\core\AbstractPlugin; |
12
|
|
|
use flipbox\saml\core\controllers\cp\view\AbstractController; |
13
|
|
|
use flipbox\saml\core\EnsureSAMLPlugin; |
14
|
|
|
use flipbox\saml\core\models\SettingsInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AbstractDefaultController |
18
|
|
|
* @package flipbox\saml\core\controllers\cp\view\metadata |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractDefaultController extends AbstractController implements EnsureSAMLPlugin |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
const TEMPLATE_INDEX = DIRECTORY_SEPARATOR . '_cp' . DIRECTORY_SEPARATOR . 'metadata'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return \yii\web\Response |
27
|
|
|
* @throws \Exception |
28
|
|
|
*/ |
29
|
|
|
public function actionIndex() |
30
|
|
|
{ |
31
|
|
|
$variables = $this->getPlugin()->getEditProvider()->getBaseVariables(); |
32
|
|
|
$plugin = $this->getPlugin(); |
33
|
|
|
$variables['myProvider'] = null; |
34
|
|
|
$variables['spProviders'] = []; |
35
|
|
|
$variables['idpProviders'] = []; |
36
|
|
|
$variables['idpListInstructions'] = $this->getListInstructions(SettingsInterface::IDP); |
37
|
|
|
$variables['spListInstructions'] = $this->getListInstructions(SettingsInterface::SP); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Breadcrumbs |
41
|
|
|
*/ |
42
|
|
|
$variables['crumbs'] = [ |
43
|
|
|
[ |
44
|
|
|
'url' => UrlHelper::cpUrl($this->getPlugin()->getHandle()), |
45
|
|
|
'label' => $this->getPlugin()->name, |
46
|
|
|
], |
47
|
|
|
[ |
48
|
|
|
'url' => UrlHelper::cpUrl($this->getPlugin()->getHandle()) . '/metadata', |
49
|
|
|
'label' => 'Provider List', |
50
|
|
|
], |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get IDPs |
55
|
|
|
*/ |
56
|
|
|
foreach ($plugin->getProvider()->findByIdp([ |
57
|
|
|
'enabled' => [true, false], |
58
|
|
|
])->all() as $provider) { |
59
|
|
|
$variables['idpProviders'][] = $provider; |
60
|
|
|
if ($provider->getEntityId() == $this->getPlugin()->getSettings()->getEntityId()) { |
61
|
|
|
$variables['myProvider'] = $provider; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get SPs |
67
|
|
|
*/ |
68
|
|
|
foreach ($plugin->getProvider()->findBySp([ |
69
|
|
|
'enabled' => [true, false], |
70
|
|
|
])->all() as $provider) { |
71
|
|
|
$variables['spProviders'][] = $provider; |
72
|
|
|
if ($provider->getEntityId() == $this->getPlugin()->getSettings()->getEntityId()) { |
73
|
|
|
$variables['myProvider'] = $provider; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$variables['title'] = Craft::t($this->getPlugin()->getHandle(), $this->getPlugin()->name); |
78
|
|
|
return $this->renderTemplate( |
79
|
|
|
$this->getPlugin()->getEditProvider()->getTemplateIndex() . static::TEMPLATE_INDEX . DIRECTORY_SEPARATOR . 'list', |
80
|
|
|
$variables |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param $providerType |
86
|
|
|
* @return string |
87
|
|
|
* @throws \Exception |
88
|
|
|
*/ |
89
|
|
|
protected function getListInstructions($providerType) |
90
|
|
|
{ |
91
|
|
|
/** @var AbstractPlugin $plugin */ |
92
|
|
|
$plugin = $this->getPlugin(); |
|
|
|
|
93
|
|
|
if (! in_array($providerType, [ |
94
|
|
|
SettingsInterface::SP, |
95
|
|
|
SettingsInterface::IDP, |
96
|
|
|
])) { |
97
|
|
|
throw new \Exception($providerType . ' is not a valid type.'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Base return off of getMyType and the provider type passed |
102
|
|
|
*/ |
103
|
|
|
switch ($this->getPlugin()->getMyType()) { |
104
|
|
|
case SettingsInterface::IDP: |
105
|
|
|
$return = SettingsInterface::SP === $providerType ? Craft::t( |
106
|
|
|
$this->getPlugin()->getHandle(), |
107
|
|
|
'These are the remote providers using this Craft CMS instance to authenticate. ' |
108
|
|
|
) : Craft::t( |
109
|
|
|
$this->getPlugin()->getHandle(), |
110
|
|
|
'Your provider configuration(s).' |
111
|
|
|
); |
112
|
|
|
break; |
113
|
|
|
case SettingsInterface::SP: |
114
|
|
|
$return = SettingsInterface::SP === $providerType ? Craft::t( |
115
|
|
|
$this->getPlugin()->getHandle(), |
116
|
|
|
'Your provider configuration(s). ' |
117
|
|
|
) : Craft::t( |
118
|
|
|
$this->getPlugin()->getHandle(), |
119
|
|
|
'These are the remote providers where the user ' . |
120
|
|
|
'authenticates, ie, OKTA, Microsoft AD, or Google, etc. To configure and IDP, simply obtain the metadata.' |
121
|
|
|
); |
122
|
|
|
break; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $return; |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.