You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2017/01/23 12:38:27 UTC

[1/2] ambari git commit: AMBARI-19664. Log Search: Snapshot tour fix & configurable CORS filter (oleewere)

Repository: ambari
Updated Branches:
  refs/heads/trunk 09c1894f7 -> b6b43785e


AMBARI-19664. Log Search: Snapshot tour fix & configurable CORS filter (oleewere)

Change-Id: I763e9ac69d1058f85a2be3a2aa036e008ff89b95


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9bd8b7f2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9bd8b7f2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9bd8b7f2

Branch: refs/heads/trunk
Commit: 9bd8b7f2ff1c7d2ca2cfd4bf8b0833a1bec98bb9
Parents: 09c1894
Author: oleewere <ol...@gmail.com>
Authored: Sun Jan 22 22:29:19 2017 +0100
Committer: oleewere <ol...@gmail.com>
Committed: Mon Jan 23 13:33:53 2017 +0100

----------------------------------------------------------------------
 .../conf/LogSearchHttpHeaderConfig.java         | 70 ++++++++++++++++++++
 .../ambari/logsearch/conf/SecurityConfig.java   | 11 +++
 .../web/filters/LogsearchCorsFilter.java        | 59 +++++++++++++++++
 .../src/main/webapp/scripts/utils/Tour.js       | 30 ++++-----
 4 files changed, 154 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9bd8b7f2/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
