@Test public void testValidateImpersonatorInvalid() { String[] users = {ALICE, BOB, CHARLIE}; for (String user : users) { try { ProxyUserValidation.validateImpersonator(SPARK, user); fail(); } catch (StatusRuntimeException e) { assertEquals(Status.PERMISSION_DENIED.getCode(), e.getStatus().getCode()); assertEquals("Impersonation disallowed for `spark/testhost@EXAMPLE.COM`", e.getStatus().getDescription()); } } }
public static void validateImpersonator(String impersonator, String impersonated) { String mappedImpersonated = AbstractUserMapper.getInstance().map(impersonated); EmailValidation.validateEmail(mappedImpersonated); MDC.put(LoggingUtils.MDC_AUTH_MODE_PROXY_IMPERSONATED_USER_KEY, impersonated); List<? extends Config> proxyConfigs = AppSettings.getInstance().getConfigList(AppSettings.PROXY_USERS); for (Config proxyConfig : proxyConfigs) { String proxy = proxyConfig.getString(CONFIG_PROXY); if (impersonator.equals(proxy)) { if (isWhitelistedByUsername(proxyConfig, mappedImpersonated)) { return; } else if (isWhitelistedByGroupMembership(proxyConfig, mappedImpersonated)) { return; } } } throw Status.PERMISSION_DENIED .withDescription("Impersonation disallowed for `" + impersonator + "`") .asRuntimeException(); }
ProxyUserValidation { public static void validateImpersonator(String impersonator, String impersonated) { String mappedImpersonated = AbstractUserMapper.getInstance().map(impersonated); EmailValidation.validateEmail(mappedImpersonated); MDC.put(LoggingUtils.MDC_AUTH_MODE_PROXY_IMPERSONATED_USER_KEY, impersonated); List<? extends Config> proxyConfigs = AppSettings.getInstance().getConfigList(AppSettings.PROXY_USERS); for (Config proxyConfig : proxyConfigs) { String proxy = proxyConfig.getString(CONFIG_PROXY); if (impersonator.equals(proxy)) { if (isWhitelistedByUsername(proxyConfig, mappedImpersonated)) { return; } else if (isWhitelistedByGroupMembership(proxyConfig, mappedImpersonated)) { return; } } } throw Status.PERMISSION_DENIED .withDescription("Impersonation disallowed for `" + impersonator + "`") .asRuntimeException(); } }
ProxyUserValidation { public static void validateImpersonator(String impersonator, String impersonated) { String mappedImpersonated = AbstractUserMapper.getInstance().map(impersonated); EmailValidation.validateEmail(mappedImpersonated); MDC.put(LoggingUtils.MDC_AUTH_MODE_PROXY_IMPERSONATED_USER_KEY, impersonated); List<? extends Config> proxyConfigs = AppSettings.getInstance().getConfigList(AppSettings.PROXY_USERS); for (Config proxyConfig : proxyConfigs) { String proxy = proxyConfig.getString(CONFIG_PROXY); if (impersonator.equals(proxy)) { if (isWhitelistedByUsername(proxyConfig, mappedImpersonated)) { return; } else if (isWhitelistedByGroupMembership(proxyConfig, mappedImpersonated)) { return; } } } throw Status.PERMISSION_DENIED .withDescription("Impersonation disallowed for `" + impersonator + "`") .asRuntimeException(); }  }
ProxyUserValidation { public static void validateImpersonator(String impersonator, String impersonated) { String mappedImpersonated = AbstractUserMapper.getInstance().map(impersonated); EmailValidation.validateEmail(mappedImpersonated); MDC.put(LoggingUtils.MDC_AUTH_MODE_PROXY_IMPERSONATED_USER_KEY, impersonated); List<? extends Config> proxyConfigs = AppSettings.getInstance().getConfigList(AppSettings.PROXY_USERS); for (Config proxyConfig : proxyConfigs) { String proxy = proxyConfig.getString(CONFIG_PROXY); if (impersonator.equals(proxy)) { if (isWhitelistedByUsername(proxyConfig, mappedImpersonated)) { return; } else if (isWhitelistedByGroupMembership(proxyConfig, mappedImpersonated)) { return; } } } throw Status.PERMISSION_DENIED .withDescription("Impersonation disallowed for `" + impersonator + "`") .asRuntimeException(); }  static void validateImpersonator(String impersonator, String impersonated); static Directory getDirectoryService(); }
ProxyUserValidation { public static void validateImpersonator(String impersonator, String impersonated) { String mappedImpersonated = AbstractUserMapper.getInstance().map(impersonated); EmailValidation.validateEmail(mappedImpersonated); MDC.put(LoggingUtils.MDC_AUTH_MODE_PROXY_IMPERSONATED_USER_KEY, impersonated); List<? extends Config> proxyConfigs = AppSettings.getInstance().getConfigList(AppSettings.PROXY_USERS); for (Config proxyConfig : proxyConfigs) { String proxy = proxyConfig.getString(CONFIG_PROXY); if (impersonator.equals(proxy)) { if (isWhitelistedByUsername(proxyConfig, mappedImpersonated)) { return; } else if (isWhitelistedByGroupMembership(proxyConfig, mappedImpersonated)) { return; } } } throw Status.PERMISSION_DENIED .withDescription("Impersonation disallowed for `" + impersonator + "`") .asRuntimeException(); }  static void validateImpersonator(String impersonator, String impersonated); static Directory getDirectoryService();  }