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());
}
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;
}
}
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());
}
}
Aggregations