Example usage for org.apache.hadoop.minikdc MiniKdc KDC_BIND_ADDRESS

List of usage examples for org.apache.hadoop.minikdc MiniKdc KDC_BIND_ADDRESS

Introduction

In this page you can find the example usage for org.apache.hadoop.minikdc MiniKdc KDC_BIND_ADDRESS.

Prototype

String KDC_BIND_ADDRESS

To view the source code for org.apache.hadoop.minikdc MiniKdc KDC_BIND_ADDRESS.

Click Source Link

Usage

From source file:org.apache.flink.test.util.SecureTestEnvironment.java

License:Apache License

public static void prepare(TemporaryFolder tempFolder) {

    try {/*from   w  w  w.jav  a2s  .c o m*/
        File baseDirForSecureRun = tempFolder.newFolder();
        LOG.info("Base Directory for Secure Environment: {}", baseDirForSecureRun);

        String hostName = "localhost";
        Properties kdcConf = MiniKdc.createConf();
        if (LOG.isDebugEnabled()) {
            kdcConf.setProperty(MiniKdc.DEBUG, "true");
        }
        kdcConf.setProperty(MiniKdc.KDC_BIND_ADDRESS, hostName);
        kdc = new MiniKdc(kdcConf, baseDirForSecureRun);
        kdc.start();
        LOG.info("Started Mini KDC");

        File keytabFile = new File(baseDirForSecureRun, "test-users.keytab");
        testKeytab = keytabFile.getAbsolutePath();
        testZkServerPrincipal = "zookeeper/127.0.0.1";
        testZkClientPrincipal = "zk-client/127.0.0.1";
        testKafkaServerPrincipal = "kafka/" + hostName;
        hadoopServicePrincipal = "hadoop/" + hostName;
        testPrincipal = "client/" + hostName;

        kdc.createPrincipal(keytabFile, testPrincipal, testZkServerPrincipal, hadoopServicePrincipal,
                testZkClientPrincipal, testKafkaServerPrincipal);

        testPrincipal = testPrincipal + "@" + kdc.getRealm();
        testZkServerPrincipal = testZkServerPrincipal + "@" + kdc.getRealm();
        testZkClientPrincipal = testZkClientPrincipal + "@" + kdc.getRealm();
        testKafkaServerPrincipal = testKafkaServerPrincipal + "@" + kdc.getRealm();
        hadoopServicePrincipal = hadoopServicePrincipal + "@" + kdc.getRealm();

        LOG.info("-------------------------------------------------------------------");
        LOG.info("Test Principal: {}", testPrincipal);
        LOG.info("Test ZK Server Principal: {}", testZkServerPrincipal);
        LOG.info("Test ZK Client Principal: {}", testZkClientPrincipal);
        LOG.info("Test Kafka Server Principal: {}", testKafkaServerPrincipal);
        LOG.info("Test Hadoop Service Principal: {}", hadoopServicePrincipal);
        LOG.info("Test Keytab: {}", testKeytab);
        LOG.info("-------------------------------------------------------------------");

        //Security Context is established to allow non hadoop applications that requires JAAS
        //based SASL/Kerberos authentication to work. However, for Hadoop specific applications
        //the context can be reinitialized with Hadoop configuration by calling
        //ctx.setHadoopConfiguration() for the UGI implementation to work properly.
        //See Yarn test case module for reference
        Configuration flinkConfig = GlobalConfiguration.loadConfiguration();
        flinkConfig.setString(SecurityOptions.KERBEROS_LOGIN_KEYTAB, testKeytab);
        flinkConfig.setBoolean(SecurityOptions.KERBEROS_LOGIN_USETICKETCACHE, false);
        flinkConfig.setString(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, testPrincipal);
        flinkConfig.setString(SecurityOptions.KERBEROS_LOGIN_CONTEXTS, "Client,KafkaClient");
        SecurityUtils.SecurityConfiguration ctx = new SecurityUtils.SecurityConfiguration(flinkConfig);
        TestingSecurityContext.install(ctx, getClientSecurityConfigurationMap());

        populateJavaPropertyVariables();

    } catch (Exception e) {
        throw new RuntimeException("Exception occured while preparing secure environment.", e);
    }

}

From source file:org.kitesdk.minicluster.KdcService.java

License:Apache License

@Override
public void start() throws IOException, InterruptedException {
    Preconditions.checkState(workDir != null,
            "Working directory must be set before starting the mini KDC cluster");

    kdcConf = MiniKdc.createConf();/*  w ww .  ja v  a  2  s  .  c o m*/
    if (bindIP != null) {
        kdcConf.setProperty(MiniKdc.KDC_BIND_ADDRESS, bindIP);
    }
    try {
        kdc = new MiniKdc(kdcConf, getKdcLocation(workDir));
        kdc.start();
    } catch (Exception ex) {
        throw new RuntimeException("Unexpected exception: " + ex.getMessage(), ex);
    }

    getKeytabsLocation(workDir).mkdirs();

    logger.info("KDC Minicluster Service Started.");
}