SentryServiceUtil { public static Set<TSentryAuthorizable> parseAuthorizables(String objects) throws SentryUserException { if (StringUtils.isEmpty(objects)) { return Collections.emptySet(); } Set<TSentryAuthorizable> authorizables = new HashSet<>(); for (String object : objects.split(SentryConstants.COMMA_SEPARATOR)) { Set<String> ketSet = new HashSet<>(); String objectTrimmed = object.trim(); if (objectTrimmed.isEmpty()) { continue; } TSentryAuthorizable authorizable = new TSentryAuthorizable(""); ketSet.clear(); for (String kvStr : SentryConstants.AUTHORIZABLE_SPLITTER.split(objectTrimmed)) { KeyValue kv; String key; String value; try { kv = new KeyValue(kvStr); key = kv.getKey(); value = kv.getValue(); } catch (Exception exception) { throw new SentryUserException("Wrongly formatted authorizable " + objectTrimmed); } if(!ketSet.add(key)) { throw new SentryUserException("Wrongly formatted authorizable " + objectTrimmed); } if (PolicyFileConstants.PRIVILEGE_DATABASE_NAME.equalsIgnoreCase(key)) { authorizable.setDb(value); } else if (PolicyFileConstants.PRIVILEGE_TABLE_NAME.equalsIgnoreCase(key)) { authorizable.setTable(value); } else if (PolicyFileConstants.PRIVILEGE_URI_NAME.equalsIgnoreCase(key)) { authorizable.setUri(value); } else { LOGGER.error("Wrongly formatted authorizable " + objectTrimmed ); throw new SentryUserException("Wrongly formatted authorizable " + objectTrimmed); } } authorizables.add(authorizable); } return authorizables; } private  SentryServiceUtil(); static TSentryPrivilege convertToTSentryPrivilege(String privilegeStr); static Set<TSentryAuthorizable> parseAuthorizables(String objects); static String getPrivilegeScope(TSentryPrivilege tSentryPrivilege); static String convertTSentryPrivilegeToStr(TSentryPrivilege tSentryPrivilege); static void shutdownAndAwaitTermination(ExecutorService pool, String poolName,
                       long timeout, TimeUnit unit, Logger logger); static boolean isHDFSSyncEnabled(Configuration conf); static boolean isHDFSSyncEnabledNoCache(Configuration conf); static boolean isSyncPolicyStoreEnabled(Configuration conf); static String getHiveMetastoreURI(); static String getAuthzObj(TSentryAuthorizable authorizable); static String getAuthzObj(String dbName, String tblName); static String getCurrentTimeStampWithMessage(String logMessage); static void checkDbExplicitGrantsPermitted(Configuration conf, Set<TSentryPrivilege> privileges);  }
@Test public void testparseAuthorizables() throws Exception { Set<TSentryAuthorizable> authorizables; authorizables = parseAuthorizables("db=db1->table=tb1,db=db1->table=tbl2"); assertEquals(2, authorizables.size()); authorizables = parseAuthorizables("uri=/path/for/test"); assertEquals(1, authorizables.size()); authorizables = parseAuthorizables("db=db1->table=tb1,db=db1->table=tbl2,uri=/path/for/test"); assertEquals(3, authorizables.size()); authorizables = parseAuthorizables("db=db1->table=tb1 , db=db1->table=tbl2 , uri=/path/for/test"); assertEquals(3, authorizables.size()); authorizables = parseAuthorizables("db=db1->table=tb1,,,db=db1->table=tbl2"); assertEquals(2, authorizables.size()); try { authorizables = parseAuthorizables("db=db1->table=,db=db1->table=tbl1"); fail("There should been an exception"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("db=db1->table=")); } try { authorizables = parseAuthorizables("db=db1->table,db=db1->table=tbl1"); fail("There should been an exception"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("db=db1->table")); } try { authorizables = parseAuthorizables("db=db1->table=tbl1,d=db1->table=tbl2"); fail("There should been an exception"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("d=db1->table=tbl2")); } try { authorizables = parseAuthorizables("db=db1->table=tbl1,db=db1->table=tbl2db=db1->table=tbl3"); fail("There should been an exception"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("db=db1->table=tbl2db=db1->table=tbl3")); } }