Search in sources :

Example 1 with SimpleKdcServer

use of org.apache.kerby.kerberos.kerb.server.SimpleKdcServer in project calcite-avatica by apache.

the class HttpServerSpnegoWithJaasTest method setupKdc.

@BeforeClass
public static void setupKdc() throws Exception {
    kdc = new SimpleKdcServer();
    File target = new File(System.getProperty("user.dir"), "target");
    assertTrue(target.exists());
    File kdcDir = new File(target, HttpServerSpnegoWithJaasTest.class.getSimpleName());
    if (kdcDir.exists()) {
        SpnegoTestUtil.deleteRecursively(kdcDir);
    }
    kdcDir.mkdirs();
    kdc.setWorkDir(kdcDir);
    kdc.setKdcHost(SpnegoTestUtil.KDC_HOST);
    kdcPort = SpnegoTestUtil.getFreePort();
    kdc.setAllowTcp(true);
    kdc.setAllowUdp(false);
    kdc.setKdcTcpPort(kdcPort);
    LOG.info("Starting KDC server at {}:{}", SpnegoTestUtil.KDC_HOST, kdcPort);
    kdc.init();
    kdc.start();
    isKdcStarted = true;
    File keytabDir = new File(target, HttpServerSpnegoWithJaasTest.class.getSimpleName() + "_keytabs");
    if (keytabDir.exists()) {
        SpnegoTestUtil.deleteRecursively(keytabDir);
    }
    keytabDir.mkdirs();
    setupUsers(keytabDir);
    clientConfig = new KrbConfig();
    clientConfig.setString(KrbConfigKey.KDC_HOST, SpnegoTestUtil.KDC_HOST);
    clientConfig.setInt(KrbConfigKey.KDC_TCP_PORT, kdcPort);
    clientConfig.setString(KrbConfigKey.DEFAULT_REALM, SpnegoTestUtil.REALM);
    serverSpnegoConfigFile = new File(kdcDir, "server-spnego.conf");
    SpnegoTestUtil.writeSpnegoConf(serverSpnegoConfigFile, serverKeytab);
    // Kerby sets "java.security.krb5.conf" for us!
    System.setProperty("java.security.auth.login.config", serverSpnegoConfigFile.toString());
    // http://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/...
    //    tutorials/BasicClientServer.html#useSub
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
    //System.setProperty("sun.security.spnego.debug", "true");
    //System.setProperty("sun.security.krb5.debug", "true");
    // Create and start an HTTP server configured only to allow SPNEGO requests
    // We're not using `withAutomaticLogin(File)` which means we're relying on JAAS to log the
    // server in.
    httpServer = new HttpServer.Builder().withPort(0).withSpnego(SpnegoTestUtil.SERVER_PRINCIPAL, SpnegoTestUtil.REALM).withHandler(new SpnegoTestUtil.AuthenticationRequiredAvaticaHandler()).build();
    httpServer.start();
    isHttpServerStarted = true;
    httpServerUrl = new URL("http://" + SpnegoTestUtil.KDC_HOST + ":" + httpServer.getPort());
    LOG.info("HTTP server running at {}", httpServerUrl);
    SpnegoTestUtil.refreshJaasConfiguration();
}
Also used : SpnegoTestUtil(org.apache.calcite.avatica.SpnegoTestUtil) KrbConfig(org.apache.kerby.kerberos.kerb.client.KrbConfig) File(java.io.File) URL(java.net.URL) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer) BeforeClass(org.junit.BeforeClass)

Example 2 with SimpleKdcServer

use of org.apache.kerby.kerberos.kerb.server.SimpleKdcServer in project drill by apache.

the class KerberosHelper method setupKdc.

public void setupKdc() throws Exception {
    kdc = new SimpleKdcServer();
    workspace = new File(getTempDir("kerberos_target"));
    kdcDir = new File(workspace, testName);
    if (!kdcDir.mkdirs()) {
        throw new Exception(String.format("Failed to create the kdc directory %s", kdcDir.getName()));
    }
    kdc.setWorkDir(kdcDir);
    kdc.setKdcHost(HOSTNAME);
    kdcPort = getFreePort();
    kdc.setAllowTcp(true);
    kdc.setAllowUdp(false);
    kdc.setKdcTcpPort(kdcPort);
    logger.debug("Starting KDC server at {}:{}", HOSTNAME, kdcPort);
    kdc.init();
    kdc.start();
    kdcStarted = true;
    keytabDir = new File(workspace, testName + "_keytabs");
    if (!keytabDir.mkdirs()) {
        throw new Exception(String.format("Failed to create the keytab directory %s", keytabDir.getName()));
    }
    setupUsers(keytabDir);
    // Kerby sets "java.security.krb5.conf" for us!
    System.clearProperty("java.security.auth.login.config");
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
// Uncomment the following lines for debugging.
// System.setProperty("sun.security.spnego.debug", "true");
// System.setProperty("sun.security.krb5.debug", "true");
}
Also used : File(java.io.File) IOException(java.io.IOException) KrbException(org.apache.kerby.kerberos.kerb.KrbException) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)

Example 3 with SimpleKdcServer

use of org.apache.kerby.kerberos.kerb.server.SimpleKdcServer in project calcite-avatica by apache.

