All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.trustedanalytics.servicebroker.h2oprovisioner.cdhclients.KerberosClient Maven / Gradle / Ivy

There is a newer version: 0.6.9
Show newest version
/**
 * Copyright (c) 2015 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.trustedanalytics.servicebroker.h2oprovisioner.cdhclients;

import java.io.IOException;

import javax.security.auth.login.LoginException;

import org.apache.hadoop.conf.Configuration;
import org.trustedanalytics.hadoop.kerberos.KrbLoginManager;
import org.trustedanalytics.hadoop.kerberos.KrbLoginManagerFactory;
import org.trustedanalytics.servicebroker.h2oprovisioner.config.KerberosProperties;

public class KerberosClient {

  private final String kdc;
  private final String realm;
  private final String user;
  private final char[] password;

  public KerberosClient(KerberosProperties kerberosProperties) {
    this.kdc = kerberosProperties.getKdc();
    this.realm = kerberosProperties.getRealm();
    this.user = kerberosProperties.getUser();
    this.password = kerberosProperties.getPassword().toCharArray();
  }

  public Configuration logInToKerberos(Configuration hadoopConf)
      throws LoginException, IOException {
    KrbLoginManager krbLoginManager =
        KrbLoginManagerFactory.getInstance().getKrbLoginManagerInstance(kdc, realm);
    krbLoginManager.loginInHadoop(krbLoginManager.loginWithCredentials(user, password), hadoopConf);
    return hadoopConf;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy