{"action":"created","comment":{"url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/comments/40950332","id":40950332,"diff_hunk":"@@ -0,0 +1,96 @@\n+/**\n+ * Copyright (C) 2015 Red Hat, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * 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, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package io.fabric8.elasticsearch.plugin;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.elasticsearch.common.logging.ESLogger;\n+import org.elasticsearch.common.netty.handler.codec.http.HttpRequest;\n+import org.elasticsearch.common.settings.Settings;\n+import org.elasticsearch.http.netty.NettyHttpRequest;\n+import org.elasticsearch.rest.RestChannel;\n+import org.elasticsearch.rest.RestFilter;\n+import org.elasticsearch.rest.RestFilterChain;\n+import org.elasticsearch.rest.RestRequest;\n+\n+public class KibanaUserReindexFilter extends RestFilter {\n+\n+\tprivate final ESLogger logger;\n+\tprivate final String proxyUserHeader;\n+\tprivate final String kibanaIndex;\n+\n+\tpublic KibanaUserReindexFilter(final Settings settings, final ESLogger logger){\n+\t\tthis.logger = logger;\n+\t\tthis.proxyUserHeader = settings.get(ConfigurationSettings.SEARCHGUARD_AUTHENTICATION_PROXY_HEADER, \n+\t\t\t\tConfigurationSettings.DEFAULT_AUTH_PROXY_HEADER);\n+\t\tthis.kibanaIndex = settings.get(ConfigurationSettings.KIBANA_CONFIG_INDEX_NAME, \n+\t\t\t\tConfigurationSettings.KIBANA_CONFIG_INDEX_NAME);\n+\t}\n+\t\n+\t@Override\n+\tpublic void process(RestRequest request, RestChannel channel, RestFilterChain chain) throws Exception {\n+\t\ttry {\n+\t\t\tlogger.debug(\"Handling Request in Kibana User Reindex filter...\");\n+\t\t\tfinal String user = getUser(request);\n+\t\t\tfinal String requestedIndex = getRequestedIndex(request);\n+\t\t\t\n+\t\t\tif ( StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(requestedIndex) && requestedIndex.equalsIgnoreCase(kibanaIndex)) {\n+\t\t\t\tString userIndex = requestedIndex + \".\" + user;\n+\t\t\t\tlogger.debug(\"Matched for a kibana user header, will set to '{}' for user '{}'\", userIndex, user);\n+\t\t\t\t\n+\t\t\t\t//update the request URI here\n+\t\t\t\trequest = updateRequestIndex(request, requestedIndex, userIndex);\n+\t\t\t\t\n+\t\t\t\tlogger.debug(\"URI for request is '{}' after update\", request.uri());\n+\t\t\t}\n+\n+\t\t} catch (Exception e) {\n+\t\t\tlogger.error(\"Error handling request in OpenShift SearchGuard filter\", e);\n+\t\t} finally {\n+\t\t\tchain.continueProcessing(request, channel);\n+\t\t}\n+\t}\n+\n+\tprivate String getUser(RestRequest request) {\n+\t\treturn StringUtils.defaultIfBlank(request.header(proxyUserHeader), \"\");\n+\t}\n+\t\n+\tprivate RestRequest updateRequestIndex(RestRequest request, String oldIndex, String newIndex) {\n+\t\tString uri = request.uri();\n+\t\tString replaced = uri.replace(oldIndex, newIndex);","path":"src/main/java/io/fabric8/elasticsearch/plugin/KibanaUserReindexFilter.java","position":72,"original_position":72,"commit_id":"414d24615745e81e1ff74a9859806e6f2a1b87be","original_commit_id":"414d24615745e81e1ff74a9859806e6f2a1b87be","user":{"login":"sosiouxme","id":29690,"avatar_url":"https://avatars.githubusercontent.com/u/29690?v=3","gravatar_id":"","url":"https://api.github.com/users/sosiouxme","html_url":"https://github.com/sosiouxme","followers_url":"https://api.github.com/users/sosiouxme/followers","following_url":"https://api.github.com/users/sosiouxme/following{/other_user}","gists_url":"https://api.github.com/users/sosiouxme/gists{/gist_id}","starred_url":"https://api.github.com/users/sosiouxme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sosiouxme/subscriptions","organizations_url":"https://api.github.com/users/sosiouxme/orgs","repos_url":"https://api.github.com/users/sosiouxme/repos","events_url":"https://api.github.com/users/sosiouxme/events{/privacy}","received_events_url":"https://api.github.com/users/sosiouxme/received_events","type":"User","site_admin":false},"body":"Can't find the java docs on this... does this replace the value in a URI-safe way? In case the user name has characters that need escaping.","created_at":"2015-10-01T18:41:25Z","updated_at":"2015-10-01T18:41:25Z","html_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10#discussion_r40950332","pull_request_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/comments/40950332"},"html":{"href":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10#discussion_r40950332"},"pull_request":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10","id":46465266,"html_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10","diff_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10.diff","patch_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10.patch","issue_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/10","number":10,"state":"open","locked":false,"title":"Created RestFilter and ActionFilter to update requests to the .kibana…","user":{"login":"ewolinetz","id":1427473,"avatar_url":"https://avatars.githubusercontent.com/u/1427473?v=3","gravatar_id":"","url":"https://api.github.com/users/ewolinetz","html_url":"https://github.com/ewolinetz","followers_url":"https://api.github.com/users/ewolinetz/followers","following_url":"https://api.github.com/users/ewolinetz/following{/other_user}","gists_url":"https://api.github.com/users/ewolinetz/gists{/gist_id}","starred_url":"https://api.github.com/users/ewolinetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewolinetz/subscriptions","organizations_url":"https://api.github.com/users/ewolinetz/orgs","repos_url":"https://api.github.com/users/ewolinetz/repos","events_url":"https://api.github.com/users/ewolinetz/events{/privacy}","received_events_url":"https://api.github.com/users/ewolinetz/received_events","type":"User","site_admin":false},"body":"… index to create user profiles and responses to map back to .kibana","created_at":"2015-09-30T22:28:12Z","updated_at":"2015-10-01T18:41:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bad6a0cdaef5c962cc95bd7262e9eb711926cce0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10/commits","review_comments_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10/comments","review_comment_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/10/comments","statuses_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/statuses/414d24615745e81e1ff74a9859806e6f2a1b87be","head":{"label":"ewolinetz:kibana-user","ref":"kibana-user","sha":"414d24615745e81e1ff74a9859806e6f2a1b87be","user":{"login":"ewolinetz","id":1427473,"avatar_url":"https://avatars.githubusercontent.com/u/1427473?v=3","gravatar_id":"","url":"https://api.github.com/users/ewolinetz","html_url":"https://github.com/ewolinetz","followers_url":"https://api.github.com/users/ewolinetz/followers","following_url":"https://api.github.com/users/ewolinetz/following{/other_user}","gists_url":"https://api.github.com/users/ewolinetz/gists{/gist_id}","starred_url":"https://api.github.com/users/ewolinetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewolinetz/subscriptions","organizations_url":"https://api.github.com/users/ewolinetz/orgs","repos_url":"https://api.github.com/users/ewolinetz/repos","events_url":"https://api.github.com/users/ewolinetz/events{/privacy}","received_events_url":"https://api.github.com/users/ewolinetz/received_events","type":"User","site_admin":false},"repo":{"id":43313612,"name":"openshift-elasticsearch-plugin","full_name":"ewolinetz/openshift-elasticsearch-plugin","owner":{"login":"ewolinetz","id":1427473,"avatar_url":"https://avatars.githubusercontent.com/u/1427473?v=3","gravatar_id":"","url":"https://api.github.com/users/ewolinetz","html_url":"https://github.com/ewolinetz","followers_url":"https://api.github.com/users/ewolinetz/followers","following_url":"https://api.github.com/users/ewolinetz/following{/other_user}","gists_url":"https://api.github.com/users/ewolinetz/gists{/gist_id}","starred_url":"https://api.github.com/users/ewolinetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewolinetz/subscriptions","organizations_url":"https://api.github.com/users/ewolinetz/orgs","repos_url":"https://api.github.com/users/ewolinetz/repos","events_url":"https://api.github.com/users/ewolinetz/events{/privacy}","received_events_url":"https://api.github.com/users/ewolinetz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ewolinetz/openshift-elasticsearch-plugin","description":null,"fork":true,"url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin","forks_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/forks","keys_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/teams","hooks_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/hooks","issue_events_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/events","assignees_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/tags","blobs_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/languages","stargazers_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/stargazers","contributors_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/contributors","subscribers_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/subscribers","subscription_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/subscription","commits_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/merges","archive_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/downloads","issues_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/labels{/name}","releases_url":"https://api.github.com/repos/ewolinetz/openshift-elasticsearch-plugin/releases{/id}","created_at":"2015-09-28T16:46:42Z","updated_at":"2015-09-28T16:46:43Z","pushed_at":"2015-10-01T18:28:22Z","git_url":"git://github.com/ewolinetz/openshift-elasticsearch-plugin.git","ssh_url":"git@github.com:ewolinetz/openshift-elasticsearch-plugin.git","clone_url":"https://github.com/ewolinetz/openshift-elasticsearch-plugin.git","svn_url":"https://github.com/ewolinetz/openshift-elasticsearch-plugin","homepage":null,"size":377,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fabric8io:master","ref":"master","sha":"396715dbb94a4722c70f676d162d0e54a6674ce6","user":{"login":"fabric8io","id":6074349,"avatar_url":"https://avatars.githubusercontent.com/u/6074349?v=3","gravatar_id":"","url":"https://api.github.com/users/fabric8io","html_url":"https://github.com/fabric8io","followers_url":"https://api.github.com/users/fabric8io/followers","following_url":"https://api.github.com/users/fabric8io/following{/other_user}","gists_url":"https://api.github.com/users/fabric8io/gists{/gist_id}","starred_url":"https://api.github.com/users/fabric8io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabric8io/subscriptions","organizations_url":"https://api.github.com/users/fabric8io/orgs","repos_url":"https://api.github.com/users/fabric8io/repos","events_url":"https://api.github.com/users/fabric8io/events{/privacy}","received_events_url":"https://api.github.com/users/fabric8io/received_events","type":"Organization","site_admin":false},"repo":{"id":41058701,"name":"openshift-elasticsearch-plugin","full_name":"fabric8io/openshift-elasticsearch-plugin","owner":{"login":"fabric8io","id":6074349,"avatar_url":"https://avatars.githubusercontent.com/u/6074349?v=3","gravatar_id":"","url":"https://api.github.com/users/fabric8io","html_url":"https://github.com/fabric8io","followers_url":"https://api.github.com/users/fabric8io/followers","following_url":"https://api.github.com/users/fabric8io/following{/other_user}","gists_url":"https://api.github.com/users/fabric8io/gists{/gist_id}","starred_url":"https://api.github.com/users/fabric8io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabric8io/subscriptions","organizations_url":"https://api.github.com/users/fabric8io/orgs","repos_url":"https://api.github.com/users/fabric8io/repos","events_url":"https://api.github.com/users/fabric8io/events{/privacy}","received_events_url":"https://api.github.com/users/fabric8io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin","description":null,"fork":false,"url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin","forks_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/forks","keys_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/teams","hooks_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/hooks","issue_events_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/events","assignees_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/tags","blobs_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/languages","stargazers_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/stargazers","contributors_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/contributors","subscribers_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/subscribers","subscription_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/subscription","commits_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/merges","archive_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/downloads","issues_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/labels{/name}","releases_url":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/releases{/id}","created_at":"2015-08-19T20:37:42Z","updated_at":"2015-09-28T16:27:43Z","pushed_at":"2015-10-01T18:28:23Z","git_url":"git://github.com/fabric8io/openshift-elasticsearch-plugin.git","ssh_url":"git@github.com:fabric8io/openshift-elasticsearch-plugin.git","clone_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin.git","svn_url":"https://github.com/fabric8io/openshift-elasticsearch-plugin","homepage":null,"size":377,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10"},"html":{"href":"https://github.com/fabric8io/openshift-elasticsearch-plugin/pull/10"},"issue":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/10"},"comments":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/fabric8io/openshift-elasticsearch-plugin/statuses/414d24615745e81e1ff74a9859806e6f2a1b87be"}}}}