use BookStack\Auth\Access\SocialAuthService;
use BookStack\Exceptions\LoginAttemptEmailNeededException;
use BookStack\Exceptions\LoginAttemptException;
+use BookStack\Exceptions\UserRegistrationException;
use BookStack\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
*/
public function __construct(SocialAuthService $socialAuthService)
{
- $this->middleware('guest', ['only' => ['getLogin', 'postLogin']]);
+ $this->middleware('guest', ['only' => ['getLogin', 'login']]);
+ $this->middleware('guard:standard,ldap', ['only' => ['login', 'logout']]);
+
$this->socialAuthService = $socialAuthService;
$this->redirectPath = url('/');
$this->redirectAfterLogout = url('/login');
{
$socialDrivers = $this->socialAuthService->getActiveDrivers();
$authMethod = config('auth.method');
- $samlEnabled = config('saml2.enabled') === true;
if ($request->has('email')) {
session()->flashInput([
return view('auth.login', [
'socialDrivers' => $socialDrivers,
'authMethod' => $authMethod,
- 'samlEnabled' => $samlEnabled,
]);
}
$this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
+ // Also log some error message
+ $this->logFailedAccess($request);
+
return $this->sendLockoutResponse($request);
}
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
+ // Also log some error message
+ $this->logFailedAccess($request);
+
return $this->sendFailedLoginResponse($request);
}
*/
protected function validateLogin(Request $request)
{
- $rules = [];
+ $rules = ['password' => 'required|string'];
$authMethod = config('auth.method');
if ($authMethod === 'standard') {
- $rules = [
- 'email' => 'required|string|email',
- 'password' => 'required|string'
- ];
+ $rules['email'] = 'required|email';
}
if ($authMethod === 'ldap') {
- $rules = [
- 'username' => 'required|string',
- 'password' => 'required|string',
- 'email' => 'email',
- ];
- }
-
- if ($authMethod === 'saml2') {
- $rules = [
- 'email' => 'email',
- ];
+ $rules['username'] = 'required|string';
+ $rules['email'] = 'email';
}
$request->validate($rules);
}
/**
- * Log the user out of the application.
+ * Log failed accesses, matching the default fail2ban nginx/apache auth rules.
*/
- public function logout(Request $request)
+ protected function logFailedAccess(Request $request)
{
- if (config('saml2.enabled') && session()->get('last_login_type') === 'saml2') {
- return redirect('/saml2/logout');
- }
-
- $this->guard()->logout();
- $request->session()->invalidate();
-
- return $this->loggedOut($request) ?: redirect('/');
+ if (isset($_SERVER['SERVER_SOFTWARE']) && preg_match('/nginx/i', $_SERVER['SERVER_SOFTWARE'])) {
+ error_log('user "' . $request->get($this->username()) . '" was not found in "BookStack"', 4);
+ } else {
+ error_log('user "' . $request->get($this->username()) . '" authentication failure for "BookStack"', 4);
+ }
}
+
}