当前位置: 首页 > 知识库问答 >
问题:

Symfony 3.3在登录prod后未重定向-“页面未正确重定向”

马权
2023-03-14

安全性:编码器:AppBundle\Entity\Usuario:算法:bcrypt#https://symfony.com/doc/current/security.html#b-配置如何加载用户提供程序:db\U提供程序:实体:类:AppBundle:Usuario

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        anonymous: ~
        form_login:
              login_path: login
              check_path: login
              default_target_path: admin

        logout:
            path: logout
            target: index

        remember_me:
                    secret:   '%secret%'
                    lifetime: 604800 # 1 week in seconds
                    path:     /
access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONIMOUSLY }
    - { path: ^/admin, roles: IS_AUTHENTICATED_FULLY }

共有1个答案

汝天宇
2023-03-14
/**
 * @Route("/login", name="login")
 */
public function loginAction(AuthenticationUtils $authUtils)
{

    // get the login error if there is one
$error = $authUtils->getLastAuthenticationError();

// last username entered by the user
$lastUsername = $authUtils->getLastUsername();

    $msg = '';

    if ($error != null) {
        $msg = 'Login ou Senha Inválidos!';
    }

    return $this->render($this->urlPage.'index.html.twig', array(
        'errorMsg' => $msg,
    ));


}

/**
 * @Route("/admin", name="admin")
 */
public function adminAction(AuthorizationCheckerInterface $authChecker)
{

    $authChecker = $this->get('security.authorization_checker');

    if ($authChecker->isGranted('ROLE_USUARIO')) {
        return $this->redirectToRoute('principal');
    } else if ($authChecker->isGranted('ROLE_CLIENTE')){
        return $this->redirectToRoute('principal');
    } else {
        return $this->redirectToRoute('index');
    }

}
 类似资料:
  • 我有一个文件,带有一个,具有和字段,在上,它用

  • 我在laravel中遇到了一个用户登录的问题,我可以正确地登录用户,但是问题是,在用户登录后,他被重定向到login POST方法,而不是home,我已经将

  • 我使用jsf servlet并创建了自定义登录页面,使用了带有动作j_spring_security_check的表单,方法POST,使用了j_username和j_password。当我单击登录按钮时,我遇到的问题不是重定向到页面,而是在Chrome网络列中显示了带有302状态代码的post方法j_spring_security_check,我是否使用了Spring安全的正确方式? 登录。jsf

  • 记录器文件中的日志- org.springframework.Security.Access.event.loggerlistener-安全授权失败,原因是:org.springframework.Security.Access.accessdeniedexception:访问被拒绝;通过身份验证的主体:org.springframework.security.authentication.ano

  • 问题内容: 我正在做一个简单的论坛,由一系列论坛组成,每个论坛分别代表首页,主题,postitit,登录名和用户列表页面。在某些页面上,当用户未登录时会出现一个链接。 我想要实现的是在登录后触发重定向(在RequestDispatcher上使用forward()),以便浏览器返回到用户在单击登录链接之前所在的页面。为此,我看到了两种解决方案。 第一种解决方案是使用带有登录按钮的HTML 和一个不可

  • 我想在成功登录后为特定页面重定向用户。 我不希望用户在登录后导航到上次查看的页面。 我试过以下网址,但它显示我的错误。 错误: