diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/HiveAuthorizationProviderBase.java b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/HiveAuthorizationProviderBase.java index 2d45620..18a1b25 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/HiveAuthorizationProviderBase.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/HiveAuthorizationProviderBase.java @@ -57,10 +57,14 @@ public void setHandler(HMSHandler handler){ this.handler = handler; } + public boolean isRunFromMetaStore(){ + return (this.hiveClient == null); + } + public PrincipalPrivilegeSet get_privilege_set(HiveObjectType column, String dbName, String tableName, List partValues, String col, String userName, List groupNames) throws HiveException { - if (hiveClient != null) { + if (!isRunFromMetaStore()) { return hiveClient.get_privilege_set( column, dbName, tableName, partValues, col, userName, groupNames); } else { @@ -77,7 +81,7 @@ public PrincipalPrivilegeSet get_privilege_set(HiveObjectType column, String dbN } public Database getDatabase(String dbName) throws HiveException { - if (hiveClient != null) { + if (!isRunFromMetaStore()) { return hiveClient.getDatabase(dbName); } else { try { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/StorageBasedAuthorizationProvider.java b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/StorageBasedAuthorizationProvider.java index 5bf1927..384ef37 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/StorageBasedAuthorizationProvider.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/StorageBasedAuthorizationProvider.java @@ -63,6 +63,22 @@ private Warehouse wh; + /** + * Make sure that the warehouse variable is set up properly. + * @throws MetaException if unable to instantiate + */ + private void initWh() throws MetaException { + if (wh == null){ + if(!hive_db.isRunFromMetaStore()){ + this.wh = new Warehouse(getConf()); + }else{ + // not good if we reach here, this was initialized at setMetaStoreHandler() time. + // this means handler.getWh() is returning null. Error out. + throw new MetaException("Unitialized Warehouse from MetastoreHandler"); + } + } + } + @Override public void init(Configuration conf) throws HiveException { hive_db = new HiveProxy(); @@ -100,6 +116,7 @@ public void authorize(Table table, Privilege[] readRequiredPriv, Privilege[] wri // we try to determine what the path would be after the create table is issued. Path path = null; try { + initWh(); String location = table.getTTable().getSd().getLocation(); if (location == null || location.isEmpty()) { path = wh.getTablePath(hive_db.getDatabase(table.getDbName()), table.getTableName()); @@ -305,6 +322,7 @@ protected static void checkPermissions(final FileSystem fs, final Path path, protected Path getDbLocation(Database db) throws HiveException { try { + initWh(); String location = db.getLocationUri(); if (location == null) { return wh.getDefaultDatabasePath(db.getName());