我的 security.yml 如下:
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),
));
}
在本地主机上它可以正常工作。在正确的凭据后再次显示生产服务器登录页面。我检查了数据库连接是否正常工作。问题是 isGranted('IS_AUTHENTICATED_FULLY') 返回 false。如果我使用它没有帮助
<input type="hidden" name="_target_path" value="/menu" />
在 login.html.twig 中。有人可以指出我解决问题的正确方向吗?