|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace flipbox\saml\sp\commands; |
|
5
|
|
|
|
|
6
|
|
|
use craft\console\Controller; |
|
7
|
|
|
use flipbox\saml\sp\records\ProviderRecord; |
|
8
|
|
|
use flipbox\saml\sp\Saml; |
|
9
|
|
|
use yii\console\ExitCode; |
|
10
|
|
|
use yii\console\widgets\Table; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Automate Provider Operations |
|
14
|
|
|
* Class MetadataController |
|
15
|
|
|
* @package flipbox\saml\sp\commands |
|
16
|
|
|
*/ |
|
17
|
|
|
class MetadataController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function actionIndex() |
|
21
|
|
|
{ |
|
22
|
|
|
$providerQuery = ProviderRecord::find(); |
|
23
|
|
|
|
|
24
|
|
|
$rows = []; |
|
25
|
|
|
foreach ($providerQuery->all() as $provider) { |
|
26
|
|
|
/** @var ProviderRecord $provider */ |
|
27
|
|
|
|
|
28
|
|
|
$rows[] = [ |
|
29
|
|
|
$provider->id, |
|
|
|
|
|
|
30
|
|
|
$provider->getType(), |
|
31
|
|
|
$provider->label, |
|
|
|
|
|
|
32
|
|
|
$provider->entityId, |
|
|
|
|
|
|
33
|
|
|
$provider->uid, |
|
34
|
|
|
$provider->enabled ? 'enabled' : 'disabled', |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
$this->stdout(Table::widget([ |
|
38
|
|
|
'headers' => [ |
|
39
|
|
|
'ID', |
|
40
|
|
|
'TYPE', |
|
41
|
|
|
'LABEL', |
|
42
|
|
|
'ENTITY ID', |
|
43
|
|
|
'UID', |
|
44
|
|
|
'ENABLED/DISABLED', |
|
45
|
|
|
], |
|
46
|
|
|
'rows' => $rows, |
|
47
|
|
|
])); |
|
48
|
|
|
return ExitCode::OK; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Refresh and save the metadata from the URL saved on the provider. |
|
53
|
|
|
* Configure the URL in the Craft Control Panel before using this. |
|
54
|
|
|
* |
|
55
|
|
|
* @param $uid |
|
56
|
|
|
*/ |
|
57
|
|
|
public function actionRefreshWithUrl(string $uid) |
|
58
|
|
|
{ |
|
59
|
|
|
$message = |
|
60
|
|
|
sprintf('Trying Provider with uid %s.', $uid); |
|
61
|
|
|
$this->stderr($message . PHP_EOL); |
|
62
|
|
|
Saml::info($message); |
|
63
|
|
|
|
|
64
|
|
|
/** @var ProviderRecord $provider */ |
|
65
|
|
|
if (! $provider = Saml::getInstance()->getProvider()->findByIdp([ |
|
66
|
|
|
'uid' => $uid, |
|
67
|
|
|
])->one()) { |
|
68
|
|
|
$message = |
|
69
|
|
|
sprintf('Provider with uid %s not found.', $uid); |
|
70
|
|
|
$this->stderr( |
|
71
|
|
|
$message |
|
72
|
|
|
); |
|
73
|
|
|
Saml::warning($message); |
|
74
|
|
|
return ExitCode::DATAERR; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (! $url = $provider->getMetadataOptions()->url) { |
|
78
|
|
|
$message = |
|
79
|
|
|
sprintf('Provider with uid %s does not have a metadata url.', $uid); |
|
80
|
|
|
$this->stderr($message . PHP_EOL); |
|
81
|
|
|
Saml::warning($message); |
|
82
|
|
|
return ExitCode::DATAERR; |
|
83
|
|
|
} |
|
84
|
|
|
$message = |
|
85
|
|
|
sprintf('Provider %s (%s) found with URL %s.', $uid, $provider->getEntityId(), $url); |
|
86
|
|
|
$this->stderr($message . PHP_EOL); |
|
87
|
|
|
Saml::info($message); |
|
88
|
|
|
|
|
89
|
|
|
$entityDescriptor = Saml::getInstance()->getMetadata()->fetchByUrl($url); |
|
90
|
|
|
|
|
91
|
|
|
$provider->metadata = $entityDescriptor->toXML()->ownerDocument->saveXML(); |
|
92
|
|
|
$provider->setMetadataModel($entityDescriptor); |
|
93
|
|
|
|
|
94
|
|
|
Saml::getInstance()->getProvider()->save($provider); |
|
95
|
|
|
$message = sprintf('Provider %s saved! (%s)', $uid, $entityDescriptor->getEntityID()); |
|
96
|
|
|
Saml::info($message); |
|
97
|
|
|
$this->stdout($message . PHP_EOL); |
|
98
|
|
|
|
|
99
|
|
|
return ExitCode::OK; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.