Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\ISession;
use OCP\IUserSession;
use OCP\User\Backend\IPasswordConfirmationBackend;
use Psr\Log\LoggerInterface;

class PasswordConfirmationMiddleware extends Middleware {
/** @var ControllerMethodReflector */
Expand All @@ -41,25 +42,21 @@ class PasswordConfirmationMiddleware extends Middleware {
private $userSession;
/** @var ITimeFactory */
private $timeFactory;
/** @var LoggerInterface */
private $logger;
/** @var array */
private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true];

/**
* PasswordConfirmationMiddleware constructor.
*
* @param ControllerMethodReflector $reflector
* @param ISession $session
* @param IUserSession $userSession
* @param ITimeFactory $timeFactory
*/
public function __construct(ControllerMethodReflector $reflector,
ISession $session,
IUserSession $userSession,
ITimeFactory $timeFactory) {
ITimeFactory $timeFactory,
LoggerInterface $logger) {
$this->reflector = $reflector;
$this->session = $session;
$this->userSession = $userSession;
$this->timeFactory = $timeFactory;
$this->logger = $logger;
}

/**
Expand All @@ -85,6 +82,11 @@ public function beforeController($controller, $methodName) {
$lastConfirm = (int) $this->session->get('last-password-confirm');
// we can't check the password against a SAML backend, so skip password confirmation in this case
if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay
$this->logger->warning("User {uid} on backend {backendclass} requires password confirmation for {method}", [
"uid" => $user->getUID(),
"backendclass" => $backendClassName,
"method" => $controller::class . '::' . $methodName,
]);
throw new NotConfirmedException();
}
}
Expand Down