我security.yml如下:的symfony 2,后不能完全验证的登录
jms_security_extra:
secure_all_services: false
expressions: true
security:
encoders:
Taden\MainBundle\Entity\Employee:
algorithm: sha512
iterations: 2
encode_as_base64: true
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
entity: { class: Taden\MainBundle\Entity\Employee, property: code }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/login$
anonymous: ~
secured_area:
pattern: ^/
form_login: ~
logout:
path: /logout
target: /login
http_basic: ~
anonymous: ~
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/, roles: ROLE_USER }
我在loginAction()如下:
public function loginAction()
{
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
{
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
}
else
{
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
if ($error != null)
{
$error_message = $this->get('translator')->trans($error->getMessage());
$this->get('session')->getFlashBag()->add('error', $error_message);
}
if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY'))
{
return $this->redirect($this->generateUrl('menu'));
}
else
{
$this->get('session')->getFlashBag()->add('error', 'not logged in');
}
return $this->render('TadenMainBundle:Default:login.html.twig', array(
'company_name' => '',
'department_name' => '',
'user_name' => '',
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
));
}
localhost上它的工作原理没有问题。在生产服务器登录页面在正确凭证后再次显示 。我检查了数据库连接没有问题。问题是isGranted('IS_AUTHENTICATED_FULLY')返回false。 如果我使用
<input type="hidden" name="_target_path" value="/menu" />
in login.html.twig。有人能指出我解决问题的正确方向吗?
如果开发版工作,督促一个没有,我会点自己DB问题。 – DonCallisto
它按预期工作,如果我把数据库访问代码放入loginAction()并设置flash消息;所以我很确定这不是数据库问题。 – synergetic
synergetic:我的意思是,是相同的分贝?这个数据库仍然填充你的原始记录?我从来没有听说过这样的问题 – DonCallisto