knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject knox git commit: KNOX-879 - Fix url encoding issue for KnoxSSO
Date Thu, 16 Feb 2017 01:57:16 GMT
Repository: knox
Updated Branches:
  refs/heads/master 6b6865ddc -> d187a877c


KNOX-879 - Fix url encoding issue for KnoxSSO


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

Branch: refs/heads/master
Commit: d187a877cd9fac4cf8c203c0bc2cfb1fcc774b73
Parents: 6b6865d
Author: Sandeep More <more@apache.org>
Authored: Wed Feb 15 20:57:08 2017 -0500
Committer: Sandeep More <more@apache.org>
Committed: Wed Feb 15 20:57:08 2017 -0500

----------------------------------------------------------------------
 .../gateway/service/knoxsso/WebSSOutResource.java     | 14 +++++++-------
 .../java/org/apache/hadoop/gateway/util/Urls.java     |  9 ++++++---
 .../java/org/apache/hadoop/gateway/util/UrlsTest.java |  6 ++++++
 3 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/d187a877/gateway-service-knoxssout/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOutResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-knoxssout/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOutResource.java
b/gateway-service-knoxssout/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOutResource.java
index e082eb1..cfc9af6 100644
--- a/gateway-service-knoxssout/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOutResource.java
+++ b/gateway-service-knoxssout/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOutResource.java
@@ -17,6 +17,9 @@
  */
 package org.apache.hadoop.gateway.service.knoxsso;
 
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.util.Urls;
+
 import javax.annotation.PostConstruct;
 import javax.servlet.ServletContext;
 import javax.servlet.http.Cookie;
@@ -28,22 +31,19 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
-import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
-import org.apache.hadoop.gateway.util.Urls;
+import java.net.MalformedURLException;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static javax.ws.rs.core.MediaType.APPLICATION_XML;
 import static javax.ws.rs.core.Response.ok;
 
-import java.net.URISyntaxException;
-
 @Path( WebSSOutResource.RESOURCE_PATH )
 public class WebSSOutResource {
   private static final String JWT_COOKIE_NAME = "hadoop-jwt";
   static final String RESOURCE_PATH = "/api/v1/webssout";
   static final String KNOXSSO_RESOURCE_PATH = "/api/v1/websso";
   private static KnoxSSOutMessages log = MessagesFactory.get( KnoxSSOutMessages.class );
-  
+
   private String domainSuffix = null;
 
   @Context
@@ -88,7 +88,7 @@ public class WebSSOutResource {
     c.setPath("/");
     try {
       c.setDomain(Urls.getDomainName(request.getRequestURL().toString(), domainSuffix));
-    } catch (URISyntaxException e) {
+    } catch (MalformedURLException e) {
       log.problemWithCookieDomainUsingDefault();
       // we are probably not going to be able to
       // remove the cookie due to this error but it
@@ -96,7 +96,7 @@ public class WebSSOutResource {
       rc = false;
     }
     response.addCookie(c);
-    
+
     return rc;
   }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/d187a877/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/Urls.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/Urls.java b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/Urls.java
index f10b0d6..cae9c11 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/Urls.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/Urls.java
@@ -18,8 +18,10 @@
 package org.apache.hadoop.gateway.util;
 
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -81,9 +83,10 @@ public class Urls {
    * @return the extracted domain name
    * @throws URISyntaxException
    */
-  public static String getDomainName(String url, String domainSuffix) throws URISyntaxException
{
-    URI uri = new URI(url);
-    String domain = uri.getHost();
+  public static String getDomainName(String url, String domainSuffix) throws MalformedURLException
{
+
+    final URL originalUrl = new URL(url);
+    final String domain = originalUrl.getHost();
 
     // if the hostname ends with the domainSuffix the use the domainSuffix as
     // the cookie domain

http://git-wip-us.apache.org/repos/asf/knox/blob/d187a877/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java
index 3b1e9cc..7c14ef8 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/UrlsTest.java
@@ -55,6 +55,12 @@ public class UrlsTest {
 
     // ip addresses can not be wildcarded - may be a completely different domain
     Assert.assertEquals(Urls.getDomainName("http://127.0.0.1", null), null);
+
+    /* Make sure we handle encoded characters properly here */
+    Assert.assertTrue(Urls.getDomainName("https://www.local.com:8443/gateway/manager/admin-ui?limit=25&query=hive_table+where+name%3D%22table_1%22",
null).equals(".local.com"));
+    /* Make sure we handle un-encoded characters safely */
+    Assert.assertTrue(Urls.getDomainName("https://www.local.com:8443/gateway/manager/admin-ui/?limit=25&query=\"table_1\"",
null).equals(".local.com"));
+
   }
 
   @Test


Mime
View raw message