Skip to content

Commit

Permalink
Adapter le modèle Agent aux données de ProConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelemee committed Jan 20, 2025
1 parent f1e3686 commit 6543eec
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 514 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:

MonIndemnisationJustice\Security\Authenticator\ProConnectAuthenticator:
arguments:
$loginPageRoute: 'agent_securite_se_connecter'
$loginCheckRoute: 'agent_securite_connexion'
$loginSuccessRoute: 'agent_index'

Expand Down
60 changes: 60 additions & 0 deletions migrations/Version20250120101221.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250120101221 extends AbstractMigration
{
public function getDescription(): string
{
return 'Mise à jour de la table `agents` pour intégrer les données issues de ProConnect (OIDC)';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE dossier_etats DROP CONSTRAINT FK_71671FCF3414710B');
$this->addSql('ALTER TABLE dossier_etats ADD CONSTRAINT FK_71671FCF3414710B FOREIGN KEY (agent_id) REFERENCES agents (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX sessions_sess_lifetime_idx RENAME TO sess_lifetime_idx');
// Le changement pour ProConnect étant irréversible, on doit supprimer les comptes existants
$this->addSql('DELETE FROM agents');
$this->addSql('DROP INDEX uniq_agent_email');
$this->addSql('ALTER TABLE agents ADD identifiant VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE agents ADD uid VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE agents ADD fournisseur_identite VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE agents ADD categorie_agent VARCHAR(255)');
$this->addSql('ALTER TABLE agents ADD donnes_authentification TEXT');
$this->addSql('ALTER TABLE agents ADD est_valide BOOLEAN DEFAULT false NOT NULL');
$this->addSql('ALTER TABLE agents DROP mot_de_passe');
$this->addSql('ALTER TABLE agents DROP date_changement_mdp');
$this->addSql('ALTER TABLE agents DROP est_actif');
$this->addSql('ALTER TABLE agents DROP jeton_verification');
$this->addSql('COMMENT ON COLUMN agents.donnes_authentification IS \'(DC2Type:simple_array)\'');
$this->addSql('CREATE UNIQUE INDEX uniq_agent_identifiant ON agents (identifiant)');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER INDEX sess_lifetime_idx RENAME TO sessions_sess_lifetime_idx');
$this->addSql('ALTER TABLE dossier_etats DROP CONSTRAINT fk_71671fcf3414710b');
$this->addSql('ALTER TABLE dossier_etats ADD CONSTRAINT fk_71671fcf3414710b FOREIGN KEY (agent_id) REFERENCES agents (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('DROP INDEX uniq_agent_identifiant');
$this->addSql('ALTER TABLE agents ADD mot_de_passe VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE agents ADD date_changement_mdp DATE DEFAULT NULL');
$this->addSql('ALTER TABLE agents ADD est_actif BOOLEAN DEFAULT true NOT NULL');
$this->addSql('ALTER TABLE agents ADD jeton_verification VARCHAR(12) DEFAULT NULL');
$this->addSql('ALTER TABLE agents DROP identifiant');
$this->addSql('ALTER TABLE agents DROP uid');
$this->addSql('ALTER TABLE agents DROP organisation');
$this->addSql('ALTER TABLE agents DROP categorie_agent');
$this->addSql('ALTER TABLE agents DROP donnes_authentification');
$this->addSql('ALTER TABLE agents DROP est_valide');
$this->addSql('CREATE UNIQUE INDEX uniq_agent_email ON agents (email)');
}
}
75 changes: 0 additions & 75 deletions src/Command/CreateAgentCommand.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Contracts/EntityInterface.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Contracts/VoterInterface.php

This file was deleted.

55 changes: 3 additions & 52 deletions src/Controller/Agent/SecurityAgentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

namespace MonIndemnisationJustice\Controller\Agent;

use MonIndemnisationJustice\Dto\ModificationMotDePasse;
use MonIndemnisationJustice\Entity\Agent;
use MonIndemnisationJustice\Forms\ModificationMotDePasseType;
use MonIndemnisationJustice\Repository\AgentRepository;
use MonIndemnisationJustice\Security\Oidc\OidcClient;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
Expand Down Expand Up @@ -44,11 +41,12 @@ public function seConnecter(Request $request): Response
return $this->render('agent/connexion.html.twig', [
'title' => "Connexion à l'espace agent",
'last_username' => $this->authenticationUtils->getLastUsername(),
'error' => $this->authenticationUtils->getLastAuthenticationError(),
'error' => 'proconnect' === $request->query->get('erreur') ?
'Une erreur est survenue pendant la connexion avec ProConnect, veuillez ré-essayer' :
$this->authenticationUtils->getLastAuthenticationError(),
]);
}


#[Route('/connexion', name: 'agent_securite_connexion', methods: ['GET'])]
#[IsGranted('PUBLIC_ACCESS')]
public function connexion(Request $request): Response
Expand All @@ -65,51 +63,4 @@ public function logout(): void
{
throw new \LogicException("Impossible de déconnecter l'agent");
}

#[Route(path: '/activation/{jeton}', name: 'app_agent_securite_activation', methods: ['GET', 'POST'])]
public function activation(Request $request, string $jeton): Response
{
$agent = $this->agentRepository->findOneBy(['jetonVerification' => $jeton]);

if (null === $agent) {
return $this->redirectToRoute('agent_securite_se_connecter');
}

$modificationMotDePasse = new ModificationMotDePasse();

$form = $this->createForm(ModificationMotDePasseType::class, $modificationMotDePasse);
$errors = [];

if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$modificationMotDePasse = $form->getData();

$agent->setPassword(
$this->userPasswordHasher->hashPassword(
$agent,
$modificationMotDePasse->motDePasse
)
);
$agent->supprimerJetonVerification();

$this->agentRepository->save($agent);

return $this->redirectToRoute('agent_securite_se_connecter');
} else {
/** @var FormError $error */
foreach ($form->getErrors(true) as $key => $error) {
$errors[$error->getOrigin()?->getName()] = $error->getMessage();
}
}
}
}

return $this->render('agent/activation.html.twig', [
'agent' => $agent,
'form' => $form,
'errors' => $errors,
]);
}
}
20 changes: 0 additions & 20 deletions src/DataFixtures/AppFixtures.php

This file was deleted.

Loading

0 comments on commit 6543eec

Please sign in to comment.