{"action":"created","comment":{"url":"https://api.github.com/repos/aduprat/james-project/pulls/comments/49747232","id":49747232,"diff_hunk":"@@ -0,0 +1,85 @@\n+/****************************************************************\n+ * Licensed to the Apache Software Foundation (ASF) under one   *\n+ * or more contributor license agreements.  See the NOTICE file *\n+ * distributed with this work for additional information        *\n+ * regarding copyright ownership.  The ASF licenses this file   *\n+ * to you under the Apache License, Version 2.0 (the            *\n+ * \"License\"); you may not use this file except in compliance   *\n+ * with the License.  You may obtain a copy of the License at   *\n+ *                                                              *\n+ *   http://www.apache.org/licenses/LICENSE-2.0                 *\n+ *                                                              *\n+ * Unless required by applicable law or agreed to in writing,   *\n+ * software distributed under the License is distributed on an  *\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *\n+ * KIND, either express or implied.  See the License for the    *\n+ * specific language governing permissions and limitations      *\n+ * under the License.                                           *\n+ ****************************************************************/\n+package org.apache.james.jmap;\n+\n+import com.google.common.annotations.VisibleForTesting;\n+import org.apache.james.jmap.api.AccessTokenManager;\n+import org.apache.james.jmap.api.access.AccessToken;\n+import org.apache.james.jmap.exceptions.MailboxCreationException;\n+import org.apache.james.jmap.api.access.exceptions.NotAnAccessTokenException;\n+import org.apache.james.mailbox.MailboxManager;\n+import org.apache.james.mailbox.MailboxSession;\n+import org.apache.james.mailbox.exception.MailboxException;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import javax.inject.Inject;\n+import java.util.Optional;\n+import java.util.stream.Stream;\n+\n+public class AccessTokenAuthenticationStrategy implements AuthenticationStrategy {\n+\n+    private static final Logger LOG = LoggerFactory.getLogger(AccessTokenAuthenticationStrategy.class);\n+\n+    private final AccessTokenManager accessTokenManager;\n+    private final MailboxManager mailboxManager;\n+\n+    @Inject\n+    @VisibleForTesting\n+    AccessTokenAuthenticationStrategy(AccessTokenManager accessTokenManager, MailboxManager mailboxManager) {\n+        this.accessTokenManager = accessTokenManager;\n+        this.mailboxManager = mailboxManager;\n+    }\n+\n+    @Override\n+    public Optional<MailboxSession> createMailboxSession(Stream<String> authHeaders) {\n+\n+        return authHeaders\n+                .map(AccessToken::fromString)\n+                .map(accessTokenManager::getUsernameFromToken)\n+                .findFirst()\n+                .map(user -> {\n+                    try {\n+                        return mailboxManager.createSystemSession(user, LOG);\n+                    } catch (MailboxException e) {\n+                        throw new MailboxCreationException(e);\n+                    }\n+                });\n+    }\n+\n+    @Override\n+    public boolean checkAuthorizationHeader(Stream<String> authHeaders) {","path":"server/protocols/jmap/src/main/java/org/apache/james/jmap/AccessTokenAuthenticationStrategy.java","position":67,"original_position":67,"commit_id":"a8dbd055d1b976645bfee456d55382577050817b","original_commit_id":"a8dbd055d1b976645bfee456d55382577050817b","user":{"login":"mbaechler","id":708318,"avatar_url":"https://avatars.githubusercontent.com/u/708318?v=3","gravatar_id":"","url":"https://api.github.com/users/mbaechler","html_url":"https://github.com/mbaechler","followers_url":"https://api.github.com/users/mbaechler/followers","following_url":"https://api.github.com/users/mbaechler/following{/other_user}","gists_url":"https://api.github.com/users/mbaechler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechler/subscriptions","organizations_url":"https://api.github.com/users/mbaechler/orgs","repos_url":"https://api.github.com/users/mbaechler/repos","events_url":"https://api.github.com/users/mbaechler/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechler/received_events","type":"User","site_admin":false},"body":"is  there tests with several auth headers ?","created_at":"2016-01-14T16:23:14Z","updated_at":"2016-01-14T16:23:14Z","html_url":"https://github.com/aduprat/james-project/pull/3#discussion_r49747232","pull_request_url":"https://api.github.com/repos/aduprat/james-project/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/comments/49747232"},"html":{"href":"https://github.com/aduprat/james-project/pull/3#discussion_r49747232"},"pull_request":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/aduprat/james-project/pulls/3","id":55765615,"html_url":"https://github.com/aduprat/james-project/pull/3","diff_url":"https://github.com/aduprat/james-project/pull/3.diff","patch_url":"https://github.com/aduprat/james-project/pull/3.patch","issue_url":"https://api.github.com/repos/aduprat/james-project/issues/3","number":3,"state":"open","locked":false,"title":"JAMES-1652 add JwtTokenVerifier for JMAP","user":{"login":"fvn-linagora","id":15813847,"avatar_url":"https://avatars.githubusercontent.com/u/15813847?v=3","gravatar_id":"","url":"https://api.github.com/users/fvn-linagora","html_url":"https://github.com/fvn-linagora","followers_url":"https://api.github.com/users/fvn-linagora/followers","following_url":"https://api.github.com/users/fvn-linagora/following{/other_user}","gists_url":"https://api.github.com/users/fvn-linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/fvn-linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fvn-linagora/subscriptions","organizations_url":"https://api.github.com/users/fvn-linagora/orgs","repos_url":"https://api.github.com/users/fvn-linagora/repos","events_url":"https://api.github.com/users/fvn-linagora/events{/privacy}","received_events_url":"https://api.github.com/users/fvn-linagora/received_events","type":"User","site_admin":false},"body":"** Note: this PR is replacing the previous https://github.com/aduprat/james-project/pull/2\r\ncommits history removed, and no fix applied (yet) following comments on previous PR. **\r\n\r\nextract check and session creation into new interface AuthenticationStrategy with default impl.\r\nadd AllowAllCrossOriginRequests with hardcoded cross origin request sharing (CORS) headers sent\r\nexclude OPTIONS request from being authenticated.\r\nadd some integration test for jmap auth (ignored some jmap integration test methods that would require a full CORS impl. to pass.)\r\nadd public key to TestJMAPServerModule for running integration tests","created_at":"2016-01-12T14:37:58Z","updated_at":"2016-01-14T16:23:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"331ed129c7a416b90f90ac217af5f47c5b1b56df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aduprat/james-project/pulls/3/commits","review_comments_url":"https://api.github.com/repos/aduprat/james-project/pulls/3/comments","review_comment_url":"https://api.github.com/repos/aduprat/james-project/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aduprat/james-project/issues/3/comments","statuses_url":"https://api.github.com/repos/aduprat/james-project/statuses/a8dbd055d1b976645bfee456d55382577050817b","head":{"label":"fvn-linagora:JWTAuth","ref":"JWTAuth","sha":"a8dbd055d1b976645bfee456d55382577050817b","user":{"login":"fvn-linagora","id":15813847,"avatar_url":"https://avatars.githubusercontent.com/u/15813847?v=3","gravatar_id":"","url":"https://api.github.com/users/fvn-linagora","html_url":"https://github.com/fvn-linagora","followers_url":"https://api.github.com/users/fvn-linagora/followers","following_url":"https://api.github.com/users/fvn-linagora/following{/other_user}","gists_url":"https://api.github.com/users/fvn-linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/fvn-linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fvn-linagora/subscriptions","organizations_url":"https://api.github.com/users/fvn-linagora/orgs","repos_url":"https://api.github.com/users/fvn-linagora/repos","events_url":"https://api.github.com/users/fvn-linagora/events{/privacy}","received_events_url":"https://api.github.com/users/fvn-linagora/received_events","type":"User","site_admin":false},"repo":{"id":46065537,"name":"james-project","full_name":"fvn-linagora/james-project","owner":{"login":"fvn-linagora","id":15813847,"avatar_url":"https://avatars.githubusercontent.com/u/15813847?v=3","gravatar_id":"","url":"https://api.github.com/users/fvn-linagora","html_url":"https://github.com/fvn-linagora","followers_url":"https://api.github.com/users/fvn-linagora/followers","following_url":"https://api.github.com/users/fvn-linagora/following{/other_user}","gists_url":"https://api.github.com/users/fvn-linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/fvn-linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fvn-linagora/subscriptions","organizations_url":"https://api.github.com/users/fvn-linagora/orgs","repos_url":"https://api.github.com/users/fvn-linagora/repos","events_url":"https://api.github.com/users/fvn-linagora/events{/privacy}","received_events_url":"https://api.github.com/users/fvn-linagora/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fvn-linagora/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/fvn-linagora/james-project","forks_url":"https://api.github.com/repos/fvn-linagora/james-project/forks","keys_url":"https://api.github.com/repos/fvn-linagora/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fvn-linagora/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fvn-linagora/james-project/teams","hooks_url":"https://api.github.com/repos/fvn-linagora/james-project/hooks","issue_events_url":"https://api.github.com/repos/fvn-linagora/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/fvn-linagora/james-project/events","assignees_url":"https://api.github.com/repos/fvn-linagora/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/fvn-linagora/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/fvn-linagora/james-project/tags","blobs_url":"https://api.github.com/repos/fvn-linagora/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fvn-linagora/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fvn-linagora/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/fvn-linagora/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fvn-linagora/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/fvn-linagora/james-project/languages","stargazers_url":"https://api.github.com/repos/fvn-linagora/james-project/stargazers","contributors_url":"https://api.github.com/repos/fvn-linagora/james-project/contributors","subscribers_url":"https://api.github.com/repos/fvn-linagora/james-project/subscribers","subscription_url":"https://api.github.com/repos/fvn-linagora/james-project/subscription","commits_url":"https://api.github.com/repos/fvn-linagora/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/fvn-linagora/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/fvn-linagora/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/fvn-linagora/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/fvn-linagora/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/fvn-linagora/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fvn-linagora/james-project/merges","archive_url":"https://api.github.com/repos/fvn-linagora/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fvn-linagora/james-project/downloads","issues_url":"https://api.github.com/repos/fvn-linagora/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/fvn-linagora/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/fvn-linagora/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/fvn-linagora/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fvn-linagora/james-project/labels{/name}","releases_url":"https://api.github.com/repos/fvn-linagora/james-project/releases{/id}","created_at":"2015-11-12T16:28:28Z","updated_at":"2015-11-12T16:28:36Z","pushed_at":"2016-01-14T15:54:48Z","git_url":"git://github.com/fvn-linagora/james-project.git","ssh_url":"git@github.com:fvn-linagora/james-project.git","clone_url":"https://github.com/fvn-linagora/james-project.git","svn_url":"https://github.com/fvn-linagora/james-project","homepage":null,"size":9316,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"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":"trunk"}},"base":{"label":"aduprat:JAMES-1652","ref":"JAMES-1652","sha":"573e9dbfc50a96f7a963cb71fc7e4ee8dbc6ee28","user":{"login":"aduprat","id":2900528,"avatar_url":"https://avatars.githubusercontent.com/u/2900528?v=3","gravatar_id":"","url":"https://api.github.com/users/aduprat","html_url":"https://github.com/aduprat","followers_url":"https://api.github.com/users/aduprat/followers","following_url":"https://api.github.com/users/aduprat/following{/other_user}","gists_url":"https://api.github.com/users/aduprat/gists{/gist_id}","starred_url":"https://api.github.com/users/aduprat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduprat/subscriptions","organizations_url":"https://api.github.com/users/aduprat/orgs","repos_url":"https://api.github.com/users/aduprat/repos","events_url":"https://api.github.com/users/aduprat/events{/privacy}","received_events_url":"https://api.github.com/users/aduprat/received_events","type":"User","site_admin":false},"repo":{"id":39448317,"name":"james-project","full_name":"aduprat/james-project","owner":{"login":"aduprat","id":2900528,"avatar_url":"https://avatars.githubusercontent.com/u/2900528?v=3","gravatar_id":"","url":"https://api.github.com/users/aduprat","html_url":"https://github.com/aduprat","followers_url":"https://api.github.com/users/aduprat/followers","following_url":"https://api.github.com/users/aduprat/following{/other_user}","gists_url":"https://api.github.com/users/aduprat/gists{/gist_id}","starred_url":"https://api.github.com/users/aduprat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduprat/subscriptions","organizations_url":"https://api.github.com/users/aduprat/orgs","repos_url":"https://api.github.com/users/aduprat/repos","events_url":"https://api.github.com/users/aduprat/events{/privacy}","received_events_url":"https://api.github.com/users/aduprat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aduprat/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/aduprat/james-project","forks_url":"https://api.github.com/repos/aduprat/james-project/forks","keys_url":"https://api.github.com/repos/aduprat/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aduprat/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aduprat/james-project/teams","hooks_url":"https://api.github.com/repos/aduprat/james-project/hooks","issue_events_url":"https://api.github.com/repos/aduprat/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/aduprat/james-project/events","assignees_url":"https://api.github.com/repos/aduprat/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/aduprat/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/aduprat/james-project/tags","blobs_url":"https://api.github.com/repos/aduprat/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aduprat/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aduprat/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/aduprat/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aduprat/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/aduprat/james-project/languages","stargazers_url":"https://api.github.com/repos/aduprat/james-project/stargazers","contributors_url":"https://api.github.com/repos/aduprat/james-project/contributors","subscribers_url":"https://api.github.com/repos/aduprat/james-project/subscribers","subscription_url":"https://api.github.com/repos/aduprat/james-project/subscription","commits_url":"https://api.github.com/repos/aduprat/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/aduprat/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/aduprat/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/aduprat/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/aduprat/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/aduprat/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aduprat/james-project/merges","archive_url":"https://api.github.com/repos/aduprat/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aduprat/james-project/downloads","issues_url":"https://api.github.com/repos/aduprat/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/aduprat/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/aduprat/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/aduprat/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aduprat/james-project/labels{/name}","releases_url":"https://api.github.com/repos/aduprat/james-project/releases{/id}","created_at":"2015-07-21T13:55:14Z","updated_at":"2016-01-13T10:07:40Z","pushed_at":"2016-01-14T15:54:49Z","git_url":"git://github.com/aduprat/james-project.git","ssh_url":"git@github.com:aduprat/james-project.git","clone_url":"https://github.com/aduprat/james-project.git","svn_url":"https://github.com/aduprat/james-project","homepage":null,"size":9892,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/3"},"html":{"href":"https://github.com/aduprat/james-project/pull/3"},"issue":{"href":"https://api.github.com/repos/aduprat/james-project/issues/3"},"comments":{"href":"https://api.github.com/repos/aduprat/james-project/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aduprat/james-project/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/aduprat/james-project/statuses/a8dbd055d1b976645bfee456d55382577050817b"}}}}