我正在使用帶有FOSUserBundle的FR3DLdapBundle。FR3DLdapBundle - 身份驗證請求失敗
Symfony的版本3.2.6 FR3DLdapBundle 3版
config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
fr3d_ldap:
driver:
host: ldap.forumsys.com
port: 389
username: cn=read-only-admin,dc=example,dc=com
password: password
bindRequiresDn: true
user:
baseDn: dc=example,dc=com
filter: (&(objectClass=person))
attributes:
- { ldap_attr: uid, user_method: setUsername }
security.yml
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
AppBundle\Entity\User: plaintext
erase_credentials: false
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN]
providers:
chain_provider:
chain:
providers: [fr3d_ldapbundle,fos_userbundle]
fr3d_ldapbundle:
id: fr3d_ldap.security.user.provider
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
fr3d_ldap: ~
form_login:
provider: chain_provider
always_use_default_target_path: true
default_target_path:/
logout: true
anonymous: true
encoders:
AcmeBundle\Acme\User\LdapUser: plaintext
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_USER }
我測試用Online LDAP Test Server服務。 我已成功地使一個成功登錄具有以下配置:
fr3d_ldap:
driver:
host: ldap.forumsys.com
port: 389
#version: 3
username: cn=read-only-admin,dc=example,dc=com
password: password
bindRequiresDn: true
user:
baseDn: uid=euclid,dc=example,dc=com
filter: (&(objectClass=person))
attributes:
- { ldap_attr: uid, user_method: setUsername }
但有了這個配置我只能登錄爲用戶歐幾里得的問題。但我想以每個可用用戶的身份登錄。
但與其他配置我得到的消息在日誌中,該用戶被發現,但一個期待已發生。
2017-04-20 09:36:16] ldap_driver.DEBUG: ldap_search(dc=example,dc=com, (&(&(objectClass=person))(uid=einstein)), [array]) {"action":"ldap_search","base_dn":"dc=example,dc=com","filter":"(&(&(objectClass=person))(uid=einstein))","attributes":[]} []
[2017-04-20 09:36:17] security.INFO: User einstein found on LDAP {"action":"loadUserByUsername","username":"einstein","result":"found"} []
[2017-04-20 09:36:17] ldap_driver.DEBUG: ldap_bind(einstein, ****) {"action":"ldap_bind","bind_rdn":"einstein"} []
[2017-04-20 09:36:17] ldap_driver.DEBUG: exception 'Zend\Ldap\Exception\LdapException' with message '0x1: Failed to retrieve DN for account: einstein [0x1: Unexpected result count (16) for: (&(objectClass=person))]' in /vendor/zendframework/zend-ldap/src/Ldap.php:805 Stack trace: #0 /vendor/fr3d/ldap-bundle/Driver/ZendLdapDriver.php(82): Zend\Ldap\Ldap->bind('einstein', 'password') #1 /vendor/fr3d/ldap-bundle/Ldap/LdapManager.php(78): FR3D\LdapBundle\Driver\ZendLdapDriver->bind(Object(AppBundle\Entity\User), 'password') #2 /vendor/fr3d/ldap-bundle/Security/Authentication/LdapAuthenticationProvider.php(90): FR3D\LdapBundle\Ldap\LdapManager->bind(Object(AppBundle\Entity\User), 'password') #3 ...
[2017-04-20 09:36:17] ldap_driver.DEBUG: ldap_search(dc=example,dc=com, (&(&(objectClass=person))(uid=einstein)), [array]) {"action":"ldap_search","base_dn":"dc=example,dc=com","filter":"(&(&(objectClass=person))(uid=einstein))","attributes":[]} []
[2017-04-20 09:36:17] security.INFO: User einstein found on LDAP {"action":"loadUserByUsername","username":"einstein","result":"found"} []
[2017-04-20 09:36:17] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): Bad credentials. at /vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:90, Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): The presented password is invalid. at /vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:67)"} []
我不知道我做錯了什麼,我在我的開始與LDAP。
編輯 我改變了我的代碼,就像Alvin發佈的例子。 但我收到以下錯誤:Symfony Dev Log。 系統找到用戶,但然後我得到日誌文件中的錯誤。
您是否明確要使用FR3D LDAP Bundle,或者您的目標是使用任何可用的可能性/工具來針對LDAP服務器驗證用戶身份?如果答案是第二個選項,那麼您應該知道Symfony從版本2開始支持LDAP。8並且不需要外部捆綁。 – cezar
我只想對LDAP服務器進行身份驗證。我發現了這個包,並認爲它會很有用。 – tablesuplex
此外,仔細檢查你根據我的文章所做的一切。我認爲當我第一次寫文章時,我必須從頭開始創建一些Symfony項目,直到我開始工作。對於我現在的新項目,我只是複製所有相同的設置。不要忘記更新架構。 –