mirror of https://github.com/MISP/MISP
chg: [AppController] move loading and initialisation of Auth plugins to reuseable method
For some authentication workflows it might be desireable to execute the exact same code without having to call the entire beforeFilter method from the base class. That way you do not have to work around all the edge cases without having to reinvent the same code in multiple locations.pull/5187/head
parent
9edffd01ba
commit
3cbc36af4e
|
@ -287,21 +287,7 @@ class AppController extends Controller
|
|||
throw new ForbiddenException('Authentication failed. Please make sure you pass the API key of an API enabled user along in the Authorization header.');
|
||||
}
|
||||
} elseif (!$this->Session->read(AuthComponent::$sessionKey)) {
|
||||
// load authentication plugins from Configure::read('Security.auth')
|
||||
$auth = Configure::read('Security.auth');
|
||||
if ($auth) {
|
||||
$this->Auth->authenticate = array_merge($auth, $this->Auth->authenticate);
|
||||
if ($this->Auth->startup($this)) {
|
||||
$user = $this->Auth->user();
|
||||
if ($user) {
|
||||
// User found in the db, add the user info to the session
|
||||
$this->Session->renew();
|
||||
$this->Session->write(AuthComponent::$sessionKey, $user);
|
||||
}
|
||||
unset($user);
|
||||
}
|
||||
}
|
||||
unset($auth);
|
||||
$this->_loadAuthenticationPlugins();
|
||||
}
|
||||
}
|
||||
$this->set('externalAuthUser', $userLoggedIn);
|
||||
|
@ -1033,4 +1019,22 @@ class AppController extends Controller
|
|||
$targetRoute['admin'] = false;
|
||||
$this->redirect($targetRoute);
|
||||
}
|
||||
|
||||
protected function _loadAuthenticationPlugins() {
|
||||
// load authentication plugins from Configure::read('Security.auth')
|
||||
$auth = Configure::read('Security.auth');
|
||||
|
||||
if (!$auth) return;
|
||||
|
||||
$this->Auth->authenticate = array_merge($auth, $this->Auth->authenticate);
|
||||
if ($this->Auth->startup($this)) {
|
||||
$user = $this->Auth->user();
|
||||
if ($user) {
|
||||
// User found in the db, add the user info to the session
|
||||
$this->Session->renew();
|
||||
$this->Session->write(AuthComponent::$sessionKey, $user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue