use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.
the class SpnegoConfig method loginAndReturnUgi.
// Performs the Server login to KDC for SPNEGO
private UserGroupInformation loginAndReturnUgi() throws DrillException {
validateSpnegoConfig();
UserGroupInformation ugi;
try {
// After the login is performed reset the static UGI state.
if (!UserGroupInformation.isSecurityEnabled()) {
final Configuration newConfig = new Configuration();
newConfig.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, UserGroupInformation.AuthenticationMethod.KERBEROS.toString());
if (clientNameMapping != null) {
newConfig.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTH_TO_LOCAL, clientNameMapping);
}
UserGroupInformation.setConfiguration(newConfig);
ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
// Reset the original configuration for static UGI
UserGroupInformation.setConfiguration(new Configuration());
} else {
// Let's not overwrite the rules here since it might be possible that CUSTOM security is configured for
// JDBC/ODBC with default rules. If Kerberos was enabled then the correct rules must already be set
ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
}
} catch (Exception e) {
throw new DrillException(String.format("Login failed for %s with given keytab", principal), e);
}
return ugi;
}
use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.
the class SSLConfig method initializeTrustManagerFactory.
public TrustManagerFactory initializeTrustManagerFactory() throws DrillException {
TrustManagerFactory tmf;
KeyStore ts = null;
// Support Windows/MacOs system trust store
try {
String trustStoreType = getTrustStoreType();
if ((isWindows || isMacOs) && useSystemTrustStore()) {
// This is valid for MS-Windows and MacOs
logger.debug("Initializing System truststore.");
ts = KeyStore.getInstance(!trustStoreType.isEmpty() ? trustStoreType : KeyStore.getDefaultType());
ts.load(null, null);
} else if (!getTrustStorePath().isEmpty()) {
// if truststore is not provided then we will use the default. Note that the default depends on
// the TrustManagerFactory that in turn depends on the Security Provider.
// Use null as the truststore which will result in the default truststore being picked up
logger.debug("Initializing truststore {}.", getTrustStorePath());
ts = KeyStore.getInstance(!trustStoreType.isEmpty() ? trustStoreType : KeyStore.getDefaultType());
InputStream tsStream = new FileInputStream(getTrustStorePath());
ts.load(tsStream, getTrustStorePassword().toCharArray());
} else {
logger.debug("Initializing default truststore.");
}
if (disableCertificateVerification()) {
tmf = InsecureTrustManagerFactory.INSTANCE;
} else {
tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
}
tmf.init(ts);
} catch (Exception e) {
// Catch any SSL initialization Exceptions here and abort.
throw new DrillException(new StringBuilder().append("Exception while initializing the truststore: [").append(e.getMessage()).append("]. ").toString(), e);
}
return tmf;
}
use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.
the class SSLConfigClient method initJDKSSLContext.
@Override
public SSLContext initJDKSSLContext() throws DrillException {
final SSLContext sslCtx;
if (!userSslEnabled) {
return null;
}
TrustManagerFactory tmf;
try {
tmf = initializeTrustManagerFactory();
sslCtx = SSLContext.getInstance(protocol);
sslCtx.init(null, tmf.getTrustManagers(), null);
} catch (Exception e) {
// Catch any SSL initialization Exceptions here and abort.
throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized due to the following exception: ").append("[ ").append(e.getMessage()).append("]. ").toString());
}
this.jdkSSlContext = sslCtx;
return sslCtx;
}
use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.
the class SSLConfigServer method initJDKSSLContext.
@Override
public SSLContext initJDKSSLContext() throws DrillException {
final SSLContext sslCtx;
if (!userSslEnabled) {
return null;
}
KeyManagerFactory kmf;
TrustManagerFactory tmf;
try {
if (keyStorePath.isEmpty()) {
throw new DrillException("No Keystore provided.");
}
kmf = initializeKeyManagerFactory();
tmf = initializeTrustManagerFactory();
sslCtx = SSLContext.getInstance(protocol);
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
} catch (Exception e) {
// Catch any SSL initialization Exceptions here and abort.
throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized - ").append("[ ").append(e.getMessage()).append("]. ").toString());
}
this.jdkSSlContext = sslCtx;
return sslCtx;
}
use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.
the class TestSSLConfig method testMissingKeystorePath.
@Test
public void testMissingKeystorePath() throws Exception {
ConfigBuilder config = new ConfigBuilder();
config.put(ExecConstants.HTTP_KEYSTORE_PATH, "");
config.put(ExecConstants.HTTP_KEYSTORE_PASSWORD, "root");
config.put(ExecConstants.SSL_USE_HADOOP_CONF, false);
config.put(ExecConstants.USER_SSL_ENABLED, true);
try {
SSLConfig sslv = new SSLConfigBuilder().config(config.build()).mode(SSLConfig.Mode.SERVER).initializeSSLContext(false).validateKeyStore(true).build();
fail();
// Expected
} catch (Exception e) {
assertTrue(e instanceof DrillException);
}
}
Aggregations