Skip to content

Instantly share code, notes, and snippets.

@wizhippo
Created May 29, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizhippo/06f480a44ff8d114852385b478eee726 to your computer and use it in GitHub Desktop.
Save wizhippo/06f480a44ff8d114852385b478eee726 to your computer and use it in GitHub Desktop.
<?php
namespace App\EventListener;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\Core\MVC\Symfony\Event\InteractiveLoginEvent;
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class InteractiveLoginListener implements EventSubscriberInterface
{
/**
* @var \eZ\Publish\API\Repository\Repository
*/
private $repository;
public function __construct(Repository $repository)
{
$this->repository = $repository;
}
public static function getSubscribedEvents()
{
return [
MVCEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];
}
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
$userService = $this->repository->getUserService();
try {
$user = $userService->loadUser(14);
$event->setApiUser($user);
} catch (NotFoundException $e) {
// Do nothing
}
}
}
#security:
# # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
# providers:
# in_memory: { memory: ~ }
# firewalls:
# dev:
# pattern: ^/(_(profiler|wdt)|css|images|js)/
# security: false
# main:
# anonymous: true
#
# # activate different ways to authenticate
#
# # http_basic: true
# # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#
# # form_login: true
# # https://symfony.com/doc/current/security/form_login_setup.html
#
# # 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: ^/profile, roles: ROLE_USER }
#
# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
encoders:
# this internal class is used by Symfony to represent in-memory users
Symfony\Component\Security\Core\User\User: 'auto'
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
ezplatform:
id: ezpublish.security.user_provider
in_memory:
memory:
users:
admin: { password: '$argon2id$v=19$m=65536,t=4,p=1$OyjIkSeGnUPk6bzvjDgB9w$8Y1v/H5KF6itNKSwczhp7goLL8NfhlIDeXGdIpPGN0o', roles: ['ROLE_ADMIN'] }
all_users:
chain:
providers: ['in_memory', 'ezplatform']
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
ezpublish_forgot_password:
pattern: /user/(forgot-password|reset-password)
security: false
ezpublish_front:
pattern: ^/
provider: all_users
user_checker: eZ\Publish\Core\MVC\Symfony\Security\UserChecker
anonymous: ~
ezpublish_rest_session: ~
form_login:
require_previous_session: false
csrf_token_generator: security.csrf.token_manager
logout: ~
main:
anonymous: ~
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#http_basic: ~
# https://symfony.com/doc/current/security/form_login_setup.html
#form_login: ~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment