1 | <?php |
||
24 | abstract class AbstractLogoutController extends AbstractController implements \flipbox\saml\core\EnsureSAMLPlugin |
||
25 | { |
||
26 | |||
27 | protected $allowAnonymous = [ |
||
28 | 'actionIndex', |
||
29 | 'actionRequest', |
||
30 | ]; |
||
31 | |||
32 | public $enableCsrfValidation = false; |
||
33 | |||
34 | /** |
||
35 | * @return ProviderInterface |
||
36 | */ |
||
37 | abstract protected function getRemoteProvider($uid = null); |
||
38 | |||
39 | /** |
||
40 | * @param \yii\base\Action $action |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function beforeAction($action) |
||
44 | { |
||
45 | if (in_array( |
||
46 | $action->actionMethod, |
||
47 | [ |
||
48 | 'actionIndex', |
||
49 | 'actionRequest', |
||
50 | ] |
||
51 | )) { |
||
52 | return true; |
||
53 | } |
||
54 | return parent::beforeAction($action); |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * @return \yii\web\Response |
||
60 | * @throws HttpException |
||
61 | * @throws \flipbox\saml\core\exceptions\InvalidMetadata |
||
62 | * @throws \yii\base\ExitException |
||
63 | * @throws \yii\base\InvalidConfigException |
||
64 | */ |
||
65 | public function actionIndex() |
||
66 | { |
||
67 | $message = Factory::receive(); |
||
68 | |||
69 | $isRequest = $message instanceof LogoutRequest; |
||
70 | $isResponse = $message instanceof LogoutResponse; |
||
71 | |||
72 | if ((! $isRequest && ! $isResponse) || |
||
73 | $isResponse && $this->getPlugin()->getSession()->getRequestId() !== $message->getInResponseTo()) { |
||
|
|||
74 | throw new HttpException(400, "Invalid request"); |
||
75 | } |
||
76 | |||
77 | /** @var AbstractProvider $theirProvider */ |
||
78 | $theirProvider = $this->getPlugin()->getProvider()->findByEntityId( |
||
79 | MessageHelper::getIssuer($message->getIssuer()) |
||
80 | )->one(); |
||
81 | |||
82 | /** @var AbstractProvider $ourProvider */ |
||
83 | $ourProvider = $this->getPlugin()->getProvider()->findOwn(); |
||
84 | |||
85 | if ($isRequest) { |
||
86 | if (\Craft::$app->getUser()->isGuest) { |
||
87 | $this->destroySpecifiedSession( |
||
88 | $message, |
||
89 | $theirProvider, |
||
90 | $this->getPlugin()->getSettings() |
||
91 | ); |
||
92 | } |
||
93 | |||
94 | /** @var LogoutResponse $response */ |
||
95 | $response = $this->getPlugin()->getLogoutResponse()->create( |
||
96 | $message, |
||
97 | $theirProvider, |
||
98 | $ourProvider |
||
99 | ); |
||
100 | |||
101 | /** |
||
102 | * Add the request id to the the response. |
||
103 | */ |
||
104 | $response->setInResponseTo($message->getId()); |
||
105 | |||
106 | \Craft::$app->user->logout(true); |
||
107 | Factory::send($response, $theirProvider); |
||
108 | \Craft::$app->end(); |
||
109 | } |
||
110 | |||
111 | return $this->redirect( |
||
112 | \Craft::$app->config->general->logoutPath |
||
113 | ); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param LogoutRequest $message |
||
118 | * @param AbstractProvider $theirProvider |
||
119 | * @throws \yii\db\Exception |
||
120 | */ |
||
121 | protected function destroySpecifiedSession( |
||
144 | |||
145 | |||
146 | /** |
||
147 | * @param null $uid |
||
148 | * @throws \flipbox\saml\core\exceptions\InvalidMetadata |
||
149 | * @throws \yii\base\ExitException |
||
150 | * @throws \yii\base\InvalidConfigException |
||
151 | */ |
||
152 | public function actionRequest($uid = null) |
||
196 | } |
||
197 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: