I am writing a Test app in Symfony3 and I am trying to set up LDAP user authentication on top of my FOSUserBundle
I have found this Symfony ldap Bundle: FR3DLdapBundle
I followed the documentation and 'I think I set it up correctly'. Once I have done the configuration as specified here when i refresh my page nothing happens no errors either. To check if anything has happened i used Wireshark to track if there was a LDAP call/pacage but nothing.
Security.yml:
security:
erase_credentials: false
firewalls:
main:
pattern: ^/
fr3d_ldap: ~
form_login:
always_use_default_target_path: true
default_target_path: /profile
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout: true
anonymous: true
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
chain_provider:
chain:
providers: [fos_userbundle, fr3d_ldapbundle]
fr3d_ldapbundle:
id: fr3d_ldap.security.user.provider
fos_userbundle:
id: fos_user.user_provider.username
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
`congig.yml:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Test\TestBundle\Entity\User
# app/config/config.yml
fr3d_ldap:
driver:
host: ldap.forumsys.com
# port: 389 # Optional
# username: foo # Optional
# password: bar # Optional
# bindRequiresDn: true # Optional
# baseDn: ou=users, dc=host, dc=foo # Optional
# accountFilterFormat: (&(uid=%s)) # Optional. sprintf format %s will be the username
# optReferrals: false # Optional
# useSsl: true # Enable SSL negotiation. Optional
# useStartTls: true # Enable TLS negotiation. Optional
# accountCanonicalForm: 3 # ACCTNAME_FORM_BACKSLASH this is only needed if your users have to login with something like HOST\User
# accountDomainName: HOST
# accountDomainNameShort: HOST # if you use the Backslash form set both to Hostname than the Username will be converted to HOST\User
user:
baseDn: ou=users, dc=host, dc=foo
filter: (&(ObjectClass=Person))
# usernameAttribute: uid # Optional
attributes: # Specify ldap attributes mapping [ldap attribute, user object method]
# - { ldap_attr: uid, user_method: setUsername } # Default
# - { ldap_attr: cn, user_method: setName } # Optional
# - { ldap_attr: ..., user_method: ... } # Optional
# service:
# user_hydrator: fr3d_ldap.user_hydrator.default # Overrides default user hydrator
# ldap_manager: fr3d_ldap.ldap_manager.default # Overrides default ldap manager`
The documentation on this bundle is Poor yet it is suggested by everyone everywhere i google ldap Symfony.
Question 1. How do I check or know that something is happening...?
Lets assume that it works, I then created a service like this:
` <!-- LDAP Connection -->
<service id="test.testldap.ldap_adapter"
class="Test\TestBundle\CambioLDAP\LdapAdapter">
<argument type="service" id="fr3d_ldap.driver"/>
</service>`
Also added LdapAdapter:
<?php
namespace Test\TestBundle\CambioLDAP;
use FR3D\LdapBundle\Model\LdapUserInterface;
class LdapAdaptor
{
private $ldap;
public function __construct
(
LdapUserInterface $userInterface
) {
$this->ldap = $userInterface;
}
}
Not even sure if its the LdapUserInreface i should use it only gives me two options:
getDn
setDN
Either way Symfony gives me this error:
The service "test.testldap.ldap_adapter" has a dependency on a non-existent service "fr3d_ldap.driver".
Of course fr3d_ldap.driver is from config.yml.
Question2 Which classes should I be extending
Sorry for the length of this question but It seems Symfony2-3 is very poorly covered by LDAP as well as this bundle, wouldynt it be easier to use straight php to do this...?
Question 1 :
List of loaded services you can check in console:
php app/console debug:container | grep YOUR_SERVICE_ID
Maybe your xml file with services isn't loading? Check in YourBundle\\DependencyInjection\\YourBundleExtension file which service file is loading.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.