new file mode 100644
index 0000000..cb8c097
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpHeaderConfig.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.conf;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class LogSearchHttpHeaderConfig {
+
+  @Value("${logsearch.http.header.access-control-allow-origin:*}")
+  private String accessControlAllowOrigin;
+
+  @Value("${logsearch.http.header.access-control-allow-headers:origin, content-type, accept, authorization}")
+  private String accessControlAllowHeaders;
+
+  @Value("${logsearch.http.header.access-control-allow-credentials:true}")
+  private String accessControlAllowCredentials;
+
+  @Value("${logsearch.http.header.access-control-allow-methods:GET, POST, PUT, DELETE, OPTIONS, HEAD}")
+  private String accessControlAllowMethods;
+
+  public String getAccessControlAllowOrigin() {
+    return accessControlAllowOrigin;
+  }
+
+  public void setAccessControlAllowOrigin(String accessControlAllowOrigin) {
+    this.accessControlAllowOrigin = accessControlAllowOrigin;
+  }
+
+  public String getAccessControlAllowHeaders() {
+    return accessControlAllowHeaders;
+  }
+
+  public void setAccessControlAllowHeaders(String accessControlAllowHeaders) {
+    this.accessControlAllowHeaders = accessControlAllowHeaders;
+  }
+
+  public String getAccessControlAllowCredentials() {
+    return accessControlAllowCredentials;
+  }
+
+  public void setAccessControlAllowCredentials(String accessControlAllowCredentials) {
+    this.accessControlAllowCredentials = accessControlAllowCredentials;
+  }
+
+  public String getAccessControlAllowMethods() {
+    return accessControlAllowMethods;
+  }
+
+  public void setAccessControlAllowMethods(String accessControlAllowMethods) {
+    this.accessControlAllowMethods = accessControlAllowMethods;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/9bd8b7f2/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
index 115dcc3..b15ae43 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
@@ -25,6 +25,7 @@ import org.apache.ambari.logsearch.web.authenticate.LogsearchAuthSuccessHandler;
 import org.apache.ambari.logsearch.web.authenticate.LogsearchLogoutSuccessHandler;
 import org.apache.ambari.logsearch.web.filters.LogsearchAuditLogsStateFilter;
 import org.apache.ambari.logsearch.web.filters.LogsearchAuthenticationEntryPoint;
+import org.apache.ambari.logsearch.web.filters.LogsearchCorsFilter;
 import org.apache.ambari.logsearch.web.filters.LogsearchKRBAuthenticationFilter;
 import org.apache.ambari.logsearch.web.filters.LogsearchJWTFilter;
 import org.apache.ambari.logsearch.web.filters.LogsearchSecurityContextFormationFilter;
@@ -46,6 +47,7 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.servlet.Filter;
 import java.util.List;
 
 import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_SESSION_ID;
@@ -58,6 +60,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
   private AuthPropsConfig authPropsConfig;
 
   @Inject
+  private LogSearchHttpHeaderConfig logSearchHttpHeaderConfig;
+
+  @Inject
   private SolrServiceLogPropsConfig solrServiceLogPropsConfig;
 
   @Inject
@@ -104,6 +109,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
       .addFilterAfter(logsearchUserConfigFilter(), LogsearchSecurityContextFormationFilter.class)
       .addFilterAfter(logsearchAuditLogFilter(), LogsearchSecurityContextFormationFilter.class)
       .addFilterAfter(logsearchServiceLogFilter(), LogsearchSecurityContextFormationFilter.class)
+      .addFilterBefore(corsFilter(), LogsearchSecurityContextFormationFilter.class)
       .addFilterBefore(logsearchJwtFilter(), LogsearchSecurityContextFormationFilter.class)
       .logout()
         .logoutUrl("/logout.html")
@@ -112,6 +118,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
   }
 
   @Bean
+  public LogsearchCorsFilter corsFilter() {
+    return new LogsearchCorsFilter(logSearchHttpHeaderConfig);
+  }
+
+  @Bean
   public LogsearchSecurityContextFormationFilter securityContextFormationFilter() {
     return new LogsearchSecurityContextFormationFilter();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/9bd8b7f2/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchCorsFilter.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchCorsFilter.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchCorsFilter.java
new file mode 100644
index 0000000..f5e7bca
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/filters/LogsearchCorsFilter.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ambari.logsearch.web.filters;
+
+import org.apache.ambari.logsearch.conf.LogSearchHttpHeaderConfig;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class LogsearchCorsFilter implements Filter {
+
+  private LogSearchHttpHeaderConfig logSearchHttpHeaderConfig;
+
+  public LogsearchCorsFilter(LogSearchHttpHeaderConfig logSearchHttpHeaderConfig) {
+    this.logSearchHttpHeaderConfig = logSearchHttpHeaderConfig;
+  }
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+    throws IOException, ServletException {
+    HttpServletResponse response = (HttpServletResponse) servletResponse;
+    response.setHeader("Access-Control-Allow-Origin", logSearchHttpHeaderConfig.getAccessControlAllowOrigin());
+    response.setHeader("Access-Control-Allow-Headers", logSearchHttpHeaderConfig.getAccessControlAllowHeaders());
+    response.setHeader("Access-Control-Allow-Credentials", logSearchHttpHeaderConfig.getAccessControlAllowCredentials());
+    response.setHeader("Access-Control-Allow-Methods", logSearchHttpHeaderConfig.getAccessControlAllowMethods());
+    filterChain.doFilter(servletRequest, servletResponse);
+  }
+
+  @Override
+  public void destroy() {
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/9bd8b7f2/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Tour.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Tour.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Tour.js
index fff82ed..f9d093b 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Tour.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Tour.js
@@ -56,6 +56,10 @@ define(['require', 'tour'], function (require, TourJs) {
         content: "This filter allows you to filter the log data depending upon the component selection. Include Component is again \"or\" condition and Exclude Component is \"and\" condition between multiple selection.",
         placement: "bottom"
       }, {
+        element: $('[data-id="startStop"]').get(0),
+        content: "Snapshot helps you quickly see all logs generated while you reproduce an issue. Click start, reproduce your issue, click stop and we'll load all logs that were produced during that time frame.",
+        placement: "bottom"
+      }, {
         element: $('#r_Histogram').get(0),
         content: "Histogram displays comparative ratios of log severity during the currently defined time filter.",
         placement: "top"
@@ -64,10 +68,6 @@ define(['require', 'tour'], function (require, TourJs) {
         content: "The Log Data default view displays consolidated for all hosts.",
         placement: "top",
       }, {
-        element: 'a[data-id="timerBtn"]',
-        content: "Snapshot helps you quickly see all logs generated while you reproduce an issue. Click start, reproduce your issue, click stop and we'll load all logs that were produced during that time frame.",
-        placement: "top"
-      }, {
         element: document.querySelectorAll('#r_BubbleTable')[1],
         content: "Expand the Log Data tree view and choose components to further refine your diagnostics.",
         placement: "top",
@@ -146,8 +146,6 @@ define(['require', 'tour'], function (require, TourJs) {
         } else if (tour._state.current_step == 6) {
         } else if (tour._state.current_step == 7) {
           appendFingerAndOverlayDiv(tour._options.showFinger[tour._state.current_step]);
-        } else if (tour._state.current_step == 8) {
-          appendFingerAndOverlayDiv(tour._options.showFinger[tour._state.current_step]);
         } else if (tour._state.current_step == 9) {
           appendFingerAndOverlayDiv(tour._options.showFinger[tour._state.current_step]);
         } else if (tour._state.current_step == 10) {
@@ -257,26 +255,26 @@ define(['require', 'tour'], function (require, TourJs) {
       },
       8: {
         css: {
-          'top': '45px',
-          'left': '122px'
+          'top': '30px',
+          'left': '309px'
         },
-        handDirection: 'up',
+        handDirection: 'down',
         handClass: "up-down"
       },
       9: {
         css: {
           'top': '45px',
-          'left': '100px'
+          'left': '122px'
         },
-        appendIndex: 0,
-        handDirection: 'down',
+        handDirection: 'up',
         handClass: "up-down"
       },
       10: {
         css: {
-          'top': '30px',
-          'left': '309px'
+          'top': '45px',
+          'left': '100px'
         },
+        appendIndex: 0,
         handDirection: 'down',
         handClass: "up-down"
       },
@@ -396,13 +394,13 @@ define(['require', 'tour'], function (require, TourJs) {
         $('#r_BubbleTable input[value="H"]').click();
         removeFingerAndOverlayDiv();
       } else if (tour._state.current_step == 8) {
-        $('#r_BubbleTable li[data-parent="true"]').first().find('span[data-state="collapse"]').first().click();
-        $('#r_BubbleTable li[data-parent="true"]').first().find('a[data-type="C"]').first().removeClass('hidden');
         removeFingerAndOverlayDiv();
       } else if (tour._state.current_step == 9) {
+        $('#r_BubbleTable li[data-parent="true"]').first().find('span[data-state="collapse"]').first().click();
         $('#r_BubbleTable li[data-parent="true"]').first().find('a[data-type="C"]').first().removeClass('hidden');
         removeFingerAndOverlayDiv();
       } else if (tour._state.current_step == 10) {
+        $('#r_BubbleTable li[data-parent="true"]').first().find('a[data-type="C"]').first().removeClass('hidden');
         removeFingerAndOverlayDiv();
       } else if (tour._state.current_step == 11) {
         $('#r_BubbleTable input[value="T"]').click();


[2/2] ambari git commit: AMBARI-19665. Add basic auth support for Log Search Swagger UI (oleewere)

Posted by ol...@apache.org.
AMBARI-19665. Add basic auth support for Log Search Swagger UI (oleewere)

Change-Id: I369d3e994e178a98a1a925bb32fdb400232f71d4


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b6b43785
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b6b43785
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b6b43785

Branch: refs/heads/trunk
Commit: b6b43785ea2f335734a647771cb468ccf89da06b
Parents: 9bd8b7f
Author: oleewere <ol...@gmail.com>
Authored: Mon Jan 23 11:32:08 2017 +0100
Committer: oleewere <ol...@gmail.com>
Committed: Mon Jan 23 13:33:54 2017 +0100

----------------------------------------------------------------------
 .../ambari/logsearch/conf/ApiDocConfig.java     |  1 -
 .../src/main/resources/swagger/swagger.html     | 26 +++++++++-----------
 2 files changed, 11 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b6b43785/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
index 0ddad65..86c1edd 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
@@ -45,7 +45,6 @@ public class ApiDocConfig {
   public BeanConfig swaggerConfig() throws UnknownHostException {
     BeanConfig beanConfig = new BeanConfig();
     beanConfig.setSchemes(new String[]{"http", "https"});
-    beanConfig.setHost(InetAddress.getLocalHost().getHostAddress() + ":61888"); // TODO: port from property
     beanConfig.setBasePath("/api/v1");
     beanConfig.setTitle("Log Search REST API");
     beanConfig.setDescription("Log aggregation, analysis, and visualization.");

http://git-wip-us.apache.org/repos/asf/ambari/blob/b6b43785/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
index e1b052a..33346d3 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
@@ -17,7 +17,7 @@
 -->
 <html>
 <head>
-    <title>Swagger UI</title>
+    <title>Log Search REST API</title>
     <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
     <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
     <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
@@ -43,7 +43,7 @@
             if (url && url.length > 1) {
                 url = decodeURIComponent(url[1]);
             } else {
-                var urlPrefix = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
+                var urlPrefix = location.protocol +'//'+ location.hostname+(location.port ? ':'+location.port: '');
                 url = urlPrefix + "/api/v1/swagger.yaml";
             }
             window.swaggerUi = new SwaggerUi({
@@ -74,21 +74,16 @@
             });
 
             function addApiKeyAuthorization(){
-                var key = encodeURIComponent($('#input_apiKey')[0].value);
-                if(key && key.trim() != "") {
-                    var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
-                    window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
-                    log("added key " + key);
+                var username = encodeURIComponent($('#input_username')[0].value);
+                var password = encodeURIComponent($('#input_password')[0].value);
+                if (username && username.trim() != "" && password && password != "") {
+                    var apiKeyAuth = new SwaggerClient.PasswordAuthorization("Authorization", username, password);
+                    window.swaggerUi.api.clientAuthorizations.add("key", apiKeyAuth);
+                    log("added authorization header: " + 'Basic ' + btoa(username + ':' + password));
                 }
             }
 
-            $('#input_apiKey').change(addApiKeyAuthorization);
-
-            // if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
-            /*
-             var apiKey = "myApiKeyXXXX123456789";
-             $('#input_apiKey').val(apiKey);
-             */
+            $('#input_username, #input_password').change(addApiKeyAuthorization);
 
             window.swaggerUi.load();
 
@@ -107,7 +102,8 @@
         <a id="logo" href="http://swagger.io">swagger</a>
         <form id='api_selector'>
             <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
-            <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
+            <div class="input"><input placeholder="username" id="input_username" name="username" type="text" size="10"></div>
+            <div class="input"><input placeholder="password" id="input_password" name="password" type="password" size="10"></div>
             <div class='input'><a id="explore" href="#">Explore</a></div>
         </form>
     </div>