app ldap connect
This commit is contained in:
@ -102,13 +102,13 @@ class HydraController extends AbstractController
|
||||
|
||||
// S'il n'y a pas de challenge, on déclenche une bad request
|
||||
if (!$challenge) {
|
||||
return $this->redirect('app_login');
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
// On vérifie que la requête d'identification provient bien de hydra
|
||||
$response = $this->apiservice->run('GET', $this->getParameter('hydraLoginchallenge').$challenge, null);
|
||||
if (!$response) {
|
||||
return $this->redirect('app_login');
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
// si le challenge est validé par hydra, on le stocke en session pour l'utiliser par la suite et on redirige vers une route interne protégée qui va déclencher l'identification FranceConnect
|
||||
@ -148,6 +148,7 @@ class HydraController extends AbstractController
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = ' ';
|
||||
$firstname = 'noavatar.png';
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if (isset($userldap[$this->getParameter('ldapFirstname')])) {
|
||||
@ -162,9 +163,13 @@ class HydraController extends AbstractController
|
||||
$email = $userldap[$this->getParameter('ldapEmail')];
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapAvatar')])) {
|
||||
$avatar = $userldap[$this->getParameter('ldapAvatar')];
|
||||
}
|
||||
|
||||
$response = $this->apiservice->run('PUT', $this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'), ['subject' => $email, 'acr' => 'string']);
|
||||
if (!$response || '200' != $response->code) {
|
||||
return $this->redirect('app_login');
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
$datas = [
|
||||
|
107
src/DataFixtures/AppFixtures.php
Normal file
107
src/DataFixtures/AppFixtures.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Service\LdapService;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class AppFixtures extends Fixture
|
||||
{
|
||||
private $kernel;
|
||||
private $output;
|
||||
private $minio;
|
||||
private $colorbg;
|
||||
private $colorft;
|
||||
private $ldap;
|
||||
private $manager;
|
||||
|
||||
public function __construct(KernelInterface $kernel, LdapService $ldapservice)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->ldap = $ldapservice;
|
||||
$this->output = new ConsoleOutput();
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
$this->manager = $manager;
|
||||
|
||||
// Reset autoincrement
|
||||
|
||||
// app:Init
|
||||
$this->writeln('app:Init');
|
||||
$application = new Application($this->kernel);
|
||||
$application->setAutoExit(false);
|
||||
$input = new ArrayInput(['command' => 'app:Init']);
|
||||
$boutput = new BufferedOutput();
|
||||
$application->run($input, $boutput);
|
||||
$manager->flush();
|
||||
|
||||
$this->writeln('LDAP');
|
||||
$baseorganisation = $this->ldap->getParameter('basedn');
|
||||
|
||||
// Purge de la strucutre annuaire
|
||||
$this->ldap->deleteByDN('ou=crous01,'.$baseorganisation, true);
|
||||
$this->ldap->deleteByDN('ou=crous02,'.$baseorganisation, true);
|
||||
|
||||
// Création de la structure
|
||||
$this->ldap->addOrganisation('ou=crous01,'.$baseorganisation);
|
||||
$this->ldap->addOrganisation('ou=users,ou=crous01,'.$baseorganisation);
|
||||
$this->ldap->addOrganisation('ou=crous02,'.$baseorganisation);
|
||||
$this->ldap->addOrganisation('ou=users,ou=crous02,'.$baseorganisation);
|
||||
|
||||
// Création user
|
||||
$this->submitUser('admin','NUO SSO','Administrateur','uid=admin,ou=users,ou=crous01,'.$baseorganisation);
|
||||
$this->submitUser('user001','001','User','uid=user001,ou=users,ou=crous01,'.$baseorganisation);
|
||||
$this->submitUser('user002','002','User','uid=user002,ou=users,ou=crous02,'.$baseorganisation);
|
||||
}
|
||||
|
||||
|
||||
private function submituser($username,$firstname,$lastname,$dn)
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUsername($username);
|
||||
$user->setPassword($username);
|
||||
$user->setRoles(['ROLE_USER']);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setLastname($lastname);
|
||||
$user->setEmail($username.'@noreply.fr');
|
||||
|
||||
$this->ldap->fixtureUser($user,$dn);
|
||||
|
||||
}
|
||||
|
||||
private function writeln($string)
|
||||
{
|
||||
$this->output->writeln(' <fg=yellow>></> <info>'.$string.'</info>');
|
||||
}
|
||||
|
||||
private function csv_to_array($csv, $delimiter = ';', $enclosure = '', $escape = '\\', $terminator = "\n")
|
||||
{
|
||||
$r = [];
|
||||
$rows = explode($terminator, trim($csv));
|
||||
|
||||
$names = array_shift($rows);
|
||||
$names = str_getcsv($names, $delimiter, $enclosure, $escape);
|
||||
$nc = count($names);
|
||||
foreach ($rows as $row) {
|
||||
if (trim($row)) {
|
||||
$values = str_getcsv($row, $delimiter, $enclosure, $escape);
|
||||
if (!$values) {
|
||||
$values = array_fill(0, $nc, null);
|
||||
}
|
||||
@$r[] = array_combine($names, $values);
|
||||
}
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
}
|
@ -347,6 +347,28 @@ class LdapService
|
||||
// == Function User==================================================================================================================================================
|
||||
// ==================================================================================================================================================================
|
||||
|
||||
public function fixtureUser(User $user,$dn)
|
||||
{
|
||||
$connection = $this->connect();
|
||||
|
||||
$attrs = [];
|
||||
$attrs['objectclass'] = $this->getObjectClassesUser();
|
||||
$this->fillAttributesUser($user, $attrs);
|
||||
|
||||
foreach ($attrs as $key => $value) {
|
||||
if (empty($value)) {
|
||||
unset($attrs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$result = ldap_add($connection, $dn, $attrs);
|
||||
if (!$result) {
|
||||
$this->ldapError();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function addUser(User $user)
|
||||
{
|
||||
$connection = $this->connect();
|
||||
@ -643,8 +665,6 @@ class LdapService
|
||||
$attrs['sn'] = $user->getLastname();
|
||||
$attrs['mail'] = $user->getEmail();
|
||||
$attrs['displayname'] = $user->getFirstname().' '.$user->getLastname();
|
||||
$attrs['telephonenumber'] = $user->getTelephonenumber();
|
||||
$attrs['postaladdress'] = $user->getPostaladress();
|
||||
$attrs['userpassword'] = $user->getPassword();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user