{"action":"created","comment":{"url":"https://api.github.com/repos/lookout/deploydb/pulls/comments/28434778","id":28434778,"diff_hunk":"@@ -0,0 +1,135 @@\n+package deploydb.auth\n+\n+import com.google.common.base.Optional\n+import com.google.common.collect.ImmutableSet\n+import io.dropwizard.auth.AuthenticationException\n+import io.dropwizard.auth.Authenticator\n+import io.dropwizard.auth.basic.BasicCredentials\n+import javax.naming.AuthenticationException\n+import javax.naming.Context\n+import javax.naming.NamingEnumeration\n+import javax.naming.NamingException\n+import javax.naming.directory.InitialDirContext\n+import javax.naming.directory.SearchControls\n+import javax.naming.directory.SearchResult\n+import org.slf4j.Logger\n+import org.slf4j.LoggerFactory\n+\n+\n+class LdapAuthenticator implements Authenticator<BasicCredentials, BasicCredentials> {\n+    private final LdapConfiguration configuration\n+    private static final Logger logger = LoggerFactory.getLogger(LdapAuthenticator.class)\n+\n+    LdapAuthenticator(LdapConfiguration configuration) {\n+        this.configuration = configuration\n+    }\n+\n+    /* Take off everything but alphanumeric and some username specific chars */\n+    private static String sanitizeEntity(String name) {\n+        return name.replaceAll(\"[^A-Za-z0-9-_.]\", \"\")\n+    }\n+\n+    /**\n+     * Creates, connects to LDAP server using JNDI\n+     *\n+     * @param sanitizedUsername\n+     * @param password\n+     * @return Directory context\n+     * @throws NamingException\n+     */\n+    InitialDirContext buildContext(String sanitizedUsername, String password) throws NamingException {\n+        final String userDN = String.format(\"%s=%s,%s\", configuration.getUserNameAttribute(),","path":"src/main/groovy/deploydb/auth/LdapAuthenticator.groovy","position":41,"original_position":41,"commit_id":"b47715e782e5cc50f301ea29f9cb160c350d43dc","original_commit_id":"b47715e782e5cc50f301ea29f9cb160c350d43dc","user":{"login":"rtyler","id":26594,"avatar_url":"https://avatars.githubusercontent.com/u/26594?v=3","gravatar_id":"","url":"https://api.github.com/users/rtyler","html_url":"https://github.com/rtyler","followers_url":"https://api.github.com/users/rtyler/followers","following_url":"https://api.github.com/users/rtyler/following{/other_user}","gists_url":"https://api.github.com/users/rtyler/gists{/gist_id}","starred_url":"https://api.github.com/users/rtyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtyler/subscriptions","organizations_url":"https://api.github.com/users/rtyler/orgs","repos_url":"https://api.github.com/users/rtyler/repos","events_url":"https://api.github.com/users/rtyler/events{/privacy}","received_events_url":"https://api.github.com/users/rtyler/received_events","type":"User","site_admin":false},"body":"This is logic that should be put into its own method so it can be tested in isolation.","created_at":"2015-04-15T16:06:54Z","updated_at":"2015-04-15T16:06:54Z","html_url":"https://github.com/lookout/deploydb/pull/158#discussion_r28434778","pull_request_url":"https://api.github.com/repos/lookout/deploydb/pulls/158","_links":{"self":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/comments/28434778"},"html":{"href":"https://github.com/lookout/deploydb/pull/158#discussion_r28434778"},"pull_request":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/158"}}},"pull_request":{"url":"https://api.github.com/repos/lookout/deploydb/pulls/158","id":33293187,"html_url":"https://github.com/lookout/deploydb/pull/158","diff_url":"https://github.com/lookout/deploydb/pull/158.diff","patch_url":"https://github.com/lookout/deploydb/pull/158.patch","issue_url":"https://api.github.com/repos/lookout/deploydb/issues/158","number":158,"state":"open","locked":false,"title":"Added support for LDAP authentication","user":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"body":"This can be used for authentication required for manual promotion or for all\r\nREST apis in future\r\n\r\n- Added LDAP client support using JNDI.\r\n- Using dropwizard basic HTTP authenticator support for fetching the attributes from client.\r\n- Added LDAP test server using unboundid's in-memory ldap server.\r\n- Added spock and cucumber tests\r\n\r\nReferences #157","created_at":"2015-04-14T19:50:55Z","updated_at":"2015-04-15T16:06:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d7ec0a594fa6c39229b7596350ad237445c18115","assignee":{"login":"rtyler","id":26594,"avatar_url":"https://avatars.githubusercontent.com/u/26594?v=3","gravatar_id":"","url":"https://api.github.com/users/rtyler","html_url":"https://github.com/rtyler","followers_url":"https://api.github.com/users/rtyler/followers","following_url":"https://api.github.com/users/rtyler/following{/other_user}","gists_url":"https://api.github.com/users/rtyler/gists{/gist_id}","starred_url":"https://api.github.com/users/rtyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtyler/subscriptions","organizations_url":"https://api.github.com/users/rtyler/orgs","repos_url":"https://api.github.com/users/rtyler/repos","events_url":"https://api.github.com/users/rtyler/events{/privacy}","received_events_url":"https://api.github.com/users/rtyler/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/lookout/deploydb/pulls/158/commits","review_comments_url":"https://api.github.com/repos/lookout/deploydb/pulls/158/comments","review_comment_url":"https://api.github.com/repos/lookout/deploydb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lookout/deploydb/issues/158/comments","statuses_url":"https://api.github.com/repos/lookout/deploydb/statuses/b47715e782e5cc50f301ea29f9cb160c350d43dc","head":{"label":"maheshkelkar:issues/157-ldap-authentication","ref":"issues/157-ldap-authentication","sha":"b47715e782e5cc50f301ea29f9cb160c350d43dc","user":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"repo":{"id":30329363,"name":"deploydb","full_name":"maheshkelkar/deploydb","owner":{"login":"maheshkelkar","id":10839177,"avatar_url":"https://avatars.githubusercontent.com/u/10839177?v=3","gravatar_id":"","url":"https://api.github.com/users/maheshkelkar","html_url":"https://github.com/maheshkelkar","followers_url":"https://api.github.com/users/maheshkelkar/followers","following_url":"https://api.github.com/users/maheshkelkar/following{/other_user}","gists_url":"https://api.github.com/users/maheshkelkar/gists{/gist_id}","starred_url":"https://api.github.com/users/maheshkelkar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maheshkelkar/subscriptions","organizations_url":"https://api.github.com/users/maheshkelkar/orgs","repos_url":"https://api.github.com/users/maheshkelkar/repos","events_url":"https://api.github.com/users/maheshkelkar/events{/privacy}","received_events_url":"https://api.github.com/users/maheshkelkar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maheshkelkar/deploydb","description":"Your deployments: who, what, where and when.","fork":true,"url":"https://api.github.com/repos/maheshkelkar/deploydb","forks_url":"https://api.github.com/repos/maheshkelkar/deploydb/forks","keys_url":"https://api.github.com/repos/maheshkelkar/deploydb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maheshkelkar/deploydb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maheshkelkar/deploydb/teams","hooks_url":"https://api.github.com/repos/maheshkelkar/deploydb/hooks","issue_events_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues/events{/number}","events_url":"https://api.github.com/repos/maheshkelkar/deploydb/events","assignees_url":"https://api.github.com/repos/maheshkelkar/deploydb/assignees{/user}","branches_url":"https://api.github.com/repos/maheshkelkar/deploydb/branches{/branch}","tags_url":"https://api.github.com/repos/maheshkelkar/deploydb/tags","blobs_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/refs{/sha}","trees_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maheshkelkar/deploydb/statuses/{sha}","languages_url":"https://api.github.com/repos/maheshkelkar/deploydb/languages","stargazers_url":"https://api.github.com/repos/maheshkelkar/deploydb/stargazers","contributors_url":"https://api.github.com/repos/maheshkelkar/deploydb/contributors","subscribers_url":"https://api.github.com/repos/maheshkelkar/deploydb/subscribers","subscription_url":"https://api.github.com/repos/maheshkelkar/deploydb/subscription","commits_url":"https://api.github.com/repos/maheshkelkar/deploydb/commits{/sha}","git_commits_url":"https://api.github.com/repos/maheshkelkar/deploydb/git/commits{/sha}","comments_url":"https://api.github.com/repos/maheshkelkar/deploydb/comments{/number}","issue_comment_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues/comments{/number}","contents_url":"https://api.github.com/repos/maheshkelkar/deploydb/contents/{+path}","compare_url":"https://api.github.com/repos/maheshkelkar/deploydb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maheshkelkar/deploydb/merges","archive_url":"https://api.github.com/repos/maheshkelkar/deploydb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maheshkelkar/deploydb/downloads","issues_url":"https://api.github.com/repos/maheshkelkar/deploydb/issues{/number}","pulls_url":"https://api.github.com/repos/maheshkelkar/deploydb/pulls{/number}","milestones_url":"https://api.github.com/repos/maheshkelkar/deploydb/milestones{/number}","notifications_url":"https://api.github.com/repos/maheshkelkar/deploydb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maheshkelkar/deploydb/labels{/name}","releases_url":"https://api.github.com/repos/maheshkelkar/deploydb/releases{/id}","created_at":"2015-02-05T00:36:28Z","updated_at":"2015-02-05T00:36:29Z","pushed_at":"2015-04-15T01:10:23Z","git_url":"git://github.com/maheshkelkar/deploydb.git","ssh_url":"git@github.com:maheshkelkar/deploydb.git","clone_url":"https://github.com/maheshkelkar/deploydb.git","svn_url":"https://github.com/maheshkelkar/deploydb","homepage":"http://hackers.lookout.com/deploydb/","size":1598,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lookout:master","ref":"master","sha":"ecec786b7b9a3edb2d3d28af77826277e7e66d66","user":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"repo":{"id":28099382,"name":"deploydb","full_name":"lookout/deploydb","owner":{"login":"lookout","id":47237,"avatar_url":"https://avatars.githubusercontent.com/u/47237?v=3","gravatar_id":"","url":"https://api.github.com/users/lookout","html_url":"https://github.com/lookout","followers_url":"https://api.github.com/users/lookout/followers","following_url":"https://api.github.com/users/lookout/following{/other_user}","gists_url":"https://api.github.com/users/lookout/gists{/gist_id}","starred_url":"https://api.github.com/users/lookout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lookout/subscriptions","organizations_url":"https://api.github.com/users/lookout/orgs","repos_url":"https://api.github.com/users/lookout/repos","events_url":"https://api.github.com/users/lookout/events{/privacy}","received_events_url":"https://api.github.com/users/lookout/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lookout/deploydb","description":"Your deployments: who, what, where and when.","fork":false,"url":"https://api.github.com/repos/lookout/deploydb","forks_url":"https://api.github.com/repos/lookout/deploydb/forks","keys_url":"https://api.github.com/repos/lookout/deploydb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lookout/deploydb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lookout/deploydb/teams","hooks_url":"https://api.github.com/repos/lookout/deploydb/hooks","issue_events_url":"https://api.github.com/repos/lookout/deploydb/issues/events{/number}","events_url":"https://api.github.com/repos/lookout/deploydb/events","assignees_url":"https://api.github.com/repos/lookout/deploydb/assignees{/user}","branches_url":"https://api.github.com/repos/lookout/deploydb/branches{/branch}","tags_url":"https://api.github.com/repos/lookout/deploydb/tags","blobs_url":"https://api.github.com/repos/lookout/deploydb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lookout/deploydb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lookout/deploydb/git/refs{/sha}","trees_url":"https://api.github.com/repos/lookout/deploydb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lookout/deploydb/statuses/{sha}","languages_url":"https://api.github.com/repos/lookout/deploydb/languages","stargazers_url":"https://api.github.com/repos/lookout/deploydb/stargazers","contributors_url":"https://api.github.com/repos/lookout/deploydb/contributors","subscribers_url":"https://api.github.com/repos/lookout/deploydb/subscribers","subscription_url":"https://api.github.com/repos/lookout/deploydb/subscription","commits_url":"https://api.github.com/repos/lookout/deploydb/commits{/sha}","git_commits_url":"https://api.github.com/repos/lookout/deploydb/git/commits{/sha}","comments_url":"https://api.github.com/repos/lookout/deploydb/comments{/number}","issue_comment_url":"https://api.github.com/repos/lookout/deploydb/issues/comments{/number}","contents_url":"https://api.github.com/repos/lookout/deploydb/contents/{+path}","compare_url":"https://api.github.com/repos/lookout/deploydb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lookout/deploydb/merges","archive_url":"https://api.github.com/repos/lookout/deploydb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lookout/deploydb/downloads","issues_url":"https://api.github.com/repos/lookout/deploydb/issues{/number}","pulls_url":"https://api.github.com/repos/lookout/deploydb/pulls{/number}","milestones_url":"https://api.github.com/repos/lookout/deploydb/milestones{/number}","notifications_url":"https://api.github.com/repos/lookout/deploydb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lookout/deploydb/labels{/name}","releases_url":"https://api.github.com/repos/lookout/deploydb/releases{/id}","created_at":"2014-12-16T18:04:06Z","updated_at":"2015-04-14T02:23:00Z","pushed_at":"2015-04-15T01:10:24Z","git_url":"git://github.com/lookout/deploydb.git","ssh_url":"git@github.com:lookout/deploydb.git","clone_url":"https://github.com/lookout/deploydb.git","svn_url":"https://github.com/lookout/deploydb","homepage":"http://hackers.lookout.com/deploydb/","size":2735,"stargazers_count":38,"watchers_count":38,"language":"Groovy","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":8,"forks":7,"open_issues":8,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/158"},"html":{"href":"https://github.com/lookout/deploydb/pull/158"},"issue":{"href":"https://api.github.com/repos/lookout/deploydb/issues/158"},"comments":{"href":"https://api.github.com/repos/lookout/deploydb/issues/158/comments"},"review_comments":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/158/comments"},"review_comment":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lookout/deploydb/pulls/158/commits"},"statuses":{"href":"https://api.github.com/repos/lookout/deploydb/statuses/b47715e782e5cc50f301ea29f9cb160c350d43dc"}}}}