@@ -131,25 +131,62 @@ public function authPreDispatch($event)
131
131
$ objectManagerProvider = $ serviceManager ->get (\Magento \Setup \Model \ObjectManagerProvider::class);
132
132
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
133
133
$ objectManager = $ objectManagerProvider ->get ();
134
- $ authorization = $ objectManager ->get (\Magento \Setup \Mvc \Bootstrap \Authorization::class);
135
- if (!$ authorization ->authorize ()) {
134
+ /** @var \Magento\Framework\App\State $adminAppState */
135
+ $ adminAppState = $ objectManager ->get (\Magento \Framework \App \State::class);
136
+ $ adminAppState ->setAreaCode (\Magento \Framework \App \Area::AREA_ADMINHTML );
137
+ /** @var \Magento\Backend\Model\Session\AdminConfig $sessionConfig */
138
+ $ sessionConfig = $ objectManager ->get (\Magento \Backend \Model \Session \AdminConfig::class);
139
+ $ cookiePath = $ this ->getSetupCookiePath ($ objectManager );
140
+ $ sessionConfig ->setCookiePath ($ cookiePath );
141
+ /** @var \Magento\Backend\Model\Auth\Session $adminSession */
142
+ $ adminSession = $ objectManager ->create (
143
+ \Magento \Backend \Model \Auth \Session::class,
144
+ [
145
+ 'sessionConfig ' => $ sessionConfig ,
146
+ 'appState ' => $ adminAppState
147
+ ]
148
+ );
149
+ /** @var \Magento\Backend\Model\Auth $auth */
150
+ $ authentication = $ objectManager ->get (\Magento \Backend \Model \Auth::class);
151
+
152
+ if (!$ authentication ->isLoggedIn () ||
153
+ !$ adminSession ->isAllowed ('Magento_Backend::setup_wizard ' )
154
+ ) {
155
+ $ adminSession ->destroy ();
136
156
/** @var \Zend\Http\Response $response */
137
157
$ response = $ event ->getResponse ();
138
158
$ baseUrl = Http::getDistroBaseUrlPath ($ _SERVER );
139
- $ response ->getHeaders ()
140
- ->addHeaderLine (
141
- 'Location ' ,
142
- $ baseUrl . 'index.php/session/unlogin '
143
- );
159
+ $ response ->getHeaders ()->addHeaderLine ('Location ' , $ baseUrl . 'index.php/session/unlogin ' );
144
160
$ response ->setStatusCode (302 );
145
161
$ event ->stopPropagation ();
162
+
146
163
return $ response ;
147
164
}
148
165
}
149
166
}
167
+
150
168
return false ;
151
169
}
152
170
171
+ /**
172
+ * Get cookie path
173
+ *
174
+ * @param \Magento\Framework\ObjectManagerInterface $objectManager
175
+ * @return string
176
+ */
177
+ private function getSetupCookiePath (\Magento \Framework \ObjectManagerInterface $ objectManager )
178
+ {
179
+ /** @var \Magento\Backend\App\BackendAppList $backendAppList */
180
+ $ backendAppList = $ objectManager ->get (\Magento \Backend \App \BackendAppList::class);
181
+ $ backendApp = $ backendAppList ->getBackendApp ('setup ' );
182
+ /** @var \Magento\Backend\Model\Url $url */
183
+ $ url = $ objectManager ->create (\Magento \Backend \Model \Url::class);
184
+ $ baseUrl = parse_url ($ url ->getBaseUrl (), PHP_URL_PATH );
185
+ $ baseUrl = \Magento \Framework \App \Request \Http::getUrlNoScript ($ baseUrl );
186
+ $ cookiePath = $ baseUrl . $ backendApp ->getCookiePath ();
187
+ return $ cookiePath ;
188
+ }
189
+
153
190
/**
154
191
* {@inheritdoc}
155
192
*/
0 commit comments