use of org.apache.drill.exec.rpc.security.AuthenticatorFactory in project drill by axbaretto.
the class UserClient method prepareSaslHandshake.
@Override
protected void prepareSaslHandshake(final RpcConnectionHandler<UserToBitConnection> connectionHandler, List<String> serverAuthMechanisms) {
try {
final Map<String, String> saslProperties = properties.stringPropertiesAsMap();
// Set correct QOP property and Strength based on server needs encryption or not.
// If ChunkMode is enabled then negotiate for buffer size equal to wrapChunkSize,
// If ChunkMode is disabled then negotiate for MAX_WRAPPED_SIZE buffer size.
saslProperties.putAll(SaslProperties.getSaslProperties(connection.isEncryptionEnabled(), connection.getMaxWrappedSize()));
final AuthenticatorFactory factory = getAuthenticatorFactory(properties, serverAuthMechanisms);
final String mechanismName = factory.getSimpleName();
logger.trace("Will try to authenticate to server using {} mechanism with encryption context {}", mechanismName, connection.getEncryptionCtxtString());
// Update the thread context class loader to current class loader
// See DRILL-6063 for detailed description
final ClassLoader oldThreadCtxtCL = Thread.currentThread().getContextClassLoader();
final ClassLoader newThreadCtxtCL = this.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newThreadCtxtCL);
final UserGroupInformation ugi = factory.createAndLoginUser(saslProperties);
// Reset the thread context class loader to original one
Thread.currentThread().setContextClassLoader(oldThreadCtxtCL);
startSaslHandshake(connectionHandler, saslProperties, ugi, factory, RpcType.SASL_MESSAGE);
} catch (final IOException e) {
logger.error("Failed while doing setup for starting SASL handshake for connection", connection.getName());
final Exception ex = new RpcException(String.format("Failed to initiate authentication for connection %s", connection.getName()), e);
connectionHandler.connectionFailed(RpcConnectionHandler.FailureType.AUTHENTICATION, ex);
}
}
use of org.apache.drill.exec.rpc.security.AuthenticatorFactory in project drill by apache.
the class UserClient method prepareSaslHandshake.
@Override
protected void prepareSaslHandshake(final RpcConnectionHandler<UserToBitConnection> connectionHandler, List<String> serverAuthMechanisms) {
try {
final Map<String, String> saslProperties = properties.stringPropertiesAsMap();
// Set correct QOP property and Strength based on server needs encryption or not.
// If ChunkMode is enabled then negotiate for buffer size equal to wrapChunkSize,
// If ChunkMode is disabled then negotiate for MAX_WRAPPED_SIZE buffer size.
saslProperties.putAll(SaslProperties.getSaslProperties(connection.isEncryptionEnabled(), connection.getMaxWrappedSize()));
final AuthenticatorFactory factory = getAuthenticatorFactory(properties, serverAuthMechanisms);
final String mechanismName = factory.getSimpleName();
logger.trace("Will try to authenticate to server using {} mechanism with encryption context {}", mechanismName, connection.getEncryptionCtxtString());
// Update the thread context class loader to current class loader
// See DRILL-6063 for detailed description
final ClassLoader oldThreadCtxtCL = Thread.currentThread().getContextClassLoader();
final ClassLoader newThreadCtxtCL = this.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(newThreadCtxtCL);
final UserGroupInformation ugi = factory.createAndLoginUser(saslProperties);
// Reset the thread context class loader to original one
Thread.currentThread().setContextClassLoader(oldThreadCtxtCL);
startSaslHandshake(connectionHandler, saslProperties, ugi, factory, RpcType.SASL_MESSAGE);
} catch (IOException e) {
logger.error("Failed while doing setup for starting SASL handshake for connection {}", connection.getName());
final Exception ex = new RpcException(String.format("Failed to initiate authentication for connection %s", connection.getName()), e);
connectionHandler.connectionFailed(RpcConnectionHandler.FailureType.AUTHENTICATION, ex);
}
}
use of org.apache.drill.exec.rpc.security.AuthenticatorFactory in project drill by apache.
the class DrillRestLoginService method login.
@Override
public UserIdentity login(String username, Object credentials, ServletRequest request) {
if (!(credentials instanceof String)) {
return null;
}
try {
// Authenticate WebUser locally using UserAuthenticator. If WebServer is started that guarantees the PLAIN
// mechanism is configured and authenticator is also available
final AuthenticatorFactory plainFactory = drillbitContext.getAuthProvider().getAuthenticatorFactory(PlainFactory.SIMPLE_NAME);
final UserAuthenticator userAuthenticator = ((PlainFactory) plainFactory).getAuthenticator();
// Authenticate the user with configured Authenticator
userAuthenticator.authenticate(username, credentials.toString());
logger.info("WebUser {} logged in from {}:{}", username, request.getRemoteHost(), request.getRemotePort());
final SystemOptionManager sysOptions = drillbitContext.getOptionManager();
final boolean isAdmin = ImpersonationUtil.hasAdminPrivileges(username, ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(sysOptions), ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(sysOptions));
// Create the UserPrincipal corresponding to logged in user.
final Principal userPrincipal = new DrillUserPrincipal(username, isAdmin);
final Subject subject = new Subject();
subject.getPrincipals().add(userPrincipal);
subject.getPrivateCredentials().add(credentials);
if (isAdmin) {
subject.getPrincipals().addAll(DrillUserPrincipal.ADMIN_PRINCIPALS);
return identityService.newUserIdentity(subject, userPrincipal, DrillUserPrincipal.ADMIN_USER_ROLES);
} else {
subject.getPrincipals().addAll(DrillUserPrincipal.NON_ADMIN_PRINCIPALS);
return identityService.newUserIdentity(subject, userPrincipal, DrillUserPrincipal.NON_ADMIN_USER_ROLES);
}
} catch (final Exception e) {
if (e instanceof UserAuthenticationException) {
logger.debug("Authentication failed for WebUser '{}'", username, e);
} else {
logger.error("Unexpected failure occurred for WebUser {} during login.", username, e);
}
return null;
}
}
Aggregations