PHP code example of neevalt / arena-auth-bundle
1. Go to this page and download the library: Download neevalt/arena-auth-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
neevalt / arena-auth-bundle example snippets
/* src/Security/MyCustomUserLoader.php */
namespace App\Security;
use Neevalt\ArenaAuthBundle\Security\User\ArenaAuthUserLoaderInterface;
use Neevalt\ArenaAuthBundle\Security\User\ArenaAuthUser;
use Psr\Log\LoggerInterface;
class MyCustomUserLoader implements ArenaAuthUserLoaderInterface
{
private $logger;
// On peut par exempler injecter le Logger ici.
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function loadUser(ArenaAuthUser $user): ArenaAuthUser
{
// vaut le paramètre is_client_rsa
if (ArenaAuthUser::DEFAULT_USERNAME !== $user->getUsername()) {
if ($user->isGroupeAppartenance('appli_admin')) {
$user->addRole('ROLE_ADMIN');
} elseif ($user->isGroupeAppartenance('appli_adsi')) {
$user->addRole('ROLE_ADSI');
}
} else {
$user->setRoles(['ROLE_VIEWER', 'ROLE_DEV']);
}
$uid = $user->getUsername();
$roles = implode(', ', $user->getRoles());
$this->logger->info("${uid} s'authentifie avec les rôles : [${roles}].");
return $user;
}
}