String uri = privilege.getURI();
String action = safeTrimLower(privilege.getAction());
PrivilegeScope scope;
if (serverName == null) {
throw new SentryInvalidInputException("Server name is null");
}
if (AccessConstants.SELECT.equalsIgnoreCase(action) ||
AccessConstants.INSERT.equalsIgnoreCase(action)) {
if (Strings.nullToEmpty(tableName).trim().isEmpty()
&&Strings.nullToEmpty(dbName).trim().isEmpty()) {
throw new SentryInvalidInputException("Either Table name or Db name must be NON-NULL for SELECT/INSERT privilege");
}
}
if (action == null) {
action = AccessConstants.ALL;
}
// Validate privilege scope
try {
scope = Enum.valueOf(PrivilegeScope.class, privilege.getPrivilegeScope().toUpperCase());
} catch (IllegalArgumentException e) {
throw new SentryInvalidInputException("Invalid Privilege scope: " +
privilege.getPrivilegeScope());
}
if (PrivilegeScope.SERVER.equals(scope)) {
if (StringUtils.isNotEmpty(dbName) || StringUtils.isNotEmpty(tableName)) {
throw new SentryInvalidInputException("DB and TABLE names should not be "
+ "set for SERVER scope");
}
} else if (PrivilegeScope.DATABASE.equals(scope)) {
if (StringUtils.isEmpty(dbName)) {
throw new SentryInvalidInputException("DB name not set for DB scope");
}
if (StringUtils.isNotEmpty(tableName)) {
StringUtils.isNotEmpty("TABLE names should not be set for DB scope");
}
} else if (PrivilegeScope.TABLE.equals(scope)) {
if (StringUtils.isEmpty(dbName) || StringUtils.isEmpty(tableName)) {
throw new SentryInvalidInputException("TABLE or DB name not set for TABLE scope");
}
} else if (PrivilegeScope.URI.equals(scope)){
if (StringUtils.isEmpty(uri)) {
throw new SentryInvalidInputException("URI path not set for URI scope");
}
if (StringUtils.isNotEmpty(tableName)) {
throw new SentryInvalidInputException("TABLE should not be set for URI scope");
}
} else {
throw new SentryInvalidInputException("Unsupported operation scope: " + scope);
}
if (uri == null || uri.equals("")) {
privilegeName.append(serverName);
privilegeName.append("+");