Search in sources :

Example 1 with HiveMetastoreClientFactoryImpl

use of org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactoryImpl in project hive by apache.

the class ResourceMaps method setupAuth.

/**
 * Setup authentication and authorization plugins for this session.
 */
private void setupAuth() {
    if (authenticator != null) {
        // auth has been initialized
        return;
    }
    try {
        authenticator = HiveUtils.getAuthenticator(sessionConf, HiveConf.ConfVars.HIVE_AUTHENTICATOR_MANAGER);
        authenticator.setSessionState(this);
        String clsStr = HiveConf.getVar(sessionConf, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER);
        authorizer = HiveUtils.getAuthorizeProviderManager(sessionConf, clsStr, authenticator, true);
        if (authorizer == null) {
            // if it was null, the new (V2) authorization plugin must be specified in
            // config
            HiveAuthorizerFactory authorizerFactory = HiveUtils.getAuthorizerFactory(sessionConf, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER);
            HiveAuthzSessionContext.Builder authzContextBuilder = new HiveAuthzSessionContext.Builder();
            authzContextBuilder.setClientType(isHiveServerQuery() ? CLIENT_TYPE.HIVESERVER2 : CLIENT_TYPE.HIVECLI);
            authzContextBuilder.setSessionString(getSessionId());
            authorizerV2 = authorizerFactory.createHiveAuthorizer(new HiveMetastoreClientFactoryImpl(), sessionConf, authenticator, authzContextBuilder.build());
            setAuthorizerV2Config();
        }
        // create the create table grants with new config
        createTableGrants = CreateTableAutomaticGrant.create(sessionConf);
    } catch (HiveException e) {
        LOG.error("Error setting up authorization: " + e.getMessage(), e);
        throw new RuntimeException(e);
    }
    if (LOG.isDebugEnabled()) {
        Object authorizationClass = getActiveAuthorizer();
        LOG.debug("Session is using authorization class " + authorizationClass.getClass());
    }
    return;
}
Also used : HiveAuthorizerFactory(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) HiveAuthzSessionContext(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext) HiveMetastoreClientFactoryImpl(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactoryImpl)

Aggregations

HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 HiveAuthorizerFactory (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory)1 HiveAuthzSessionContext (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext)1 HiveMetastoreClientFactoryImpl (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactoryImpl)1