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\keychain\KeyChain; |
12
|
|
|
use flipbox\saml\core\records\ProviderInterface; |
13
|
|
|
use flipbox\saml\core\traits\EnsureSamlPlugin; |
14
|
|
|
|
15
|
|
|
trait VariablesTrait |
16
|
|
|
{ |
17
|
|
|
use EnsureSamlPlugin; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ProviderInterface $provider |
21
|
|
|
* @return array |
22
|
|
|
*/ |
23
|
|
|
protected function getActions(ProviderInterface $provider) |
24
|
|
|
{ |
25
|
|
|
$actions = []; |
26
|
|
|
|
27
|
|
|
if ($provider->id) { |
|
|
|
|
28
|
|
|
$actions = [ |
29
|
|
|
[ |
30
|
|
|
//action list 1 |
31
|
|
|
[ |
32
|
|
|
'action' => $this->getSamlPlugin()->getHandle() . '/metadata/change-status', |
33
|
|
|
'label' => $provider->enabled ? 'Disable' : 'Enable', |
|
|
|
|
34
|
|
|
], |
35
|
|
|
[ |
36
|
|
|
'action' => $this->getSamlPlugin()->getHandle() . '/metadata/delete', |
37
|
|
|
'label' => 'Delete', |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
return $actions; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
protected function getBaseVariables() |
49
|
|
|
{ |
50
|
|
|
|
51
|
|
|
return array_merge( |
52
|
|
|
parent::getBaseVariables(), |
53
|
|
|
[ |
54
|
|
|
'autoCreate' => false, |
55
|
|
|
'myEntityId' => $this->getSamlPlugin()->getSettings()->getEntityId(), |
56
|
|
|
'myType' => $this->getSamlPlugin()->getSettings(), |
57
|
|
|
] |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string|null|ProviderInterface $provider |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
protected function prepVariables($provider = null) |
66
|
|
|
{ |
67
|
|
|
$variables = $this->getBaseVariables(); |
68
|
|
|
|
69
|
|
|
$variables['title'] = Craft::t( |
70
|
|
|
$this->getSamlPlugin()->getHandle(), |
71
|
|
|
$this->getSamlPlugin()->name |
|
|
|
|
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* TYPES |
76
|
|
|
*/ |
77
|
|
|
$variables['myType'] = $this->getSamlPlugin()->getMyType(); |
78
|
|
|
$variables['remoteType'] = $this->getSamlPlugin()->getRemoteType(); |
79
|
|
|
$variables['createType'] = $variables['remoteType']; |
80
|
|
|
|
81
|
|
|
if ($provider) { |
82
|
|
|
/** |
83
|
|
|
* @var ProviderInterface $provider |
84
|
|
|
*/ |
85
|
|
|
$provider = $variables['provider'] = ( |
86
|
|
|
/** |
87
|
|
|
* Is instance provider |
88
|
|
|
*/ |
89
|
|
|
$provider instanceof ProviderInterface ? |
90
|
|
|
$provider : |
91
|
|
|
$provider = $this->getSamlPlugin()->getProviderRecordClass()::find()->where([ |
92
|
|
|
/** |
93
|
|
|
* Is ID |
94
|
|
|
*/ |
95
|
|
|
'id' => $provider, |
96
|
|
|
])->one() |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$variables['title'] .= ': Edit'; |
100
|
|
|
|
101
|
|
|
$crumb = [ |
102
|
|
|
[ |
103
|
|
|
|
104
|
|
|
'url' => UrlHelper::cpUrl( |
105
|
|
|
implode( |
106
|
|
|
'/', |
107
|
|
|
[ |
108
|
|
|
$this->getSamlPlugin()->getHandle(), |
109
|
|
|
'metadata', |
110
|
|
|
] |
111
|
|
|
) |
112
|
|
|
), |
113
|
|
|
'label' => 'Provider List', |
114
|
|
|
], [ |
115
|
|
|
'url' => UrlHelper::cpUrl( |
116
|
|
|
$this->getSamlPlugin()->getHandle() . '/metadata/' . $provider->id |
|
|
|
|
117
|
|
|
), |
118
|
|
|
'label' => $provider->label ?: $provider->entityId, |
|
|
|
|
119
|
|
|
] |
120
|
|
|
]; |
121
|
|
|
$variables['keypair'] = $provider->keychain; |
|
|
|
|
122
|
|
|
|
123
|
|
|
$variables = array_merge( |
124
|
|
|
$variables, |
125
|
|
|
$this->addUrls($provider) |
|
|
|
|
126
|
|
|
); |
127
|
|
|
} else { |
128
|
|
|
$record = $this->getSamlPlugin()->getProviderRecordClass(); |
129
|
|
|
|
130
|
|
|
$provider = $variables['provider'] = new $record([ |
|
|
|
|
131
|
|
|
'providerType' => 'idp', |
132
|
|
|
]); |
133
|
|
|
|
134
|
|
|
$variables['title'] .= ': Create'; |
135
|
|
|
|
136
|
|
|
$crumb = [ |
137
|
|
|
[ |
138
|
|
|
'url' => UrlHelper::cpUrl( |
139
|
|
|
$this->getSamlPlugin()->getHandle() . '/new' |
140
|
|
|
), |
141
|
|
|
'label' => 'New', |
142
|
|
|
] |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$variables['allkeypairs'] = []; |
147
|
|
|
|
148
|
|
|
$keypairs = KeyChain::getInstance()->getService()->findByPlugin($this->getSamlPlugin())->all(); |
149
|
|
|
|
150
|
|
|
foreach ($keypairs as $keypair) { |
151
|
|
|
$variables['allkeypairs'][] = [ |
152
|
|
|
'label' => $keypair->description, |
153
|
|
|
'value' => $keypair->id, |
154
|
|
|
]; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$variables['crumbs'] = array_merge([ |
158
|
|
|
[ |
159
|
|
|
'url' => UrlHelper::cpUrl($this->getSamlPlugin()->getHandle()), |
160
|
|
|
'label' => Craft::t($this->getSamlPlugin()->getHandle(), $this->getSamlPlugin()->name), |
|
|
|
|
161
|
|
|
], |
162
|
|
|
], $crumb); |
163
|
|
|
|
164
|
|
|
return $variables; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: