{"action":"created","comment":{"url":"https://api.github.com/repos/Wikia/pandora/pulls/comments/28166895","id":28166895,"diff_hunk":"@@ -0,0 +1,84 @@\n+package com.wikia.pandora.core.auth;\n+\n+import org.apache.shiro.authc.AuthenticationToken;\n+import org.apache.shiro.authz.UnauthenticatedException;\n+import org.apache.shiro.web.filter.authc.AuthenticatingFilter;\n+import org.apache.shiro.web.util.WebUtils;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.Optional;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import javax.servlet.ServletRequest;\n+import javax.servlet.ServletResponse;\n+import javax.servlet.http.HttpServletRequest;\n+\n+/**\n+ * ServiceAuthenticatingFilter will create an AuthenticationToken with the Bearer token so it can be\n+ * authenticated against Helios.\n+ */\n+public class ServiceAuthenticatingFilter extends AuthenticatingFilter {\n+\n+  private static final Logger log = LoggerFactory.getLogger(ServiceAuthenticatingFilter.class);\n+\n+  /**\n+   * HTTP Authorization header, equal to <code>Authorization</code>\n+   */\n+  protected static final String AUTHORIZATION_HEADER = \"Authorization\";\n+\n+\n+  @Override\n+  protected AuthenticationToken createToken(ServletRequest request, ServletResponse response)\n+      throws Exception {\n+    String authorizationHeader = getAuthzHeader(request);\n+    if (authorizationHeader == null || authorizationHeader.length() == 0) {\n+      // Create an empty authentication token since there is no\n+      // Authorization header.\n+      return createToken(\"\", request, response);\n+    }\n+\n+    if (log.isDebugEnabled()) {\n+      log.debug(\"Attempting to execute login with headers [\" + authorizationHeader + \"]\");\n+    }\n+\n+    Optional<String>\n+        optionalAuthenticationToken = getAuthenticationCredentials(authorizationHeader);\n+\n+    return optionalAuthenticationToken\n+        .map(authorizationToken -> createToken(authorizationToken, request, response))\n+        .orElseGet(() -> createToken(\"\", request, response));\n+  }\n+\n+  @Override\n+  protected boolean onAccessDenied(ServletRequest request, ServletResponse response)\n+      throws Exception {\n+    boolean isAuthenticated = false; //false by default or we wouldn't be in this method\n+    isAuthenticated = executeLogin(request, response);","path":"lib/service-core/src/main/java/com/wikia/pandora/core/auth/ServiceAuthenticatingFilter.java","position":58,"original_position":58,"commit_id":"7ac103bfcffdf9100d1bf81bcf91ae4e3c8cb94e","original_commit_id":"7ac103bfcffdf9100d1bf81bcf91ae4e3c8cb94e","user":{"login":"jogura","id":907775,"avatar_url":"https://avatars.githubusercontent.com/u/907775?v=3","gravatar_id":"","url":"https://api.github.com/users/jogura","html_url":"https://github.com/jogura","followers_url":"https://api.github.com/users/jogura/followers","following_url":"https://api.github.com/users/jogura/following{/other_user}","gists_url":"https://api.github.com/users/jogura/gists{/gist_id}","starred_url":"https://api.github.com/users/jogura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jogura/subscriptions","organizations_url":"https://api.github.com/users/jogura/orgs","repos_url":"https://api.github.com/users/jogura/repos","events_url":"https://api.github.com/users/jogura/events{/privacy}","received_events_url":"https://api.github.com/users/jogura/received_events","type":"User","site_admin":false},"body":"This is part of the Shiro framework, not much we can do about it.","created_at":"2015-04-10T18:05:15Z","updated_at":"2015-04-10T18:05:15Z","html_url":"https://github.com/Wikia/pandora/pull/152#discussion_r28166895","pull_request_url":"https://api.github.com/repos/Wikia/pandora/pulls/152","_links":{"self":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/comments/28166895"},"html":{"href":"https://github.com/Wikia/pandora/pull/152#discussion_r28166895"},"pull_request":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/152"}}},"pull_request":{"url":"https://api.github.com/repos/Wikia/pandora/pulls/152","id":32997105,"html_url":"https://github.com/Wikia/pandora/pull/152","diff_url":"https://github.com/Wikia/pandora/pull/152.diff","patch_url":"https://github.com/Wikia/pandora/pull/152.patch","issue_url":"https://api.github.com/repos/Wikia/pandora/issues/152","number":152,"state":"open","locked":false,"title":"Initial checkin of Shiro framework for Authn/Authz for Discussion Service","user":{"login":"jogura","id":907775,"avatar_url":"https://avatars.githubusercontent.com/u/907775?v=3","gravatar_id":"","url":"https://api.github.com/users/jogura","html_url":"https://github.com/jogura","followers_url":"https://api.github.com/users/jogura/followers","following_url":"https://api.github.com/users/jogura/following{/other_user}","gists_url":"https://api.github.com/users/jogura/gists{/gist_id}","starred_url":"https://api.github.com/users/jogura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jogura/subscriptions","organizations_url":"https://api.github.com/users/jogura/orgs","repos_url":"https://api.github.com/users/jogura/repos","events_url":"https://api.github.com/users/jogura/events{/privacy}","received_events_url":"https://api.github.com/users/jogura/received_events","type":"User","site_admin":false},"body":"This PR introduces the [Apache Shiro](http://shiro.apache.org) framework to handle Authn/Authz for the discussion service. The idea is to introduce an abstract `ServiceRealm` that will understand how to authenticate against Helios (using the Bearer tokens) and return the user's information as principals for the user. The principals will be used to retrieve the user's group information which can be used by the concrete class to fetch Service specific permissions.  \r\n**NOTE: Neither of those pieces have been implement as of yet but maybe coming shortly.** \r\n\r\nThe resources have been protected declaratively using the Shiro provided [JAX-RS annotations](http://shiro.apache.org/java-annotations-list.html).\r\n\r\n**NOTE: In the near future there maybe an Authentication Proxy that may replace this**\r\n\r\nRFCR @cmiller-wikia @drsnyder @pchojnacki @nmonterroso @jimmordino @armonr et al\r\n\r\nMore commit details:\r\n* Create an abstract `ServiceRealm` that *will* in the near future interact with Helios for AuthN and some yet-to-be-created service for user group\r\nsubclasses of this realm must implement the `getAdditionalPermissions()` to add Service specific permissions\r\n* Update the \"Resources\" with jax-rs annotations to declare the required Roles and Permissions access to the Resource's methods\r\n* Configure shiro to have a security filter that checks for Bearer token and creates the appropriate token for the `ServiceRealm` implementation\r\n* Refactored to use `ServiceExceptionMapper`\r\n* Add unit and integration tests","created_at":"2015-04-09T21:15:02Z","updated_at":"2015-04-10T18:05:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d907117bcd94ecc2d87a7919bf94c81da34cebda","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wikia/pandora/pulls/152/commits","review_comments_url":"https://api.github.com/repos/Wikia/pandora/pulls/152/comments","review_comment_url":"https://api.github.com/repos/Wikia/pandora/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wikia/pandora/issues/152/comments","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/7ac103bfcffdf9100d1bf81bcf91ae4e3c8cb94e","head":{"label":"Wikia:DIS-16_authorization","ref":"DIS-16_authorization","sha":"7ac103bfcffdf9100d1bf81bcf91ae4e3c8cb94e","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":26663749,"name":"pandora","full_name":"Wikia/pandora","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/pandora","description":"API Service","fork":false,"url":"https://api.github.com/repos/Wikia/pandora","forks_url":"https://api.github.com/repos/Wikia/pandora/forks","keys_url":"https://api.github.com/repos/Wikia/pandora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/pandora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/pandora/teams","hooks_url":"https://api.github.com/repos/Wikia/pandora/hooks","issue_events_url":"https://api.github.com/repos/Wikia/pandora/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/pandora/events","assignees_url":"https://api.github.com/repos/Wikia/pandora/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/pandora/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/pandora/tags","blobs_url":"https://api.github.com/repos/Wikia/pandora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/pandora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/pandora/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/pandora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/pandora/languages","stargazers_url":"https://api.github.com/repos/Wikia/pandora/stargazers","contributors_url":"https://api.github.com/repos/Wikia/pandora/contributors","subscribers_url":"https://api.github.com/repos/Wikia/pandora/subscribers","subscription_url":"https://api.github.com/repos/Wikia/pandora/subscription","commits_url":"https://api.github.com/repos/Wikia/pandora/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/pandora/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/pandora/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/pandora/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/pandora/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/pandora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/pandora/merges","archive_url":"https://api.github.com/repos/Wikia/pandora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/pandora/downloads","issues_url":"https://api.github.com/repos/Wikia/pandora/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/pandora/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/pandora/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/pandora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/pandora/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/pandora/releases{/id}","created_at":"2014-11-15T00:29:06Z","updated_at":"2015-04-10T10:51:47Z","pushed_at":"2015-04-10T17:34:34Z","git_url":"git://github.com/Wikia/pandora.git","ssh_url":"git@github.com:Wikia/pandora.git","clone_url":"https://github.com/Wikia/pandora.git","svn_url":"https://github.com/Wikia/pandora","homepage":null,"size":7515,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":3,"default_branch":"master"}},"base":{"label":"Wikia:master","ref":"master","sha":"a695850b52f20f021c9d6a3e108f3a422af97f35","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":26663749,"name":"pandora","full_name":"Wikia/pandora","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/pandora","description":"API Service","fork":false,"url":"https://api.github.com/repos/Wikia/pandora","forks_url":"https://api.github.com/repos/Wikia/pandora/forks","keys_url":"https://api.github.com/repos/Wikia/pandora/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/pandora/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/pandora/teams","hooks_url":"https://api.github.com/repos/Wikia/pandora/hooks","issue_events_url":"https://api.github.com/repos/Wikia/pandora/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/pandora/events","assignees_url":"https://api.github.com/repos/Wikia/pandora/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/pandora/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/pandora/tags","blobs_url":"https://api.github.com/repos/Wikia/pandora/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/pandora/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/pandora/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/pandora/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/pandora/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/pandora/languages","stargazers_url":"https://api.github.com/repos/Wikia/pandora/stargazers","contributors_url":"https://api.github.com/repos/Wikia/pandora/contributors","subscribers_url":"https://api.github.com/repos/Wikia/pandora/subscribers","subscription_url":"https://api.github.com/repos/Wikia/pandora/subscription","commits_url":"https://api.github.com/repos/Wikia/pandora/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/pandora/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/pandora/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/pandora/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/pandora/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/pandora/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/pandora/merges","archive_url":"https://api.github.com/repos/Wikia/pandora/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/pandora/downloads","issues_url":"https://api.github.com/repos/Wikia/pandora/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/pandora/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/pandora/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/pandora/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/pandora/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/pandora/releases{/id}","created_at":"2014-11-15T00:29:06Z","updated_at":"2015-04-10T10:51:47Z","pushed_at":"2015-04-10T17:34:34Z","git_url":"git://github.com/Wikia/pandora.git","ssh_url":"git@github.com:Wikia/pandora.git","clone_url":"https://github.com/Wikia/pandora.git","svn_url":"https://github.com/Wikia/pandora","homepage":null,"size":7515,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/152"},"html":{"href":"https://github.com/Wikia/pandora/pull/152"},"issue":{"href":"https://api.github.com/repos/Wikia/pandora/issues/152"},"comments":{"href":"https://api.github.com/repos/Wikia/pandora/issues/152/comments"},"review_comments":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/152/comments"},"review_comment":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wikia/pandora/pulls/152/commits"},"statuses":{"href":"https://api.github.com/repos/Wikia/pandora/statuses/7ac103bfcffdf9100d1bf81bcf91ae4e3c8cb94e"}}}}