Bonjour,

je dois faire une authentification LDAP via un AD distant et j'ai un problème lors du submit de mon formulaire.
J'arrive bien à retrouver l'user de mon AD, mais l'authentification fail avec une erreur "The presented password is invalid".

Je suis sûr de rentrer le même password que celui enregistré dans l'AD.

Ce que je fais

security.yaml

security:
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers

  providers:
    ad_ldap:
      ldap:
        service: Symfony\Component\Ldap\Ldap
        base_dn: '*****'
        search_dn: '*****'
        search_password: '****'
        default_roles: ROLE_USER
        uid_key: uid
        filter: '(uid={username})'

  firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
      pattern: ^/(_(profiler|wdt)|css|images|js)/
      security: false

    main:
      anonymous: ~

      form_login_ldap:
      #http_basic_ldap:

        login_path: login
        check_path: login
        service: Symfony\Component\Ldap\Ldap

            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#firewalls-authentication

            # https://symfony.com/doc/current/security/impersonating_user.html
            # switch_user: true

    # 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: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    #- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/user_agent, roles: ROLE_USER }

security.yaml

# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

    Symfony\Component\Ldap\Ldap:
        arguments: ['@Symfony\Component\Ldap\Adapter\ExtLdap\Adapter']
    Symfony\Component\Ldap\Adapter\ExtLdap\Adapter:
        arguments:
            - host: 192.168.40.40
              port: 389
              encryption: none
              options:
                  protocol_version: 3
                  referrals: false

mon controller

<?php

namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Routing\Annotation\Route;

class homeAuth extends AbstractController
{
    /**
     * @Route("/login", name="login")
     */

    /**
     * @param Request $request
     * @param AuthenticationUtils $authUtils
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function loginAct(Request $request, AuthenticationUtils $authUtils)
    {
        //get the log error
        $error = $authUtils->getLastAuthenticationError();

        //last username entered
        $lastUsername = $authUtils->getLastUsername();

        return $this->render('pages/login.html.twig', array(
            'last_username' => $lastUsername,
            'error' => $error,
        ));
    }
}

et enfin mon formulaire

{% extends 'base.html.twig' %}

{% block title %}

    PEX - Auth

{% endblock %}

{% block body %}

    <div id="formContainer">

    <form action="{{ path('login') }}" method="post" id="formElement">
     <h2>LOGIN</h2>
        <table>
            <tr>
                {% if error %}
                    {{ error.messageKey|trans(error.messageData, 'security') }}
                {% endif %}
            </tr>
            <tr>
                <td>
                    <label for="inputUsername">Username</label>
                </td>
                <td>
                    <input type="text" class="form-control" id="inputUsername" name="_username" value="{{ last_username }}" required="required">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="InputPassword">Password</label>
                </td>
                <td>
                    <input type="password" class="form-control" name="_password" id="InputPassword" required="required">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" class="form-check-input" id="checker">
                </td>
                <td>
                    <label class="form-check-label" for="checker">Remember my login and my password on this computer</label>
                </td>
            </tr>
        </table>
        <button type="submit" class="btn btn-primary" id="loginButton">Login</button>

    </form>

{% endblock %}

{% block stylesheets %}
    <link rel="stylesheet" href="{{ asset('css/login.css') }}">
{% endblock %}

Je ne comprends pas d'où vient mon erreur, et j'ai l'impression que cela ne check pas le password dans l'AD.

Merci d'avance pour votre aide

Aucune réponse