I am using fr3d/ldap-bundle . It registers me and imports users from AD if they are not in db. It's great.
Despite AD users, I also have local users who are in my db. There is a special authType column that says how the user should be authenticated - through LDAP or initially (FOS). I created my own user:
public function chooseProviderForUsername($username) { if($user->getAuthType() == User::LOGIN_LDAP) { $this->properProvider = $this->ldapUserProvider; } elseif($user->getAuthType() == User::LOGIN_NATIVE) { $this->properProvider = $this->fosUserProvider; } else { throw new InvalidArgumentException('Error'); } } public function loadUserByUsername($username) { return $this->chooseProviderForUsername($username)->loadUserByUsername($username); }
PROBLEM: The chain provider is not an option - it allows the user to log in with his LDAP password and with his local password! This is a serious security issue.
Is there a way to log in through different authentication providers, depending on the db field?
EDIT:
My security.yml:
providers: fos_userbundle: id: fos_user.user_provider.username appbundle_user_provider: id: appbundle.user_provider fr3d_ldapbundle: id: fr3d_ldap.security.user.provider firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false admin: pattern: ^/admin.* context: user fr3d_ldap: ~ form_login: provider: appbundle_user_provider csrf_provider: security.csrf.token_manager always_use_default_target_path: true default_target_path: admin_main login_path: /admin/login check_path: /admin/login_check logout: path: /admin/logout target: /admin/login anonymous: true
Here is security.yml. This fr3d_ldap: ~ allows you to create an ldap package that allows ldap users and saves them in my db. Without this, I cannot resolve them, I may have to write my own authentication method.
authentication php symfony ldap
mmmm
source share