php 使用 Symfony 框架在生产服务器上的用户登录失败(无法处理身份验证请求,因为...)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31519901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)
提问by Charalampos Hadjiantoniou
I'am using Symfony for a project and I have been trying to get the login to work on production server with no success for the past 2 days. I keep getting the error
我正在将 Symfony 用于一个项目,并且过去 2 天我一直试图让登录名在生产服务器上工作但没有成功。我不断收到错误
Authentication request could not be processed due to a system problem.
由于系统问题,无法处理身份验证请求。
I have followed the guide here (http://symfony.com/doc/current/cookbook/security/entity_provider.html) to setup loading users from database.
我已经按照这里的指南(http://symfony.com/doc/current/cookbook/security/entity_provider.html)设置从数据库加载用户。
My security.ymlfile:
我的security.yml文件:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Acceptme\UserBundle\Entity\User: plaintext
role_hierarchy:
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
patricia:
password: patricia
roles: 'ROLE_ADMIN'
users:
name: user_provider
entity: { class: AcceptmeUserBundle:User, property: username }
firewalls:
user_area:
pattern: ^/
anonymous: ~
provider: user_provider
form_login:
login_path: login_route
check_path: _login_check
default_target_path: homepage
dev:
pattern: ^/(_(profiler|wdt|error)|css|images|js)/
security: false
default:
anonymous: ~
http_basic: ~
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
My SecurityController.php:
我的SecurityController.php:
namespace AppBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Security\Core\SecurityContext;
class SecurityController extends Controller
{
/**
* @Route("/login", name="login_route")
* @Template("security/login.html.twig")
*/
public function loginAction(Request $request)
{
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return array(
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
'error' => $error,
);
}
/**
* @Route("/login_check", name="_login_check")
*/
public function securityCheckAction()
{
// this controller will not be executed,
// as the route is handled by the Security system
}
}
I have tried uploading the project on 2 different web hosts (FatCow & GoDaddy) and the problem remains. Locally i am using PHP 5.4.19 (FatCow uses 5.3.2 and GoDaddy uses 5.4.37). Keep in mind that when working on localhost with XAMPP everything works fine!
我尝试在 2 个不同的网络主机(FatCow 和 GoDaddy)上上传项目,但问题仍然存在。我在本地使用 PHP 5.4.19(FatCow 使用 5.3.2,GoDaddy 使用 5.4.37)。请记住,使用 XAMPP 在本地主机上工作时一切正常!
I've confirmed that PDO is enabled in both cases. I've confirmed that the database username, password and host are correct in the parameters.ymlfile. Error logs on both local and remote servers show nothing.
我已经确认在这两种情况下都启用了 PDO。我已经确认parameters.yml文件中的数据库用户名、密码和主机是正确的。本地和远程服务器上的错误日志均未显示任何内容。
I have followed all directions from this previous post Deploying Symfony2 app getting fosuserbundle errorsand still no success.
我已经按照上一篇文章部署 Symfony2 应用程序获取 fosuserbundle 错误中的所有说明进行操作,但仍然没有成功。
I appreciate all the help in advance.
我提前感谢所有帮助。
采纳答案by Charalampos Hadjiantoniou
UPDATE: Issue solved. The issue was that a table in the entity php file was named with upper case letters while the database table was named with lower case. +1 to ClémentBERTILLON for pointing in the right direction, namely prod.log
更新:问题已解决。问题是实体php文件中的表以大写字母命名,而数据库表以小写字母命名。+1 给 ClémentBERTILLON 指出正确的方向,即 prod.log
回答by Francesco Borzi
It looks like that the error:
看起来是这样的错误:
Authentication request could not be processed due to a system problem.
由于系统问题,无法处理身份验证请求。
is too generic and does not tell anything about where the problem is (there is an issue opened about this matter here).
太普通了,不告诉是哪里的问题(有打开这件事情的任何问题,在这里)。
I solved my issue by checking the logs and see what happened (in var/logs/dev.log
), hoping this helps someone.
我通过检查日志并查看发生了什么(在 中var/logs/dev.log
)解决了我的问题,希望这对某人有所帮助。
In my specific case, there was a wrong parameter in parameters.yml about database connection. But, again, the error is too generic and does not necessarily imply that the problem is related with database connection.
在我的具体情况下,parameters.yml 中有一个关于数据库连接的错误参数。但是,同样,该错误过于笼统,并不一定意味着问题与数据库连接有关。
回答by Luis Jimenez
This problem can be fixed running command: php bin/console cache:clear --env=prod --no-debug
这个问题可以通过运行命令来修复: php bin/console cache:clear --env=prod --no-debug
回答by Paul Leclerc
AS @ShinDarth mention it. It is too generic and log inspection will help people in our case to get throught this.
AS @ShinDarth 提到它。这太笼统了,日志检查将帮助我们案例中的人解决这个问题。
If it can help in my situation it was :
如果它可以帮助我的情况是:
After an SonataUserBundle installation in SF3, I had to
在 SF3 中安装 SonataUserBundle 后,我不得不
bin/console doctrine:schema:update --force
My context is particular, I have had already installed and used FOSUserBundle before to install SonataUserBundle. (Because of SF3 compatibility with FOSUser/SonataUSer... Database have been taken 16 queries after that. Working great.
我的上下文很特别,我之前已经安装并使用过 FOSUserBundle 来安装 SonataUserBundle。(因为 SF3 与 FOSUser/SonataUSer 兼容......此后数据库进行了 16 次查询。运行良好。
回答by Yuchen BAI
I'm sure that this error is too generic. In my case, The follow is incorrect:
我确信这个错误太笼统了。就我而言,以下是不正确的:
class: App/Entity/User;
Correction:
更正:
class: App\Entity\User;
回答by pdchaudhary
In my case, I changed user entity and then I forgot to update table.
就我而言,我更改了用户实体,然后忘记更新表。
for table update:
表更新:
php bin/console doctrine:schema:update --force
回答by juanitourquiza
This solution is correct for me: https://stackoverflow.com/a/39782535/2400373
这个解决方案对我来说是正确的:https: //stackoverflow.com/a/39782535/2400373
But If you do not have access to the terminal, you can enter the server and delete the folders that are inside var/cache
.
但是,如果您无法访问终端,则可以进入服务器并删除其中的文件夹var/cache
。
Another solution if you have access to the console is to type
如果您有权访问控制台,另一种解决方案是键入
#rm -rf var/cache/*
or
或者
$sudo rm -rf var/cache/*
this solution works on symfony 3
此解决方案适用于 symfony 3
回答by CappY
Currently there is a bug in Symfony and on production IF during authentication system error occurs (missing table, missing column or any other exception) - it's logged as INFO instead of ERROR and with default error logging options it's not logged at all.
目前在 Symfony 和生产 IF 中存在一个错误,在身份验证系统错误发生期间(缺少表、缺少列或任何其他异常) - 它被记录为 INFO 而不是 ERROR 并且使用默认错误日志记录选项根本没有记录它。
https://github.com/symfony/symfony/pull/28462
https://github.com/symfony/symfony/pull/28462
I think there are two options right now - temporary log everything (including INFO) on production until you find the real error.
我认为现在有两个选择 - 在生产中临时记录所有内容(包括 INFO),直到找到真正的错误。
Second option: use this patch or debug directly on production.
第二种选择:使用此补丁或直接在生产中调试。
回答by gogaz
You probably used the template given by Symfony docs here:
您可能在这里使用了 Symfony 文档提供的模板:
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
Which actually gives you this error message. The most simple and reliable way to fix this issue is to replace this line by the following :
这实际上给了你这个错误信息。解决此问题的最简单可靠的方法是将这一行替换为以下内容:
<div class="alert alert-danger">{{ error }}</div>
Which will give you the full stack-trace for your error and (hopefully) help you debug your application. Don't forget to revert this before going to production!
这将为您提供错误的完整堆栈跟踪,并(希望)帮助您调试应用程序。不要忘记在开始生产之前恢复它!
回答by Sanjok Gurung
In my case the issue was fixed by correcting a typo in connection details in the .env
file.
就我而言,问题是通过更正.env
文件中连接详细信息中的拼写错误来解决的。