Search in sources :

Example 46 with ScanResult

use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.

the class TestSpnegoAuthentication method testOnlySPNEGOEnabled.

/**
 * Validate only SPNEGO security handler is configured properly when enabled via configuration
 */
@Test
public void testOnlySPNEGOEnabled() throws Exception {
    final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("spnego"))).withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())));
    final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig);
    final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class);
    Mockito.when(authenticatorProvider.containsFactory(PlainFactory.SIMPLE_NAME)).thenReturn(false);
    final DrillbitContext context = Mockito.mock(DrillbitContext.class);
    Mockito.when(context.getClasspathScan()).thenReturn(scanResult);
    Mockito.when(context.getConfig()).thenReturn(newConfig);
    Mockito.when(context.getAuthProvider()).thenReturn(authenticatorProvider);
    final DrillHttpSecurityHandlerProvider securityProvider = new DrillHttpSecurityHandlerProvider(newConfig, context);
    assertTrue(!securityProvider.isFormEnabled());
    assertTrue(securityProvider.isSpnegoEnabled());
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) AuthenticatorProviderImpl(org.apache.drill.exec.rpc.security.AuthenticatorProviderImpl) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) DrillHttpSecurityHandlerProvider(org.apache.drill.exec.server.rest.auth.DrillHttpSecurityHandlerProvider) DrillConfig(org.apache.drill.common.config.DrillConfig) BaseTest(org.apache.drill.test.BaseTest) SecurityTest(org.apache.drill.categories.SecurityTest) Test(org.junit.Test)

Example 47 with ScanResult

use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.

the class FunctionImplementationRegistry method validate.

/**
 * Using given local path to jar creates unique class loader for this jar.
 * Class loader is closed to release opened connection to jar when validation is finished.
 * Scan jar content to receive list of all scanned classes
 * and starts validation process against local function registry.
 * Checks if received list of validated function is not empty.
 *
 * @param path local path to jar we need to validate
 * @return list of validated function signatures
 */
public List<String> validate(Path path) throws IOException {
    URL url = path.toUri().toURL();
    URL[] urls = { url };
    try (URLClassLoader classLoader = new URLClassLoader(urls)) {
        ScanResult jarScanResult = scan(classLoader, path, urls);
        List<String> functions = localFunctionRegistry.validate(path.getName(), jarScanResult);
        if (functions.isEmpty()) {
            throw new FunctionValidationException(String.format("Jar %s does not contain functions", path.getName()));
        }
        return functions;
    }
}
Also used : FunctionValidationException(org.apache.drill.exec.exception.FunctionValidationException) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Example 48 with ScanResult

use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.

the class RunTimeScan method fromPrescan.

/**
 * Loads prescanned classpath info and scans for extra ones based on configuration.
 * (unless prescan is disabled with {@link ClassPathScanner#IMPLEMENTATIONS_SCAN_CACHE}{@code =false})
 * @param config to retrieve the packages to scan
 * @return the scan result
 */
public static ScanResult fromPrescan(DrillConfig config) {
    List<String> packagePrefixes = ClassPathScanner.getPackagePrefixes(config);
    List<String> scannedBaseClasses = ClassPathScanner.getScannedBaseClasses(config);
    List<String> scannedAnnotations = ClassPathScanner.getScannedAnnotations(config);
    if (ClassPathScanner.isScanBuildTimeCacheEnabled(config)) {
        // scan only locations that have not been scanned yet
        ScanResult runtimeScan = ClassPathScanner.scan(NON_PRESCANNED_MARKED_PATHS, packagePrefixes, scannedBaseClasses, scannedAnnotations, PRESCANNED);
        return runtimeScan.merge(PRESCANNED);
    } else {
        // scan everything
        return ClassPathScanner.scan(ClassPathScanner.getMarkedPaths(ConfigConstants.DRILL_JAR_MARKER_FILE_RESOURCE_PATHNAME), packagePrefixes, scannedBaseClasses, scannedAnnotations, ClassPathScanner.emptyResult());
    }
}
Also used : ScanResult(org.apache.drill.common.scanner.persistence.ScanResult)

Aggregations

ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)48 DrillConfig (org.apache.drill.common.config.DrillConfig)29 Test (org.junit.Test)26 SecurityTest (org.apache.drill.categories.SecurityTest)16 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)12 IOException (java.io.IOException)10 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)10 AuthenticatorProviderImpl (org.apache.drill.exec.rpc.security.AuthenticatorProviderImpl)10 DrillHttpSecurityHandlerProvider (org.apache.drill.exec.server.rest.auth.DrillHttpSecurityHandlerProvider)10 URL (java.net.URL)9 LogicalPlanPersistence (org.apache.drill.common.config.LogicalPlanPersistence)7 BootStrapContext (org.apache.drill.exec.server.BootStrapContext)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)6 FragmentWritableBatch (org.apache.drill.exec.record.FragmentWritableBatch)6 WorkEventBus (org.apache.drill.exec.rpc.control.WorkEventBus)6 WorkerBee (org.apache.drill.exec.work.WorkManager.WorkerBee)6 BaseTest (org.apache.drill.test.BaseTest)6 URLClassLoader (java.net.URLClassLoader)4 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)4