Symfony4 安全问题

Symfony4 security issue

我尝试使用通过 webapp 创建或注册的用户创建一个简单的登录表单。

这是我的 security.yml 文件

security:

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern:    ^/
            http_basic: ~
            provider: our_db_provider
    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

    encoders:
        App\Project\UserBundle\Entity\Users:
        algorithm: bcrypt

    providers:
        our_db_provider:
            entity:
                class: App\Project\UserBundle\Entity\Users:
                property: username

如果我访问像 /nl/admin/.. 这样的页面,即使我没有登录也可以访问该页面。 访问控制失败?

即使当我尝试登录时,我得到的凭据无效..但凭据是正确的..

这是我的控制器

namespace App\Project\UserBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class LoginController extends Controller
{

    public function loginAction(Request $request, AuthenticationUtils $authenticationUtils)
    {

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

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

        return $this->render('@ProjectUser/frontend/login/login.html.twig', array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ));
    }
}

我错过了什么?

您必须 "regexify" access_control 路径中的 _locale URI 路径,具体取决于它们的定义方式。对于仅包含 2 个字母的语言环境,您可以将 access_control 编写如下:

access_control:
    - { path: ^/[a-z]{2}/admin/, role: ROLE_ADMIN }

或者,如果您想列出它们,可以是:

access_control:
    - { path: ^/(en|nl|de)/admin/, role: ROLE_ADMIN }

access_control路径是纯字符串模式,不考虑路由参数...