Skip to content

[Ldap] form_login_ldap and new authentication system #42346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcp-dev opened this issue Aug 2, 2021 · 1 comment
Closed

[Ldap] form_login_ldap and new authentication system #42346

dcp-dev opened this issue Aug 2, 2021 · 1 comment

Comments

@dcp-dev
Copy link
Contributor

dcp-dev commented Aug 2, 2021

Symfony version(s) affected: 5.1+

Description
With the new authenticator manager enabled, the form_login_ldap authenticator doesn't take care of the login_path option


How to reproduce

  • Create new project
  • Enable the new authentication system (if not)
  • Add the form_login_ldap authenticator:
        form_login_ldap:
                login_path: security_login
                check_path: security_login
                service: Symfony\Component\Ldap\Ldap
                dn_string: 'uid={username},dc=example,dc=com'
  • Protect one route for authenticated users only:
        access_control:
        - { path: ^/login$, role: PUBLIC_ACCESS }
        - { path: ^/protected, role: ROLE_USER }
  • Try to access to /protected
  • You got an Unauthorized exception instead of being redirected to /login

If you try to add:

    entry_point: form_login_ldap

You'll get a ServiceNotFoundException, which suggest to switch to entry_point: security.authenticator.form_login_ldap.main which leads to a new issue:

Argument 5 passed to Symfony\Component\Security\Http\Firewall\ExceptionListener::__construct() must implement interface Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface or be null, instance of Symfony\Component\Ldap\Security\LdapAuthenticator given


Possible Solution
Make Symfony\Component\Ldap\Security\LdapAuthenticator extends of AbstractLoginFormAuthenticator.
This way we got a getLoginUrl() methods which resolve our main issue.

The problem is that, unlike the Symfony\Component\Security\Http\Authenticator, we don't have the HttpUtils service which prevents us to properly resolve the login_path option
I'm not sure on how to inject properly the service to the authenticator so this is why I'm opening an issue instead of doing a MR

@chalasr
Copy link
Member

chalasr commented Aug 2, 2021

The ldap authenticator decorates the form_login one, hence it should not extend it.
What's needed here is to make LdapAuthenticator implements AuthenticationEntryPointInterface (maybe also InteractiveAuthenticatorInterface) in addition to AuthenticatorInterface.
The start() implementation should ensure that the decorated authenticator is an AuthenticationEntryPointInterface implementation, probably by throwing a LogicException if it does not, and call start() on the decorated authenticator.

@fabpot fabpot closed this as completed Sep 26, 2021
fabpot added a commit that referenced this issue Sep 26, 2021
…-dev, chalasr)

This PR was merged into the 5.3 branch.

Discussion
----------

[Ldap][Security] Make LdapAuthenticator an EntryPoint

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #42346
| License       | MIT
| Doc PR        | N/A

I added `@chalasr`'s recommandations given in #42346 (comment)

Commits
-------

4daad9e Fix decorating non-entrypoint authenticators
0b0c15c [Ldap] Make LdapAuthenticator an EntryPoint
symfony-splitter pushed a commit to symfony/security-http that referenced this issue Sep 26, 2021
…-dev, chalasr)

This PR was merged into the 5.3 branch.

Discussion
----------

[Ldap][Security] Make LdapAuthenticator an EntryPoint

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #42346
| License       | MIT
| Doc PR        | N/A

I added `@chalasr`'s recommandations given in symfony/symfony#42346 (comment)

Commits
-------

4daad9e784 Fix decorating non-entrypoint authenticators
0b0c15c019 [Ldap] Make LdapAuthenticator an EntryPoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants