User Impersonation - Support different username cases
@@ -50,6 +50,10 @@ public class RefreshableDataSource implements DataSource {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(RefreshableDataSource.class);
+ public static enum UsernameCase {
+ AS_SPECIFIED,LOWER_CASE,UPPER_CASE;
+ }
+
private static final String DEFAULT_DATASOURCE_NAME = "DEFAULT";
String propertyPrefix;
@Autowired
@@ -207,6 +211,7 @@ public class RefreshableDataSource implements DataSource {
return prefix;
}
+
private DataSource create(boolean proxyUser, String principal) {
String prefix = getPrefixWithTrailingDot();
@@ -217,7 +222,7 @@ public class RefreshableDataSource implements DataSource {
if (proxyUser && propertyPrefix.equals("hive.datasource")) {
userName = principal;
- url = url + ";hive.server2.proxy.user=" + principal;
+ url = url + ";hive.server2.proxy.user=" + convertUsernameCase(principal,getUsernameCaseSetting(prefix));
}
log.debug("The JDBC URL is " + url + " --- User impersonation enabled: " + proxyUser);
String username = userName;
@@ -226,4 +231,32 @@ public class RefreshableDataSource implements DataSource {
return ds;
}
+ /**
+ * Gets the environment setting for how the username case sensitivity should be handled
+ * By default it uses the exact case as specified
+ * @param prefix
+ * @return
+ */
+ private UsernameCase getUsernameCaseSetting(String prefix){
+ UsernameCase usernameCase = UsernameCase.AS_SPECIFIED;
+ try {
+ usernameCase = UsernameCase.valueOf(env.getProperty(prefix+"username.case","AS_SPECIFIED"));
+ }catch (Exception e){
+ usernameCase = UsernameCase.AS_SPECIFIED;
+ }
+ return usernameCase;
+ }
+
+ private String convertUsernameCase(String username, UsernameCase usernameCase){
+ if(usernameCase == UsernameCase.LOWER_CASE){
+ return username.toLowerCase();
+ }
+ else if(usernameCase == UsernameCase.UPPER_CASE){
+ return username.toUpperCase();
+ }
+ return username;
+
+ }
+
+
}
