A
A
Alexander2021-08-03 09:19:49
symfony
Alexander, 2021-08-03 09:19:49

New authentication system no longer redirects?

I am moving the project to the latest version, I read that now there is a new authentication system. I have this configuration:

<?php

use App\Entity\User;
use App\Security\LoginAuthenticator;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Config\SecurityConfig;

return static function (SecurityConfig $security) {
    $security->enableAuthenticatorManager(true);

    $security->provider('app_user_provider')
        ->entity()
            ->class(User::class)
            ->property('login');

    $security->passwordHasher(User::class)
        ->algorithm('bcrypt')
        ->cost(12);

    $security->firewall('dev')
        ->pattern('^/(_(profiler|wdt)|css|images|js)/')
        ->security(false);

    $security->firewall('main')
        ->lazy(true)
        ->customAuthenticators([LoginAuthenticator::class])
        ->logout()
            ->path('logout')
            ->target('login');

    $security->accessControl()->path('^/login')->roles([AuthenticatedVoter::PUBLIC_ACCESS]);
    $security->accessControl()->path('^/')->roles(['ROLE_USER']);
};


The entire site is supposed to be closed to unauthorized users. But the redirect is gone.

That is, earlier, if the user is not authorized, then there was a redirect to the login form, but now the error is:

Full authentication is required to access this resource.


Question: maybe this is somehow solved through the settings or do I need to check and redirect it myself through the events?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-03
@alexrakirov

In general, I’m reading a book, I see a fig, I didn’t look well at what’s in FirewallConfig
In the firewall, add entryPointa class fromAuthenticationEntryPointInterface

$security->firewall('main')
        ->lazy(true)
        ->customAuthenticators([LoginAuthenticator::class])
        ->entryPoint(AuthenticationEntryPoint::class)
        ->logout()
            ->path('logout')
            ->target('login');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question