{"action":"created","comment":{"url":"https://api.github.com/repos/Talend/components/pulls/comments/136597174","pull_request_review_id":60162757,"id":136597174,"diff_hunk":"@@ -0,0 +1,165 @@\n+// ============================================================================\n+//\n+// Copyright (C) 2006-2017 Talend Inc. - www.talend.com\n+//\n+// This source code is available under agreement available at\n+// %InstallDIR%\\features\\org.talend.rcp.branding.%PRODUCTNAME%\\%PRODUCTNAME%license.txt\n+//\n+// You should have received a copy of the agreement\n+// along with this program; if not, write to Talend SA\n+// 9 rue Pages 92150 Suresnes, France\n+//\n+// ============================================================================\n+package org.talend.components.common.oauth.server;\n+\n+import java.io.BufferedReader;\n+import java.io.IOException;\n+import java.io.InputStreamReader;\n+import java.io.OutputStreamWriter;\n+import java.io.UnsupportedEncodingException;\n+import java.net.InetAddress;\n+import java.net.ServerSocket;\n+import java.net.Socket;\n+import java.net.URLDecoder;\n+import java.util.Date;\n+\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * A simple http server to retrieve authorization code in OAuth 2 implicit flow.\n+ * This server handle only one connection then stop listening for farther incoming connections\n+ */\n+public class SimpleTalendHttpServer implements Runnable {\n+\n+    private static final String serverName = \"Talend/Oauth2/0.0.1\";\n+\n+    private int timeout;\n+\n+    private String host;\n+\n+    private int port;\n+\n+    private ServerSocket server;\n+\n+    private String authorizationCode;\n+\n+    private static final String CRLF = \"\\r\\n\";\n+\n+    private static final String[] supportedCodeParams = { \"code\" };\n+\n+    /** Requested maximum length of the queue of incoming connections. */\n+    private static final int backlog = 5;\n+\n+    private static final Logger logger = LoggerFactory.getLogger(SimpleTalendHttpServer.class.getCanonicalName());\n+\n+    /**\n+     * @param host\n+     * @param port\n+     */\n+    public SimpleTalendHttpServer(String host, int port, int timeOut) {\n+        super();\n+        this.host = host;\n+        this.port = port;\n+        this.timeout = timeOut;\n+    }\n+\n+    @Override\n+    public void run() {\n+\n+        try {\n+            InetAddress addr = InetAddress.getByName(host);\n+            server = new ServerSocket(port, backlog, addr);\n+            logger.info(\"Talend HTTP Server started and listening on \" + port);\n+\n+            while (true) {\n+                authorizationCode = null;\n+                server.setSoTimeout(timeout);\n+                try (Socket clientSocket = server.accept()) {\n+                    BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));\n+                    String line;\n+                    while ((line = reader.readLine()) != null && !line.isEmpty()) {\n+                        logger.trace(\"<< \" + line);\n+                        if (validGetRequestLine(line)) {\n+                            authorizationCode = extractAuthorizationCode(line);\n+                        }\n+\n+                        if (authorizationCode != null) {\n+                            break;\n+                        }\n+                    }\n+\n+                    OutputStreamWriter osw = new OutputStreamWriter(clientSocket.getOutputStream());\n+                    Date now = new Date();\n+                    String response = \"\";\n+                    if (authorizationCode == null) {\n+                        response = \"<h1>ERROR 500</h1><p>Can't retrieve authorization code</p>\";\n+                        osw.write(\"HTTP/1.0 500 Can't retrieve authorization code\" + CRLF);\n+                    } else {\n+                        response = \"<p>Authorization code extracted successfully!</p>\";\n+                        osw.write(\"HTTP/1.0 200 OK\" + CRLF);\n+                    }\n+                    osw.write(\"Date:\" + now + CRLF);\n+                    osw.write(\"Server: \" + serverName + CRLF);\n+                    osw.write(\"Content-Type: text/html\" + CRLF);\n+                    osw.write(\"Content-Length:\" + response.length() + CRLF);\n+                    osw.write(\"\\r\\n\");\n+                    osw.write(response);\n+                    osw.flush();\n+                    logger.info(\"Talend Server stoped listening for incoming connections\");\n+                    break; // stop listening for connection\n+                }\n+            }\n+        } catch (IOException e) {\n+            throw new RuntimeException(e);\n+        }","path":"core/components-common-oauth/src/main/java/org/talend/components/common/oauth/server/SimpleTalendHttpServer.java","position":115,"original_position":115,"commit_id":"b77dab83078344c3c5ca0a6001cf20aadc6f703d","original_commit_id":"b77dab83078344c3c5ca0a6001cf20aadc6f703d","user":{"login":"akhabali","id":25590305,"avatar_url":"https://avatars3.githubusercontent.com/u/25590305?v=4","gravatar_id":"","url":"https://api.github.com/users/akhabali","html_url":"https://github.com/akhabali","followers_url":"https://api.github.com/users/akhabali/followers","following_url":"https://api.github.com/users/akhabali/following{/other_user}","gists_url":"https://api.github.com/users/akhabali/gists{/gist_id}","starred_url":"https://api.github.com/users/akhabali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhabali/subscriptions","organizations_url":"https://api.github.com/users/akhabali/orgs","repos_url":"https://api.github.com/users/akhabali/repos","events_url":"https://api.github.com/users/akhabali/events{/privacy}","received_events_url":"https://api.github.com/users/akhabali/received_events","type":"User","site_admin":false},"body":"try with resource handle the close here ","created_at":"2017-09-01T15:08:58Z","updated_at":"2017-09-01T15:08:58Z","html_url":"https://github.com/Talend/components/pull/930#discussion_r136597174","pull_request_url":"https://api.github.com/repos/Talend/components/pulls/930","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Talend/components/pulls/comments/136597174"},"html":{"href":"https://github.com/Talend/components/pull/930#discussion_r136597174"},"pull_request":{"href":"https://api.github.com/repos/Talend/components/pulls/930"}},"in_reply_to_id":136593544},"pull_request":{"url":"https://api.github.com/repos/Talend/components/pulls/930","id":136431470,"html_url":"https://github.com/Talend/components/pull/930","diff_url":"https://github.com/Talend/components/pull/930.diff","patch_url":"https://github.com/Talend/components/pull/930.patch","issue_url":"https://api.github.com/repos/Talend/components/issues/930","number":930,"state":"open","locked":false,"title":"feat(TDI-39278): refactor common auth","user":{"login":"akhabali","id":25590305,"avatar_url":"https://avatars3.githubusercontent.com/u/25590305?v=4","gravatar_id":"","url":"https://api.github.com/users/akhabali","html_url":"https://github.com/akhabali","followers_url":"https://api.github.com/users/akhabali/followers","following_url":"https://api.github.com/users/akhabali/following{/other_user}","gists_url":"https://api.github.com/users/akhabali/gists{/gist_id}","starred_url":"https://api.github.com/users/akhabali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhabali/subscriptions","organizations_url":"https://api.github.com/users/akhabali/orgs","repos_url":"https://api.github.com/users/akhabali/repos","events_url":"https://api.github.com/users/akhabali/events{/privacy}","received_events_url":"https://api.github.com/users/akhabali/received_events","type":"User","site_admin":false},"body":"\r\n\r\n**What is the current behavior?** (You can also link to an open issue here)\r\nhttps://jira.talendforge.org/browse/TDI-39278\r\n\r\n\r\n**What is the new behavior?**\r\n- Add jwt with assertion flow (a flow adapted for server to server communication)\r\n- Integrate the flow for salesforce\r\n\r\n\r\n**Please check if the PR fulfills these requirements**\r\n\r\n- [ ] The commit message follows Talend standard\r\n- [ ] Tests for the changes have been added (for bug fixes / features)\r\n- [ ] Docs have been added / updated (for bug fixes / features) ?\r\n- [ ] The code coverage on new code >75%\r\n- [ ] The new code does not introduce new technical issues (sonar / eslint)\r\n\r\n**What kind of change does this PR introduce?**\r\n\r\n- [ ] Bugfix\r\n- [ ] Feature\r\n- [ ] Code style update (formatting, local variables)\r\n- [ ] Refactoring (no functional changes, no api changes)\r\n- [ ] Build / CI related changes\r\n- [ ] Other... Please describe:\r\n\r\n**Does this PR introduce a breaking change?**\r\n\r\n- [ ] Yes\r\n- [ ] No\r\n\r\nIf this PR contains a breaking change, please describe the impact and migration path for existing applications: ...\r\n\r\n\r\n**Other information**:\r\n","created_at":"2017-08-18T08:55:43Z","updated_at":"2017-09-01T15:08:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d7f1f16f1494c62242d7fe3c03dd139525a407f","assignee":null,"assignees":[],"requested_reviewers":[{"login":"undx","id":265575,"avatar_url":"https://avatars3.githubusercontent.com/u/265575?v=4","gravatar_id":"","url":"https://api.github.com/users/undx","html_url":"https://github.com/undx","followers_url":"https://api.github.com/users/undx/followers","following_url":"https://api.github.com/users/undx/following{/other_user}","gists_url":"https://api.github.com/users/undx/gists{/gist_id}","starred_url":"https://api.github.com/users/undx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/undx/subscriptions","organizations_url":"https://api.github.com/users/undx/orgs","repos_url":"https://api.github.com/users/undx/repos","events_url":"https://api.github.com/users/undx/events{/privacy}","received_events_url":"https://api.github.com/users/undx/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Talend/components/pulls/930/commits","review_comments_url":"https://api.github.com/repos/Talend/components/pulls/930/comments","review_comment_url":"https://api.github.com/repos/Talend/components/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Talend/components/issues/930/comments","statuses_url":"https://api.github.com/repos/Talend/components/statuses/b77dab83078344c3c5ca0a6001cf20aadc6f703d","head":{"label":"Talend:akhabali/oauth-server-flows","ref":"akhabali/oauth-server-flows","sha":"b77dab83078344c3c5ca0a6001cf20aadc6f703d","user":{"login":"Talend","id":459687,"avatar_url":"https://avatars2.githubusercontent.com/u/459687?v=4","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"repo":{"id":39855061,"name":"components","full_name":"Talend/components","owner":{"login":"Talend","id":459687,"avatar_url":"https://avatars2.githubusercontent.com/u/459687?v=4","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Talend/components","description":"Talend component infrastructure and public components","fork":false,"url":"https://api.github.com/repos/Talend/components","forks_url":"https://api.github.com/repos/Talend/components/forks","keys_url":"https://api.github.com/repos/Talend/components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Talend/components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Talend/components/teams","hooks_url":"https://api.github.com/repos/Talend/components/hooks","issue_events_url":"https://api.github.com/repos/Talend/components/issues/events{/number}","events_url":"https://api.github.com/repos/Talend/components/events","assignees_url":"https://api.github.com/repos/Talend/components/assignees{/user}","branches_url":"https://api.github.com/repos/Talend/components/branches{/branch}","tags_url":"https://api.github.com/repos/Talend/components/tags","blobs_url":"https://api.github.com/repos/Talend/components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Talend/components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Talend/components/git/refs{/sha}","trees_url":"https://api.github.com/repos/Talend/components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Talend/components/statuses/{sha}","languages_url":"https://api.github.com/repos/Talend/components/languages","stargazers_url":"https://api.github.com/repos/Talend/components/stargazers","contributors_url":"https://api.github.com/repos/Talend/components/contributors","subscribers_url":"https://api.github.com/repos/Talend/components/subscribers","subscription_url":"https://api.github.com/repos/Talend/components/subscription","commits_url":"https://api.github.com/repos/Talend/components/commits{/sha}","git_commits_url":"https://api.github.com/repos/Talend/components/git/commits{/sha}","comments_url":"https://api.github.com/repos/Talend/components/comments{/number}","issue_comment_url":"https://api.github.com/repos/Talend/components/issues/comments{/number}","contents_url":"https://api.github.com/repos/Talend/components/contents/{+path}","compare_url":"https://api.github.com/repos/Talend/components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Talend/components/merges","archive_url":"https://api.github.com/repos/Talend/components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Talend/components/downloads","issues_url":"https://api.github.com/repos/Talend/components/issues{/number}","pulls_url":"https://api.github.com/repos/Talend/components/pulls{/number}","milestones_url":"https://api.github.com/repos/Talend/components/milestones{/number}","notifications_url":"https://api.github.com/repos/Talend/components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Talend/components/labels{/name}","releases_url":"https://api.github.com/repos/Talend/components/releases{/id}","deployments_url":"https://api.github.com/repos/Talend/components/deployments","created_at":"2015-07-28T20:02:50Z","updated_at":"2017-08-26T17:54:40Z","pushed_at":"2017-09-01T13:38:43Z","git_url":"git://github.com/Talend/components.git","ssh_url":"git@github.com:Talend/components.git","clone_url":"https://github.com/Talend/components.git","svn_url":"https://github.com/Talend/components","homepage":null,"size":14389,"stargazers_count":15,"watchers_count":15,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":16,"forks":34,"open_issues":16,"watchers":15,"default_branch":"master"}},"base":{"label":"Talend:master","ref":"master","sha":"2c1504750ed4ba69f81d1b49f40c9da9eb355b90","user":{"login":"Talend","id":459687,"avatar_url":"https://avatars2.githubusercontent.com/u/459687?v=4","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"repo":{"id":39855061,"name":"components","full_name":"Talend/components","owner":{"login":"Talend","id":459687,"avatar_url":"https://avatars2.githubusercontent.com/u/459687?v=4","gravatar_id":"","url":"https://api.github.com/users/Talend","html_url":"https://github.com/Talend","followers_url":"https://api.github.com/users/Talend/followers","following_url":"https://api.github.com/users/Talend/following{/other_user}","gists_url":"https://api.github.com/users/Talend/gists{/gist_id}","starred_url":"https://api.github.com/users/Talend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Talend/subscriptions","organizations_url":"https://api.github.com/users/Talend/orgs","repos_url":"https://api.github.com/users/Talend/repos","events_url":"https://api.github.com/users/Talend/events{/privacy}","received_events_url":"https://api.github.com/users/Talend/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Talend/components","description":"Talend component infrastructure and public components","fork":false,"url":"https://api.github.com/repos/Talend/components","forks_url":"https://api.github.com/repos/Talend/components/forks","keys_url":"https://api.github.com/repos/Talend/components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Talend/components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Talend/components/teams","hooks_url":"https://api.github.com/repos/Talend/components/hooks","issue_events_url":"https://api.github.com/repos/Talend/components/issues/events{/number}","events_url":"https://api.github.com/repos/Talend/components/events","assignees_url":"https://api.github.com/repos/Talend/components/assignees{/user}","branches_url":"https://api.github.com/repos/Talend/components/branches{/branch}","tags_url":"https://api.github.com/repos/Talend/components/tags","blobs_url":"https://api.github.com/repos/Talend/components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Talend/components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Talend/components/git/refs{/sha}","trees_url":"https://api.github.com/repos/Talend/components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Talend/components/statuses/{sha}","languages_url":"https://api.github.com/repos/Talend/components/languages","stargazers_url":"https://api.github.com/repos/Talend/components/stargazers","contributors_url":"https://api.github.com/repos/Talend/components/contributors","subscribers_url":"https://api.github.com/repos/Talend/components/subscribers","subscription_url":"https://api.github.com/repos/Talend/components/subscription","commits_url":"https://api.github.com/repos/Talend/components/commits{/sha}","git_commits_url":"https://api.github.com/repos/Talend/components/git/commits{/sha}","comments_url":"https://api.github.com/repos/Talend/components/comments{/number}","issue_comment_url":"https://api.github.com/repos/Talend/components/issues/comments{/number}","contents_url":"https://api.github.com/repos/Talend/components/contents/{+path}","compare_url":"https://api.github.com/repos/Talend/components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Talend/components/merges","archive_url":"https://api.github.com/repos/Talend/components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Talend/components/downloads","issues_url":"https://api.github.com/repos/Talend/components/issues{/number}","pulls_url":"https://api.github.com/repos/Talend/components/pulls{/number}","milestones_url":"https://api.github.com/repos/Talend/components/milestones{/number}","notifications_url":"https://api.github.com/repos/Talend/components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Talend/components/labels{/name}","releases_url":"https://api.github.com/repos/Talend/components/releases{/id}","deployments_url":"https://api.github.com/repos/Talend/components/deployments","created_at":"2015-07-28T20:02:50Z","updated_at":"2017-08-26T17:54:40Z","pushed_at":"2017-09-01T13:38:43Z","git_url":"git://github.com/Talend/components.git","ssh_url":"git@github.com:Talend/components.git","clone_url":"https://github.com/Talend/components.git","svn_url":"https://github.com/Talend/components","homepage":null,"size":14389,"stargazers_count":15,"watchers_count":15,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":16,"forks":34,"open_issues":16,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Talend/components/pulls/930"},"html":{"href":"https://github.com/Talend/components/pull/930"},"issue":{"href":"https://api.github.com/repos/Talend/components/issues/930"},"comments":{"href":"https://api.github.com/repos/Talend/components/issues/930/comments"},"review_comments":{"href":"https://api.github.com/repos/Talend/components/pulls/930/comments"},"review_comment":{"href":"https://api.github.com/repos/Talend/components/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Talend/components/pulls/930/commits"},"statuses":{"href":"https://api.github.com/repos/Talend/components/statuses/b77dab83078344c3c5ca0a6001cf20aadc6f703d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"akhabali"}}