diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 367af25..9c1b866 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -4,7 +4,12 @@ security: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: - users_in_memory: { memory: null } + users_in_memory: + memory: + users: + user: { password: '123', roles: ['ROLE_ADMIN'] } + admin: { password: '123', roles: ['ROLE_SUPER_ADMIN'] } + firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ @@ -12,6 +17,9 @@ security: main: lazy: true provider: users_in_memory + custom_authenticator: App\Security\AdminPanelAuthenticator + form_login: + login_path: /admin/login # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall @@ -22,7 +30,8 @@ security: # Easy way to control access for large sections of your site # Note: Only the *first* access control that matches will be used access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } + - { path: ^/admin/login, roles: PUBLIC_ACCESS } + - { path: ^/admin, roles: ROLE_ADMIN } # - { path: ^/profile, roles: ROLE_USER } when@test: diff --git a/src/Controller/Admin/SecurityController.php b/src/Controller/Admin/SecurityController.php new file mode 100644 index 0000000..f00bed0 --- /dev/null +++ b/src/Controller/Admin/SecurityController.php @@ -0,0 +1,18 @@ +render('admin/login.html.twig'); + } +} \ No newline at end of file diff --git a/src/Security/AdminPanelAuthenticator.php b/src/Security/AdminPanelAuthenticator.php new file mode 100644 index 0000000..348843d --- /dev/null +++ b/src/Security/AdminPanelAuthenticator.php @@ -0,0 +1,45 @@ +getRequestUri(), '/admin'); + } + + public function authenticate(Request $request): Passport + { + throw new CustomUserMessageAuthenticationException(); + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return null; + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + { + return null; + } + + // public function start(Request $request, ?AuthenticationException $authException = null): Response + // { + // /* + // * If you would like this class to control what happens when an anonymous user accesses a + // * protected page (e.g. redirect to /login), uncomment this method and make this class + // * implement Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface. + // * + // * For more details, see https://symfony.com/doc/current/security/experimental_authenticators.html#configuring-the-authentication-entry-point + // */ + // } +} diff --git a/templates/admin/login.html.twig b/templates/admin/login.html.twig new file mode 100644 index 0000000..9384089 --- /dev/null +++ b/templates/admin/login.html.twig @@ -0,0 +1,18 @@ +{% extends 'base.html.twig' %} + +{% block body %} +
+

Login

+
+
+ + +
+
+ + +
+ +
+
+{% endblock %} \ No newline at end of file