Search in sources :

Example 56 with AuthenticationResult

use of org.apache.druid.server.security.AuthenticationResult in project druid by druid-io.

the class DruidMeta method authenticateConnection.

@Nullable
private AuthenticationResult authenticateConnection(final DruidConnection connection) {
    Map<String, Object> context = connection.context();
    for (Authenticator authenticator : authenticators) {
        LOG.debug("Attempting authentication with authenticator[%s]", authenticator.getClass());
        AuthenticationResult authenticationResult = authenticator.authenticateJDBCContext(context);
        if (authenticationResult != null) {
            LOG.debug("Authenticated identity[%s] for connection[%s]", authenticationResult.getIdentity(), connection.getConnectionId());
            return authenticationResult;
        }
    }
    LOG.debug("No successful authentication");
    return null;
}
Also used : Authenticator(org.apache.druid.server.security.Authenticator) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) Nullable(javax.annotation.Nullable)

Example 57 with AuthenticationResult

use of org.apache.druid.server.security.AuthenticationResult in project druid by druid-io.

the class DruidMeta method prepareAndExecute.

@Override
public ExecuteResult prepareAndExecute(final StatementHandle statement, final String sql, final long maxRowCount, final int maxRowsInFirstFrame, final PrepareCallback callback) throws NoSuchStatementException {
    try {
        // Ignore "callback", this class is designed for use with LocalService which doesn't use it.
        final DruidStatement druidStatement = getDruidStatement(statement);
        final DruidConnection druidConnection = getDruidConnection(statement.connectionId);
        AuthenticationResult authenticationResult = authenticateConnection(druidConnection);
        if (authenticationResult == null) {
            throw logFailure(new ForbiddenException("Authentication failed."), "Authentication failed for statement[%s]", druidStatement.getStatementId());
        }
        druidStatement.prepare(sql, maxRowCount, authenticationResult);
        final Frame firstFrame = druidStatement.execute(Collections.emptyList()).nextFrame(DruidStatement.START_OFFSET, getEffectiveMaxRowsPerFrame(maxRowsInFirstFrame));
        final Signature signature = druidStatement.getSignature();
        LOG.debug("Successfully prepared statement[%s] and started execution", druidStatement.getStatementId());
        return new ExecuteResult(ImmutableList.of(MetaResultSet.create(statement.connectionId, statement.id, false, signature, firstFrame)));
    }// cannot affect these exceptions as avatica handles them
     catch (NoSuchConnectionException | NoSuchStatementException e) {
        throw e;
    } catch (Throwable t) {
        throw errorHandler.sanitize(t);
    }
}
Also used : ForbiddenException(org.apache.druid.server.security.ForbiddenException) NoSuchConnectionException(org.apache.calcite.avatica.NoSuchConnectionException) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

Example 58 with AuthenticationResult

use of org.apache.druid.server.security.AuthenticationResult in project druid by druid-io.

the class SqlLifecycle method validateAndAuthorize.

/**
 * Validate SQL query and authorize against any datasources or views which the query. Like
 * {@link #validateAndAuthorize(AuthenticationResult)} but for a {@link HttpServletRequest}.
 *
 * If successful, the lifecycle will first transition from {@link State#INITIALIZED} first to
 * {@link State#AUTHORIZING} and then to either {@link State#AUTHORIZED} or {@link State#UNAUTHORIZED}.
 */
public void validateAndAuthorize(HttpServletRequest req) {
    transition(State.INITIALIZED, State.AUTHORIZING);
    AuthenticationResult authResult = AuthorizationUtils.authenticationResultFromRequest(req);
    validate(authResult);
    Access access = doAuthorize(AuthorizationUtils.authorizeAllResourceActions(req, validationResult.getResourceActions(), plannerFactory.getAuthorizerMapper()));
    checkAccess(access);
}
Also used : Access(org.apache.druid.server.security.Access) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

Aggregations

AuthenticationResult (org.apache.druid.server.security.AuthenticationResult)58 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)25 Access (org.apache.druid.server.security.Access)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Resource (org.apache.druid.server.security.Resource)12 HashMap (java.util.HashMap)10 List (java.util.List)10 AuthConfig (org.apache.druid.server.security.AuthConfig)10 Authorizer (org.apache.druid.server.security.Authorizer)10 ImmutableList (com.google.common.collect.ImmutableList)9 Map (java.util.Map)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 AuthorizerMapper (org.apache.druid.server.security.AuthorizerMapper)8 FilterChain (javax.servlet.FilterChain)7 Action (org.apache.druid.server.security.Action)7 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 TreeMap (java.util.TreeMap)6 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)6