public function onKernelRequest(GetResponseEvent $event)
    {
        // checks if the backend is secured
        $token = $this->securityContext->getToken();
        if (null !== $token) {

            // Check if the user has already been logged in
            $user = $token->getUser();
            if (null !== $user) {
                $errorMessage = '';
                $userId = $user->getId();

                // Frees the expired locked resources and the resource previously locked
                // by the user
                try {
                    $this->resourcesLocker->unlockExpiredResources();
                    $this->resourcesLocker->unlockUserResource($userId);
                } catch (\PropelException $ex) {
                    $errorMessage = $ex->getMessage();
                }

                if ($errorMessage == '') {
                    $request = $event->getRequest();

                    // LOcks the resource
                    $locked = $request->get('locked');
                    if (null !== $locked) {
                        try {
                            // Process composite locking rules
                            $rules = explode(',', $locked);
                            if (isset($rules[1])) {
                                $locked = $rules[0];
                                $param = $request->get($rules[1]);
                            } else {
                                $param = $request->get($locked);
                            }

                            $key = ('locked' !== $locked) ? $locked . "=" . $param : $request->getUri() . '/locked';
                            $this->resourcesLocker->lockResource($userId, md5($key));
                        } catch (\PropelException $ex) {
                            $errorMessage = 'exception_resource_was_free_but_someone_locked_it';
                        }
                    }
                }

                // The resource is not free, stops the request
                if ($errorMessage != '') {
                    throw new ResourceNotFreeException($errorMessage);
                }
            }
        }
    }