use of org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator in project drill by axbaretto.
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.exec.server.rest.auth.DrillSpnegoAuthenticator 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);
}
Aggregations