sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lsk...@apache.org
Subject incubator-sentry git commit: SENTRY-422: The URI object handling needs to be more robust (Colin Ma via Lenni Kuff)
Date Sat, 06 Dec 2014 08:36:47 GMT
Repository: incubator-sentry
Updated Branches:
  refs/heads/master 2d3ff339c -> a2b6184d2


SENTRY-422: The URI object handling needs to be more robust (Colin Ma via Lenni Kuff)


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

Branch: refs/heads/master
Commit: a2b6184d2e6cf05f039140684b64e52271330505
Parents: 2d3ff33
Author: Lenni Kuff <lskuff@cloudera.com>
Authored: Sat Dec 6 00:36:12 2014 -0800
Committer: Lenni Kuff <lskuff@cloudera.com>
Committed: Sat Dec 6 00:36:12 2014 -0800

----------------------------------------------------------------------
 sentry-core/sentry-core-model-db/pom.xml        |  5 ++++-
 .../apache/sentry/core/model/db/AccessURI.java  | 22 +++++++++++++++-----
 .../java/org/apache/sentry/core/db/TestURI.java | 11 ++++++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a2b6184d/sentry-core/sentry-core-model-db/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-db/pom.xml b/sentry-core/sentry-core-model-db/pom.xml
index 9cfe3df..43ce4b8 100644
--- a/sentry-core/sentry-core-model-db/pom.xml
+++ b/sentry-core/sentry-core-model-db/pom.xml
@@ -32,7 +32,10 @@ limitations under the License.
       <groupId>org.apache.sentry</groupId>
       <artifactId>sentry-core-common</artifactId>
     </dependency>
-
+	<dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-common</artifactId>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a2b6184d/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/AccessURI.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/AccessURI.java
b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/AccessURI.java
index 8e44026..600a82f 100644
--- a/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/AccessURI.java
+++ b/sentry-core/sentry-core-model-db/src/main/java/org/apache/sentry/core/model/db/AccessURI.java
@@ -16,21 +16,33 @@
  */
 package org.apache.sentry.core.model.db;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.fs.Path;
+
 public class AccessURI implements DBModelAuthorizable {
   /**
    * Represents all URIs
    */
   public static final AccessURI ALL = new AccessURI(AccessConstants.ALL);
+  private static final String AUTHORITY_PREFIX = "://";
 
   private final String uriName;
 
-
+  /**
+   * Wrap a URI which can be HDFS, S3, SWIFT, WEBHDFS,etc. Do the validation for the URI's
format.
+   */
   public AccessURI(String uriName) {
     uriName = uriName == null ? "" : uriName;
-    if(!(uriName.equals(AccessConstants.ALL) ||
-        uriName.startsWith("file://") ||
-        uriName.startsWith("hdfs://"))) {
-      throw new IllegalArgumentException("URI '" + uriName + "' in invalid. Must start with
file:// or hdfs://");
+    if (!uriName.equals(AccessConstants.ALL)) {
+      Path uriPath = new Path(uriName);
+      String schema = uriPath.toUri().getScheme();
+      if (StringUtils.isBlank(schema) || !uriPath.isAbsolute()) {
+        throw new IllegalArgumentException("URI '" + uriName
+            + "' is invalid. Unsupport URI without schema or relative URI.");
+      }
+      if (!uriName.startsWith(schema + AUTHORITY_PREFIX)) {
+        throw new IllegalArgumentException("URI '" + uriName + "' is invalid.");
+      }
     }
     this.uriName = uriName;
   }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a2b6184d/sentry-core/sentry-core-model-db/src/test/java/org/apache/sentry/core/db/TestURI.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-db/src/test/java/org/apache/sentry/core/db/TestURI.java
b/sentry-core/sentry-core-model-db/src/test/java/org/apache/sentry/core/db/TestURI.java
index 3b2aa31..b639a95 100644
--- a/sentry-core/sentry-core-model-db/src/test/java/org/apache/sentry/core/db/TestURI.java
+++ b/sentry-core/sentry-core-model-db/src/test/java/org/apache/sentry/core/db/TestURI.java
@@ -42,4 +42,15 @@ public class TestURI {
   public void testBadUriIncorrectHdfsPrefix() {
     new AccessURI("hdfs:/some/path");
   }
+
+  @Test
+  public void testUriSwiftPrefix() {
+    new AccessURI("swift:///some/path");
+  }
+
+  @Test
+  public void testUriWithAuthority() {
+    new AccessURI("hdfs://localhost:9999/some/path");
+  }
+
 }


Mime
View raw message