the class AvaticaSpnegoTest method setupKdc.

private static void setupKdc() throws Exception {
    kdc = new SimpleKdcServer();
    File target = new File(System.getProperty("user.dir"), "target");
    assertTrue(target.exists());
    File kdcDir = new File(target, AvaticaSpnegoTest.class.getSimpleName());
    if (kdcDir.exists()) {
        SpnegoTestUtil.deleteRecursively(kdcDir);
    }
    kdcDir.mkdirs();
    kdc.setWorkDir(kdcDir);
    kdc.setKdcHost(SpnegoTestUtil.KDC_HOST);
    kdcPort = SpnegoTestUtil.getFreePort();
    kdc.setAllowTcp(true);
    kdc.setAllowUdp(false);
    kdc.setKdcTcpPort(kdcPort);
    LOG.info("Starting KDC server at {}:{}", SpnegoTestUtil.KDC_HOST, kdcPort);
    kdc.init();
    kdc.start();
    isKdcStarted = true;
    keytabDir = new File(target, AvaticaSpnegoTest.class.getSimpleName() + "_keytabs");
    if (keytabDir.exists()) {
        SpnegoTestUtil.deleteRecursively(keytabDir);
    }
    keytabDir.mkdirs();
    setupServerUser(keytabDir);
    clientConfig = new KrbConfig();
    clientConfig.setString(KrbConfigKey.KDC_HOST, SpnegoTestUtil.KDC_HOST);
    clientConfig.setInt(KrbConfigKey.KDC_TCP_PORT, kdcPort);
    clientConfig.setString(KrbConfigKey.DEFAULT_REALM, SpnegoTestUtil.REALM);
    // Kerby sets "java.security.krb5.conf" for us!
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
//System.setProperty("sun.security.spnego.debug", "true");
//System.setProperty("sun.security.krb5.debug", "true");
}
Also used : KrbConfig(org.apache.kerby.kerberos.kerb.client.KrbConfig) File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)

Example 4 with SimpleKdcServer

use of org.apache.kerby.kerberos.kerb.server.SimpleKdcServer in project hadoop by apache.

the class MiniKdc method start.

/**
   * Starts the MiniKdc.
   *
   * @throws Exception thrown if the MiniKdc could not be started.
   */
public synchronized void start() throws Exception {
    if (simpleKdc != null) {
        throw new RuntimeException("Already started");
    }
    simpleKdc = new SimpleKdcServer();
    prepareKdcServer();
    simpleKdc.init();
    resetDefaultRealm();
    simpleKdc.start();
    LOG.info("MiniKdc started.");
}
Also used : SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)

Example 5 with SimpleKdcServer

use of org.apache.kerby.kerberos.kerb.server.SimpleKdcServer in project ranger by apache.

the class KafkaRangerAuthorizerGSSTest method configureKerby.

private static void configureKerby(String baseDir) throws Exception {
    // System.setProperty("sun.security.krb5.debug", "true");
    System.setProperty("java.security.krb5.conf", baseDir + "/target/krb5.conf");
    kerbyServer = new SimpleKdcServer();
    kerbyServer.setKdcRealm("kafka.apache.org");
    kerbyServer.setAllowUdp(false);
    kerbyServer.setWorkDir(new File(baseDir + "/target"));
    kerbyServer.init();
    // Create principals
    String zookeeper = "zookeeper/localhost@kafka.apache.org";
    String kafka = "kafka/localhost@kafka.apache.org";
    String client = "client@kafka.apache.org";
    kerbyServer.createPrincipal(zookeeper, "zookeeper");
    File keytabFile = new File(baseDir + "/target/zookeeper.keytab");
    kerbyServer.exportPrincipal(zookeeper, keytabFile);
    kerbyServer.createPrincipal(kafka, "kafka");
    keytabFile = new File(baseDir + "/target/kafka.keytab");
    kerbyServer.exportPrincipal(kafka, keytabFile);
    kerbyServer.createPrincipal(client, "client");
    keytabFile = new File(baseDir + "/target/client.keytab");
    kerbyServer.exportPrincipal(client, keytabFile);
    kerbyServer.start();
}
Also used : File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)

Aggregations

SimpleKdcServer (org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)25 File (java.io.File)22 BeforeClass (org.junit.BeforeClass)14 NettyKdcServerImpl (org.apache.kerby.kerberos.kdc.impl.NettyKdcServerImpl)6 KrbConfig (org.apache.kerby.kerberos.kerb.client.KrbConfig)3 IOException (java.io.IOException)2 URL (java.net.URL)2 SpnegoTestUtil (org.apache.calcite.avatica.SpnegoTestUtil)2 KrbException (org.apache.kerby.kerberos.kerb.KrbException)2 JwtTokenProvider (org.apache.kerby.kerberos.provider.token.JwtTokenProvider)2 Provider (java.security.Provider)1 STSServer (org.apache.cxf.systest.kerberos.wssec.sts.STSServer)1 StaxSTSServer (org.apache.cxf.systest.kerberos.wssec.sts.StaxSTSServer)1 KerbyGssProvider (org.apache.kerby.kerberos.kerb.gss.KerbyGssProvider)1