mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX: Removed unnecessary database_is_ready call.
This shaves about 45ms from every request (PHP 7.1 on a 2013 rMBP), cutting down execution time of a “hello world” controller by about 33%. database_is_ready is still used in dev/build and ?flush=1 to stop people from people bypassing security by DOSing the database or otherwise forcing a DatabaseException
This commit is contained in:
parent
85f4a41c67
commit
8c15e451c6
@ -7,6 +7,7 @@ use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\Middleware\HTTPMiddleware;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\ORM\ValidationException;
|
||||
use SilverStripe\ORM\Connect\DatabaseException;
|
||||
|
||||
class AuthenticationMiddleware implements HTTPMiddleware
|
||||
{
|
||||
@ -44,7 +45,6 @@ class AuthenticationMiddleware implements HTTPMiddleware
|
||||
*/
|
||||
public function process(HTTPRequest $request, callable $delegate)
|
||||
{
|
||||
if (Security::database_is_ready()) {
|
||||
try {
|
||||
$this
|
||||
->getAuthenticationHandler()
|
||||
@ -54,7 +54,8 @@ class AuthenticationMiddleware implements HTTPMiddleware
|
||||
"Bad log-in details: " . $e->getMessage(),
|
||||
400
|
||||
);
|
||||
}
|
||||
} catch (DatabaseException $e) {
|
||||
// Database isn't ready, carry on.
|
||||
}
|
||||
|
||||
return $delegate($request);
|
||||
|
@ -10,6 +10,7 @@ use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
|
||||
use SilverStripe\ORM\Connect\DatabaseException;
|
||||
|
||||
/**
|
||||
* Provides an interface to HTTP basic authentication.
|
||||
@ -72,7 +73,7 @@ class BasicAuth
|
||||
$permissionCode = null,
|
||||
$tryUsingSessionLogin = true
|
||||
) {
|
||||
if (!Security::database_is_ready() || (Director::is_cli() && static::config()->get('ignore_cli'))) {
|
||||
if ((Director::is_cli() && static::config()->get('ignore_cli'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,6 +95,7 @@ class BasicAuth
|
||||
|
||||
$member = null;
|
||||
|
||||
try {
|
||||
if ($request->getHeader('PHP_AUTH_USER') && $request->getHeader('PHP_AUTH_PW')) {
|
||||
/** @var MemberAuthenticator $authenticator */
|
||||
$authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::LOGIN);
|
||||
@ -108,6 +110,10 @@ class BasicAuth
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DatabaseException $e) {
|
||||
// Database isn't ready, let people in
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($member instanceof Member) {
|
||||
Security::setCurrentUser($member);
|
||||
|
@ -107,8 +107,7 @@ class CookieAuthenticationHandler implements AuthenticationHandler
|
||||
$uidAndToken = Cookie::get($this->getTokenCookieName());
|
||||
$deviceID = Cookie::get($this->getDeviceCookieName());
|
||||
|
||||
// @todo Consider better placement of database_is_ready test
|
||||
if ($deviceID === null || strpos($uidAndToken, ':') === false || !Security::database_is_ready()) {
|
||||
if ($deviceID === null || strpos($uidAndToken, ':') === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user