Search in sources :

Example 1 with DefaultIdentityService

use of org.eclipse.jetty.security.DefaultIdentityService 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);
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) Field(java.lang.reflect.Field) DrillConfig(org.apache.drill.common.config.DrillConfig) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) DefaultIdentityService(org.eclipse.jetty.security.DefaultIdentityService) DrillSpnegoLoginService(org.apache.drill.exec.server.rest.auth.DrillSpnegoLoginService) KerberosHelper(org.apache.drill.exec.rpc.security.KerberosHelper) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) Authenticator(org.eclipse.jetty.security.Authenticator) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) BeforeClass(org.junit.BeforeClass)

Example 2 with DefaultIdentityService

use of org.eclipse.jetty.security.DefaultIdentityService 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);
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) Field(java.lang.reflect.Field) DrillConfig(org.apache.drill.common.config.DrillConfig) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) DefaultIdentityService(org.eclipse.jetty.security.DefaultIdentityService) DrillSpnegoLoginService(org.apache.drill.exec.server.rest.auth.DrillSpnegoLoginService) KerberosHelper(org.apache.drill.exec.rpc.security.KerberosHelper) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) Authenticator(org.eclipse.jetty.security.Authenticator) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) BeforeClass(org.junit.BeforeClass)

Aggregations

Field (java.lang.reflect.Field)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2 KerberosHelper (org.apache.drill.exec.rpc.security.KerberosHelper)2 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)2 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)2 DrillSpnegoAuthenticator (org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator)2 DrillSpnegoLoginService (org.apache.drill.exec.server.rest.auth.DrillSpnegoLoginService)2 Authenticator (org.eclipse.jetty.security.Authenticator)2 DefaultIdentityService (org.eclipse.jetty.security.DefaultIdentityService)2 BeforeClass (org.junit.BeforeClass)2