use of org.apache.drill.common.config.DrillConfig in project drill by apache.
the class TestExpirationHandler method tables.
private IcebergTables tables(String name, boolean shouldExpire, int retainNumber) {
Config config = baseIcebergConfig(new File(defaultFolder.getRoot(), name)).withValue(IcebergConfigConstants.COMPONENTS_COMMON_PROPERTIES + "." + TableProperties.METADATA_PREVIOUS_VERSIONS_MAX, ConfigValueFactory.fromAnyRef(retainNumber)).withValue(IcebergConfigConstants.COMPONENTS_COMMON_PROPERTIES + "." + TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED, ConfigValueFactory.fromAnyRef(shouldExpire));
DrillConfig drillConfig = new DrillConfig(config);
return (IcebergTables) new IcebergMetastore(drillConfig).tables();
}
use of org.apache.drill.common.config.DrillConfig in project drill by apache.
the class DrillRoot method getPortNum.
@GET
@Path("/portNum")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Integer> getPortNum() {
final DrillConfig config = work.getContext().getConfig();
final int port = config.getInt(ExecConstants.HTTP_PORT);
Map<String, Integer> portMap = new HashMap<String, Integer>();
portMap.put("port", port);
return portMap;
}
use of org.apache.drill.common.config.DrillConfig in project drill by apache.
the class BaseQueryRunner method applyUserName.
protected void applyUserName(String userName) {
if (!Strings.isNullOrEmpty(userName)) {
DrillConfig config = workManager.getContext().getConfig();
if (!config.getBoolean(ExecConstants.IMPERSONATION_ENABLED)) {
throw UserException.permissionError().message("User impersonation is not enabled").build(logger);
}
InboundImpersonationManager inboundImpersonationManager = new InboundImpersonationManager();
boolean isAdmin = !config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED) || ImpersonationUtil.hasAdminPrivileges(webUserConnection.getSession().getCredentials().getUserName(), ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(options), ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(options));
if (isAdmin) {
// Admin user can impersonate any user they want to (when authentication is disabled, all users are admin)
webUserConnection.getSession().replaceUserCredentials(inboundImpersonationManager, UserBitShared.UserCredentials.newBuilder().setUserName(userName).build());
} else {
// Check configured impersonation rules to see if this user is allowed to impersonate the given user
inboundImpersonationManager.replaceUserOnSession(userName, webUserConnection.getSession());
}
}
}
use of org.apache.drill.common.config.DrillConfig in project drill by apache.
the class TestDrillSpnegoAuthenticator method setupTest.
@BeforeClass
public static void setupTest() throws Exception {
spnegoHelper = new KerberosHelper(TestSpnegoAuthentication.class.getSimpleName(), primaryName);
spnegoHelper.setupKdc(dirTestWatcher.getTmpDir());
sun.security.krb5.Config.refresh();
// (2) Reset the default realm.
final Field defaultRealm = KerberosName.class.getDeclaredField("defaultRealm");
defaultRealm.setAccessible(true);
defaultRealm.set(null, KerberosUtil.getDefaultRealm());
// Create a DrillbitContext with service principal and keytab for DrillSpnegoLoginService
final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("spnego"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())));
// Create mock objects for optionManager and AuthConfiguration
final SystemOptionManager optionManager = Mockito.mock(SystemOptionManager.class);
Mockito.when(optionManager.getOption(ExecConstants.ADMIN_USERS_VALIDATOR)).thenReturn(ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
Mockito.when(optionManager.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR)).thenReturn(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
final DrillbitContext drillbitContext = Mockito.mock(DrillbitContext.class);
Mockito.when(drillbitContext.getConfig()).thenReturn(newConfig);
Mockito.when(drillbitContext.getOptionManager()).thenReturn(optionManager);
Authenticator.AuthConfiguration authConfiguration = Mockito.mock(Authenticator.AuthConfiguration.class);
spnegoAuthenticator = new DrillSpnegoAuthenticator("SPNEGO");
DrillSpnegoLoginService spnegoLoginService = new DrillSpnegoLoginService(drillbitContext);
Mockito.when(authConfiguration.getLoginService()).thenReturn(spnegoLoginService);
Mockito.when(authConfiguration.getIdentityService()).thenReturn(new DefaultIdentityService());
Mockito.when(authConfiguration.isSessionRenewedOnAuthentication()).thenReturn(true);
// Set the login service and identity service inside SpnegoAuthenticator
spnegoAuthenticator.setConfiguration(authConfiguration);
}
use of org.apache.drill.common.config.DrillConfig in project drill by apache.
the class TestSpnegoConfig method testValidSpnegoConfig.
/**
* Valid Configuration with both keytab & principal
* @throws Exception
*/
@Test
public void testValidSpnegoConfig() throws Exception {
try {
final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)));
final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig);
spnegoConfig.validateSpnegoConfig();
UserGroupInformation ugi = spnegoConfig.getLoggedInUgi();
assertEquals(primaryName, ugi.getShortUserName());
assertEquals(spnegoHelper.SERVER_PRINCIPAL, ugi.getUserName());
} catch (Exception ex) {
fail();
}
}
Aggregations