gpt4 book ai didi

security - symfony 2,登录后未完全验证

转载 作者:行者123 更新时间:2023-12-02 05:03:15 24 4
gpt4 key购买 nike

我的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 中。有人可以指出我解决问题的正确方向吗?

最佳答案

在 Symfony 2 中,当您的用户拥有与其自身关联的角色(至少一个)时,您就获得了完全的身份验证。

尝试为您的用户添加一个角色,您应该会在调试栏中看到您已使用您为用户提供的角色进行了完全身份验证(然后“IS_AUTHENTICATED_FULLY”应该为真)。

关于security - symfony 2,登录后未完全验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16683658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com