{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/30026956","id":30026956,"diff_hunk":"@@ -0,0 +1,221 @@\n+<?php\n+\n+namespace Symfony\\Component\\Security\\Ldap;\n+\n+use Symfony\\Component\\Security\\Ldap\\Exception\\ConnectionException;\n+use Symfony\\Component\\Security\\Ldap\\Exception\\LdapException;\n+\n+/**\n+ * @author Grégoire Pineau <lyrixx@lyrixx.info>\n+ * @author Francis Besset <francis.besset@gmail.com>\n+ * @author Charles Sarrazin <charles@sarraz.in>\n+ */\n+class Ldap implements LdapInterface\n+{\n+    private $host;\n+    private $port;\n+    private $version;\n+    private $useSsl;\n+    private $useStartTls;\n+    private $optReferrals;\n+    private $connection;\n+    private $charmaps;\n+\n+    /**\n+     * Constructor.\n+     *\n+     * @param string $host\n+     * @param int    $port\n+     * @param string $dn\n+     * @param int    $version\n+     * @param bool   $useSsl\n+     * @param bool   $useStartTls\n+     * @param bool   $optReferrals\n+     */\n+    public function __construct($host = null, $port = 389, $version = 3, $useSsl = false, $useStartTls = false, $optReferrals = false)\n+    {\n+        if (!extension_loaded('ldap')) {\n+            throw new LdapException('The ldap module is needed.');\n+        }\n+\n+        $this->host = $host;\n+        $this->port = $port;\n+        $this->version = $version;\n+        $this->useSsl = (bool) $useSsl;\n+        $this->useStartTls = (bool) $useStartTls;\n+        $this->optReferrals = (bool) $optReferrals;\n+    }\n+\n+    public function __destruct()\n+    {\n+        $this->disconnect();\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function bind($dn = null, $password = null)\n+    {\n+        if (!$this->connection) {\n+            $this->connect();\n+        }\n+\n+        if (false === @ldap_bind($this->connection, $dn, $password)) {\n+            throw new ConnectionException(sprintf('Dn / password invalid to connect on Ldap server %s:%s', $this->host, $this->port));","path":"src/Symfony/Component/Security/Ldap/Ldap.php","position":64,"original_position":64,"commit_id":"155602f7094fd9e9ec2c822d9c87f44a08e8302a","original_commit_id":"aa56589489a095cc9572bd2fd77def4d3f009b66","user":{"login":"amenophis","id":2158235,"avatar_url":"https://avatars.githubusercontent.com/u/2158235?v=3","gravatar_id":"","url":"https://api.github.com/users/amenophis","html_url":"https://github.com/amenophis","followers_url":"https://api.github.com/users/amenophis/followers","following_url":"https://api.github.com/users/amenophis/following{/other_user}","gists_url":"https://api.github.com/users/amenophis/gists{/gist_id}","starred_url":"https://api.github.com/users/amenophis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amenophis/subscriptions","organizations_url":"https://api.github.com/users/amenophis/orgs","repos_url":"https://api.github.com/users/amenophis/repos","events_url":"https://api.github.com/users/amenophis/events{/privacy}","received_events_url":"https://api.github.com/users/amenophis/received_events","type":"User","site_admin":false},"body":"Maybe the message should be the return of http://php.net/manual/fr/function.ldap-error.php ?","created_at":"2015-05-11T10:14:51Z","updated_at":"2015-05-11T10:14:51Z","html_url":"https://github.com/symfony/symfony/pull/14602#discussion_r30026956","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/14602","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/30026956"},"html":{"href":"https://github.com/symfony/symfony/pull/14602#discussion_r30026956"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14602"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/14602","id":35091045,"html_url":"https://github.com/symfony/symfony/pull/14602","diff_url":"https://github.com/symfony/symfony/pull/14602.diff","patch_url":"https://github.com/symfony/symfony/pull/14602.patch","issue_url":"https://api.github.com/repos/symfony/symfony/issues/14602","number":14602,"state":"open","locked":false,"title":"[WIP][Security] Added Ldap provider","user":{"login":"csarrazi","id":465798,"avatar_url":"https://avatars.githubusercontent.com/u/465798?v=3","gravatar_id":"","url":"https://api.github.com/users/csarrazi","html_url":"https://github.com/csarrazi","followers_url":"https://api.github.com/users/csarrazi/followers","following_url":"https://api.github.com/users/csarrazi/following{/other_user}","gists_url":"https://api.github.com/users/csarrazi/gists{/gist_id}","starred_url":"https://api.github.com/users/csarrazi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csarrazi/subscriptions","organizations_url":"https://api.github.com/users/csarrazi/orgs","repos_url":"https://api.github.com/users/csarrazi/repos","events_url":"https://api.github.com/users/csarrazi/events{/privacy}","received_events_url":"https://api.github.com/users/csarrazi/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | not yet\r\n| Fixed tickets | -\r\n| License       | MIT\r\n| Doc PR        | not yet\r\n\r\nCurrent state:\r\n\r\n- [x] Implement logic\r\n- [ ] Post-review tuning and stabilization\r\n- [ ] Fix tests\r\n\r\nThis PR is a follow-up to #5189, which was in a stand-still for a few years now. It tries to fix the remaining issues which were mentioned in the discussion.\r\n\r\nThere are still a few issues with the PR, as it is. For example, it introduces two new firewall factories, whereas the base factories (`form_login` and `http_basic`) could simply introduce new configuration options.\r\n\r\nAlso, for a user to use an LDAP server as an authentication provider, he first needs to define a service which should be an instance of `Symfony\\Component\\Security\\Ldap\\Ldap`.\r\n\r\nFor example:\r\n\r\n```yml\r\nservices:\r\n    my_ldap:\r\n        class: Symfony\\Component\\Security\\Ldap\\Ldap\r\n        arguments: [ \"ldap.mydomain.tld\" ]\r\n```\r\n\r\nThen, in `security.yml`, this service can be used in both the user provider and the firewalls:\r\n\r\n```yml\r\nsecurity:\r\n    encoders:\r\n        Symfony\\Component\\Security\\Core\\User\\User: plaintext\r\n\r\n    role_hierarchy:\r\n        ROLE_ADMIN:       ROLE_USER\r\n        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]\r\n\r\n    providers:\r\n        ldap_users:\r\n            ldap:\r\n                service: my_ldap\r\n                base_dn: dc=MyDomain,dc=tld\r\n                search_dn: CN=My User,OU=Users,DC=MyDomain,DC=tld\r\n                search_password: p455w0rd\r\n                filter: (sAMAccountName={username})\r\n                default_roles: ROLE_USER\r\n\r\n    firewalls:\r\n        dev:\r\n            pattern:  ^/(_(profiler|wdt)|css|images|js)/\r\n            security: false\r\n        demo_login:\r\n            pattern:  ^/login$\r\n            security: false\r\n        api:\r\n            provider: ldap_users\r\n            stateless: true\r\n            pattern:    ^/api\r\n            http_basic_ldap:\r\n                service: my_ldap\r\n                dn_string: \"{username}@MYDOMAIN\"\r\n        demo_secured_area:\r\n            provider: ldap_users\r\n            pattern:    ^/\r\n            logout:\r\n                path:   logout\r\n                target: login\r\n            form_login_ldap:\r\n                service: my_ldap\r\n                dn_string: CN={username},OU=Users,DC=MyDomain,DC=tld\r\n                check_path: login_check\r\n                login_path: login\r\n```","created_at":"2015-05-10T23:51:51Z","updated_at":"2015-05-11T10:14:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6bc81ada696cceed09780face1bb4433d1a4c7e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/14602/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/14602/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/14602/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/155602f7094fd9e9ec2c822d9c87f44a08e8302a","head":{"label":"csarrazi:feat-ldap","ref":"feat-ldap","sha":"155602f7094fd9e9ec2c822d9c87f44a08e8302a","user":{"login":"csarrazi","id":465798,"avatar_url":"https://avatars.githubusercontent.com/u/465798?v=3","gravatar_id":"","url":"https://api.github.com/users/csarrazi","html_url":"https://github.com/csarrazi","followers_url":"https://api.github.com/users/csarrazi/followers","following_url":"https://api.github.com/users/csarrazi/following{/other_user}","gists_url":"https://api.github.com/users/csarrazi/gists{/gist_id}","starred_url":"https://api.github.com/users/csarrazi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csarrazi/subscriptions","organizations_url":"https://api.github.com/users/csarrazi/orgs","repos_url":"https://api.github.com/users/csarrazi/repos","events_url":"https://api.github.com/users/csarrazi/events{/privacy}","received_events_url":"https://api.github.com/users/csarrazi/received_events","type":"User","site_admin":false},"repo":{"id":16704730,"name":"symfony","full_name":"csarrazi/symfony","owner":{"login":"csarrazi","id":465798,"avatar_url":"https://avatars.githubusercontent.com/u/465798?v=3","gravatar_id":"","url":"https://api.github.com/users/csarrazi","html_url":"https://github.com/csarrazi","followers_url":"https://api.github.com/users/csarrazi/followers","following_url":"https://api.github.com/users/csarrazi/following{/other_user}","gists_url":"https://api.github.com/users/csarrazi/gists{/gist_id}","starred_url":"https://api.github.com/users/csarrazi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csarrazi/subscriptions","organizations_url":"https://api.github.com/users/csarrazi/orgs","repos_url":"https://api.github.com/users/csarrazi/repos","events_url":"https://api.github.com/users/csarrazi/events{/privacy}","received_events_url":"https://api.github.com/users/csarrazi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/csarrazi/symfony","description":"The Symfony PHP framework","fork":true,"url":"https://api.github.com/repos/csarrazi/symfony","forks_url":"https://api.github.com/repos/csarrazi/symfony/forks","keys_url":"https://api.github.com/repos/csarrazi/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/csarrazi/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/csarrazi/symfony/teams","hooks_url":"https://api.github.com/repos/csarrazi/symfony/hooks","issue_events_url":"https://api.github.com/repos/csarrazi/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/csarrazi/symfony/events","assignees_url":"https://api.github.com/repos/csarrazi/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/csarrazi/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/csarrazi/symfony/tags","blobs_url":"https://api.github.com/repos/csarrazi/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/csarrazi/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/csarrazi/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/csarrazi/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/csarrazi/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/csarrazi/symfony/languages","stargazers_url":"https://api.github.com/repos/csarrazi/symfony/stargazers","contributors_url":"https://api.github.com/repos/csarrazi/symfony/contributors","subscribers_url":"https://api.github.com/repos/csarrazi/symfony/subscribers","subscription_url":"https://api.github.com/repos/csarrazi/symfony/subscription","commits_url":"https://api.github.com/repos/csarrazi/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/csarrazi/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/csarrazi/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/csarrazi/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/csarrazi/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/csarrazi/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/csarrazi/symfony/merges","archive_url":"https://api.github.com/repos/csarrazi/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/csarrazi/symfony/downloads","issues_url":"https://api.github.com/repos/csarrazi/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/csarrazi/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/csarrazi/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/csarrazi/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/csarrazi/symfony/labels{/name}","releases_url":"https://api.github.com/repos/csarrazi/symfony/releases{/id}","created_at":"2014-02-10T18:26:10Z","updated_at":"2015-03-24T15:55:17Z","pushed_at":"2015-05-11T10:03:40Z","git_url":"git://github.com/csarrazi/symfony.git","ssh_url":"git@github.com:csarrazi/symfony.git","clone_url":"https://github.com/csarrazi/symfony.git","svn_url":"https://github.com/csarrazi/symfony","homepage":"symfony.com","size":55512,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.8","ref":"2.8","sha":"88b7e7ce599c0c8bb808e1ae1d0dac8afb61cb8f","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","created_at":"2010-01-04T14:21:21Z","updated_at":"2015-05-11T09:54:59Z","pushed_at":"2015-05-11T10:03:44Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":226513,"stargazers_count":10155,"watchers_count":10155,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4019,"mirror_url":null,"open_issues_count":840,"forks":4019,"open_issues":840,"watchers":10155,"default_branch":"2.7"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14602"},"html":{"href":"https://github.com/symfony/symfony/pull/14602"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/14602"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/14602/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14602/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/14602/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/155602f7094fd9e9ec2c822d9c87f44a08e8302a"}}}}