{"action":"created","comment":{"url":"https://api.github.com/repos/auth0/Lock.Android/pulls/comments/53080657","id":53080657,"diff_hunk":"@@ -0,0 +1,131 @@\n+/*\n+ * DomainParser.java\n+ *\n+ * Copyright (c) 2016 Auth0 (http://auth0.com)\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+\n+package com.auth0.android.lock.utils;\n+\n+import android.support.annotation.Nullable;\n+\n+import com.auth0.Auth0Exception;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+/**\n+ * Helper class to find out which email domains can be valid for the current Auth0 configuration.\n+ */\n+public class EnterpriseConnectionMatcher {\n+\n+    private static final String DOMAIN_KEY = \"domain\";\n+    private static final String DOMAIN_ALIASES_KEY = \"domain_aliases\";\n+\n+    private List<Strategy> strategies;\n+\n+    public EnterpriseConnectionMatcher(List<Strategy> strategies) {\n+        this.strategies = new ArrayList<>();\n+        if (strategies == null) {\n+            return;\n+        }\n+\n+        for (Strategy s : strategies) {\n+            if (s.getType() == Strategies.Type.ENTERPRISE) {\n+                this.strategies.add(s);\n+            }\n+        }\n+    }\n+\n+    /**\n+     * Tries to find a valid domain with the given input.\n+     *\n+     * @param email to search the Domain for.\n+     * @return a Connection if found, null otherwise.\n+     */\n+    @Nullable\n+    public Connection parse(String email) {\n+        String domain = extractDomain(email);\n+        if (domain.isEmpty()) {\n+            return null;\n+        }\n+\n+        domain = domain.toLowerCase();\n+        for (Strategy s : strategies) {\n+            for (Connection c : s.getConnections()) {\n+                String mainDomain = c.getValueForKey(DOMAIN_KEY);\n+                if (mainDomain != null && mainDomain.contains(domain)) {\n+                    return c;\n+                }\n+\n+                List<String> aliases = c.getValueForKey(DOMAIN_ALIASES_KEY);\n+                if (aliases != null) {\n+                    for (String d : aliases) {\n+                        if (d.contains(domain)) {\n+                            return c;\n+                        }\n+                    }\n+                }\n+            }\n+        }\n+        return null;\n+    }\n+\n+    /**\n+     * Extracts the domain part from the email\n+     *\n+     * @param email to parse\n+     * @return the domain String if found, an empty String otherwise\n+     */\n+\n+    public String extractDomain(String email) {\n+        int indexAt = email.indexOf(\"@\") + 1;\n+        if (indexAt == 0) {\n+            return \"\";\n+        }\n+        int indexDot = email.indexOf(\".\", indexAt);\n+        String domain;\n+        if (indexDot == -1) {\n+            domain = email.substring(indexAt);\n+        } else {\n+            domain = email.substring(indexAt, indexDot);\n+        }\n+        if (domain.isEmpty()) {\n+            return \"\";\n+        }\n+        return domain;\n+    }\n+\n+    /**\n+     * Extracts the username part from the email\n+     *\n+     * @param email to parse\n+     * @return the username String if found, an empty String otherwise\n+     */\n+    public String extractUsername(String email) {","path":"lock/src/main/java/com/auth0/android/lock/utils/EnterpriseConnectionMatcher.java","position":122,"original_position":122,"commit_id":"ee1f2c66bed9a318d9204a2d1497234c3fc540ba","original_commit_id":"328691400d0e0de2465b969ea2f7984b0bbf8d96","user":{"login":"lbalmaceda","id":3900123,"avatar_url":"https://avatars.githubusercontent.com/u/3900123?v=3","gravatar_id":"","url":"https://api.github.com/users/lbalmaceda","html_url":"https://github.com/lbalmaceda","followers_url":"https://api.github.com/users/lbalmaceda/followers","following_url":"https://api.github.com/users/lbalmaceda/following{/other_user}","gists_url":"https://api.github.com/users/lbalmaceda/gists{/gist_id}","starred_url":"https://api.github.com/users/lbalmaceda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbalmaceda/subscriptions","organizations_url":"https://api.github.com/users/lbalmaceda/orgs","repos_url":"https://api.github.com/users/lbalmaceda/repos","events_url":"https://api.github.com/users/lbalmaceda/events{/privacy}","received_events_url":"https://api.github.com/users/lbalmaceda/received_events","type":"User","site_admin":false},"body":"@hzalaz this method is used on the `DomainFormView` class, when pre-filling the next username/email form with the right text (full email or only the username part) ","created_at":"2016-02-16T21:22:34Z","updated_at":"2016-02-16T21:22:34Z","html_url":"https://github.com/auth0/Lock.Android/pull/200#discussion_r53080657","pull_request_url":"https://api.github.com/repos/auth0/Lock.Android/pulls/200","_links":{"self":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/comments/53080657"},"html":{"href":"https://github.com/auth0/Lock.Android/pull/200#discussion_r53080657"},"pull_request":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/200"}}},"pull_request":{"url":"https://api.github.com/repos/auth0/Lock.Android/pulls/200","id":59089514,"html_url":"https://github.com/auth0/Lock.Android/pull/200","diff_url":"https://github.com/auth0/Lock.Android/pull/200.diff","patch_url":"https://github.com/auth0/Lock.Android/pull/200.patch","issue_url":"https://api.github.com/repos/auth0/Lock.Android/issues/200","number":200,"state":"open","locked":false,"title":"Enterprise login form and authentication methods","user":{"login":"lbalmaceda","id":3900123,"avatar_url":"https://avatars.githubusercontent.com/u/3900123?v=3","gravatar_id":"","url":"https://api.github.com/users/lbalmaceda","html_url":"https://github.com/lbalmaceda","followers_url":"https://api.github.com/users/lbalmaceda/followers","following_url":"https://api.github.com/users/lbalmaceda/following{/other_user}","gists_url":"https://api.github.com/users/lbalmaceda/gists{/gist_id}","starred_url":"https://api.github.com/users/lbalmaceda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbalmaceda/subscriptions","organizations_url":"https://api.github.com/users/lbalmaceda/orgs","repos_url":"https://api.github.com/users/lbalmaceda/repos","events_url":"https://api.github.com/users/lbalmaceda/events{/privacy}","received_events_url":"https://api.github.com/users/lbalmaceda/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-11T20:34:43Z","updated_at":"2016-02-16T21:22:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe7fb9e14c7daefbee79625e2b45f1b82c30c0b8","assignee":{"login":"hzalaz","id":895992,"avatar_url":"https://avatars.githubusercontent.com/u/895992?v=3","gravatar_id":"","url":"https://api.github.com/users/hzalaz","html_url":"https://github.com/hzalaz","followers_url":"https://api.github.com/users/hzalaz/followers","following_url":"https://api.github.com/users/hzalaz/following{/other_user}","gists_url":"https://api.github.com/users/hzalaz/gists{/gist_id}","starred_url":"https://api.github.com/users/hzalaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hzalaz/subscriptions","organizations_url":"https://api.github.com/users/hzalaz/orgs","repos_url":"https://api.github.com/users/hzalaz/repos","events_url":"https://api.github.com/users/hzalaz/events{/privacy}","received_events_url":"https://api.github.com/users/hzalaz/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/auth0/Lock.Android/pulls/200/commits","review_comments_url":"https://api.github.com/repos/auth0/Lock.Android/pulls/200/comments","review_comment_url":"https://api.github.com/repos/auth0/Lock.Android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/auth0/Lock.Android/issues/200/comments","statuses_url":"https://api.github.com/repos/auth0/Lock.Android/statuses/ee1f2c66bed9a318d9204a2d1497234c3fc540ba","head":{"label":"auth0:enterprise-login-base","ref":"enterprise-login-base","sha":"ee1f2c66bed9a318d9204a2d1497234c3fc540ba","user":{"login":"auth0","id":2824157,"avatar_url":"https://avatars.githubusercontent.com/u/2824157?v=3","gravatar_id":"","url":"https://api.github.com/users/auth0","html_url":"https://github.com/auth0","followers_url":"https://api.github.com/users/auth0/followers","following_url":"https://api.github.com/users/auth0/following{/other_user}","gists_url":"https://api.github.com/users/auth0/gists{/gist_id}","starred_url":"https://api.github.com/users/auth0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auth0/subscriptions","organizations_url":"https://api.github.com/users/auth0/orgs","repos_url":"https://api.github.com/users/auth0/repos","events_url":"https://api.github.com/users/auth0/events{/privacy}","received_events_url":"https://api.github.com/users/auth0/received_events","type":"Organization","site_admin":false},"repo":{"id":27456226,"name":"Lock.Android","full_name":"auth0/Lock.Android","owner":{"login":"auth0","id":2824157,"avatar_url":"https://avatars.githubusercontent.com/u/2824157?v=3","gravatar_id":"","url":"https://api.github.com/users/auth0","html_url":"https://github.com/auth0","followers_url":"https://api.github.com/users/auth0/followers","following_url":"https://api.github.com/users/auth0/following{/other_user}","gists_url":"https://api.github.com/users/auth0/gists{/gist_id}","starred_url":"https://api.github.com/users/auth0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auth0/subscriptions","organizations_url":"https://api.github.com/users/auth0/orgs","repos_url":"https://api.github.com/users/auth0/repos","events_url":"https://api.github.com/users/auth0/events{/privacy}","received_events_url":"https://api.github.com/users/auth0/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/auth0/Lock.Android","description":"Android Library to authenticate using Auth0 and with a Native Look & Feel","fork":false,"url":"https://api.github.com/repos/auth0/Lock.Android","forks_url":"https://api.github.com/repos/auth0/Lock.Android/forks","keys_url":"https://api.github.com/repos/auth0/Lock.Android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/auth0/Lock.Android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/auth0/Lock.Android/teams","hooks_url":"https://api.github.com/repos/auth0/Lock.Android/hooks","issue_events_url":"https://api.github.com/repos/auth0/Lock.Android/issues/events{/number}","events_url":"https://api.github.com/repos/auth0/Lock.Android/events","assignees_url":"https://api.github.com/repos/auth0/Lock.Android/assignees{/user}","branches_url":"https://api.github.com/repos/auth0/Lock.Android/branches{/branch}","tags_url":"https://api.github.com/repos/auth0/Lock.Android/tags","blobs_url":"https://api.github.com/repos/auth0/Lock.Android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/auth0/Lock.Android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/auth0/Lock.Android/git/refs{/sha}","trees_url":"https://api.github.com/repos/auth0/Lock.Android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/auth0/Lock.Android/statuses/{sha}","languages_url":"https://api.github.com/repos/auth0/Lock.Android/languages","stargazers_url":"https://api.github.com/repos/auth0/Lock.Android/stargazers","contributors_url":"https://api.github.com/repos/auth0/Lock.Android/contributors","subscribers_url":"https://api.github.com/repos/auth0/Lock.Android/subscribers","subscription_url":"https://api.github.com/repos/auth0/Lock.Android/subscription","commits_url":"https://api.github.com/repos/auth0/Lock.Android/commits{/sha}","git_commits_url":"https://api.github.com/repos/auth0/Lock.Android/git/commits{/sha}","comments_url":"https://api.github.com/repos/auth0/Lock.Android/comments{/number}","issue_comment_url":"https://api.github.com/repos/auth0/Lock.Android/issues/comments{/number}","contents_url":"https://api.github.com/repos/auth0/Lock.Android/contents/{+path}","compare_url":"https://api.github.com/repos/auth0/Lock.Android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/auth0/Lock.Android/merges","archive_url":"https://api.github.com/repos/auth0/Lock.Android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/auth0/Lock.Android/downloads","issues_url":"https://api.github.com/repos/auth0/Lock.Android/issues{/number}","pulls_url":"https://api.github.com/repos/auth0/Lock.Android/pulls{/number}","milestones_url":"https://api.github.com/repos/auth0/Lock.Android/milestones{/number}","notifications_url":"https://api.github.com/repos/auth0/Lock.Android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/auth0/Lock.Android/labels{/name}","releases_url":"https://api.github.com/repos/auth0/Lock.Android/releases{/id}","deployments_url":"https://api.github.com/repos/auth0/Lock.Android/deployments","created_at":"2014-12-02T22:13:43Z","updated_at":"2016-02-11T18:37:57Z","pushed_at":"2016-02-16T21:16:01Z","git_url":"git://github.com/auth0/Lock.Android.git","ssh_url":"git@github.com:auth0/Lock.Android.git","clone_url":"https://github.com/auth0/Lock.Android.git","svn_url":"https://github.com/auth0/Lock.Android","homepage":"https://auth0.com/lock","size":3284,"stargazers_count":30,"watchers_count":30,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":13,"forks":7,"open_issues":13,"watchers":30,"default_branch":"master"}},"base":{"label":"auth0:v2","ref":"v2","sha":"cc6a1ab68b98bfe08ede3d465db71533e7a6200d","user":{"login":"auth0","id":2824157,"avatar_url":"https://avatars.githubusercontent.com/u/2824157?v=3","gravatar_id":"","url":"https://api.github.com/users/auth0","html_url":"https://github.com/auth0","followers_url":"https://api.github.com/users/auth0/followers","following_url":"https://api.github.com/users/auth0/following{/other_user}","gists_url":"https://api.github.com/users/auth0/gists{/gist_id}","starred_url":"https://api.github.com/users/auth0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auth0/subscriptions","organizations_url":"https://api.github.com/users/auth0/orgs","repos_url":"https://api.github.com/users/auth0/repos","events_url":"https://api.github.com/users/auth0/events{/privacy}","received_events_url":"https://api.github.com/users/auth0/received_events","type":"Organization","site_admin":false},"repo":{"id":27456226,"name":"Lock.Android","full_name":"auth0/Lock.Android","owner":{"login":"auth0","id":2824157,"avatar_url":"https://avatars.githubusercontent.com/u/2824157?v=3","gravatar_id":"","url":"https://api.github.com/users/auth0","html_url":"https://github.com/auth0","followers_url":"https://api.github.com/users/auth0/followers","following_url":"https://api.github.com/users/auth0/following{/other_user}","gists_url":"https://api.github.com/users/auth0/gists{/gist_id}","starred_url":"https://api.github.com/users/auth0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/auth0/subscriptions","organizations_url":"https://api.github.com/users/auth0/orgs","repos_url":"https://api.github.com/users/auth0/repos","events_url":"https://api.github.com/users/auth0/events{/privacy}","received_events_url":"https://api.github.com/users/auth0/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/auth0/Lock.Android","description":"Android Library to authenticate using Auth0 and with a Native Look & Feel","fork":false,"url":"https://api.github.com/repos/auth0/Lock.Android","forks_url":"https://api.github.com/repos/auth0/Lock.Android/forks","keys_url":"https://api.github.com/repos/auth0/Lock.Android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/auth0/Lock.Android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/auth0/Lock.Android/teams","hooks_url":"https://api.github.com/repos/auth0/Lock.Android/hooks","issue_events_url":"https://api.github.com/repos/auth0/Lock.Android/issues/events{/number}","events_url":"https://api.github.com/repos/auth0/Lock.Android/events","assignees_url":"https://api.github.com/repos/auth0/Lock.Android/assignees{/user}","branches_url":"https://api.github.com/repos/auth0/Lock.Android/branches{/branch}","tags_url":"https://api.github.com/repos/auth0/Lock.Android/tags","blobs_url":"https://api.github.com/repos/auth0/Lock.Android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/auth0/Lock.Android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/auth0/Lock.Android/git/refs{/sha}","trees_url":"https://api.github.com/repos/auth0/Lock.Android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/auth0/Lock.Android/statuses/{sha}","languages_url":"https://api.github.com/repos/auth0/Lock.Android/languages","stargazers_url":"https://api.github.com/repos/auth0/Lock.Android/stargazers","contributors_url":"https://api.github.com/repos/auth0/Lock.Android/contributors","subscribers_url":"https://api.github.com/repos/auth0/Lock.Android/subscribers","subscription_url":"https://api.github.com/repos/auth0/Lock.Android/subscription","commits_url":"https://api.github.com/repos/auth0/Lock.Android/commits{/sha}","git_commits_url":"https://api.github.com/repos/auth0/Lock.Android/git/commits{/sha}","comments_url":"https://api.github.com/repos/auth0/Lock.Android/comments{/number}","issue_comment_url":"https://api.github.com/repos/auth0/Lock.Android/issues/comments{/number}","contents_url":"https://api.github.com/repos/auth0/Lock.Android/contents/{+path}","compare_url":"https://api.github.com/repos/auth0/Lock.Android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/auth0/Lock.Android/merges","archive_url":"https://api.github.com/repos/auth0/Lock.Android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/auth0/Lock.Android/downloads","issues_url":"https://api.github.com/repos/auth0/Lock.Android/issues{/number}","pulls_url":"https://api.github.com/repos/auth0/Lock.Android/pulls{/number}","milestones_url":"https://api.github.com/repos/auth0/Lock.Android/milestones{/number}","notifications_url":"https://api.github.com/repos/auth0/Lock.Android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/auth0/Lock.Android/labels{/name}","releases_url":"https://api.github.com/repos/auth0/Lock.Android/releases{/id}","deployments_url":"https://api.github.com/repos/auth0/Lock.Android/deployments","created_at":"2014-12-02T22:13:43Z","updated_at":"2016-02-11T18:37:57Z","pushed_at":"2016-02-16T21:16:01Z","git_url":"git://github.com/auth0/Lock.Android.git","ssh_url":"git@github.com:auth0/Lock.Android.git","clone_url":"https://github.com/auth0/Lock.Android.git","svn_url":"https://github.com/auth0/Lock.Android","homepage":"https://auth0.com/lock","size":3284,"stargazers_count":30,"watchers_count":30,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":13,"forks":7,"open_issues":13,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/200"},"html":{"href":"https://github.com/auth0/Lock.Android/pull/200"},"issue":{"href":"https://api.github.com/repos/auth0/Lock.Android/issues/200"},"comments":{"href":"https://api.github.com/repos/auth0/Lock.Android/issues/200/comments"},"review_comments":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/200/comments"},"review_comment":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/auth0/Lock.Android/pulls/200/commits"},"statuses":{"href":"https://api.github.com/repos/auth0/Lock.Android/statuses/ee1f2c66bed9a318d9204a2d1497234c3fc540ba"}}}}