Search in sources :

Example 1 with KrbConfig

use of org.apache.kerby.kerberos.kerb.client.KrbConfig 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 KrbConfig

use of org.apache.kerby.kerberos.kerb.client.KrbConfig 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 3 with KrbConfig

use of org.apache.kerby.kerberos.kerb.client.KrbConfig in project testcases by coheigea.

the class AuthenticationTest method unitTestUsingKrb5Conf.

@org.junit.Test
public void unitTestUsingKrb5Conf() throws Exception {
    File confFile = new File(System.getProperty(Krb5Conf.KRB5_CONF));
    KrbConfig krbConfig = new KrbConfig();
    krbConfig.addKrb5Config(confFile);
    KrbClient client = new KrbClient(krbConfig);
    client.init();
    TgtTicket tgt;
    SgtTicket tkt;
    try {
        tgt = client.requestTgt("alice@service.ws.apache.org", "alice");
        assertTrue(tgt != null);
        tkt = client.requestSgt(tgt, "bob/service.ws.apache.org@service.ws.apache.org");
        assertTrue(tkt != null);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
}
Also used : TgtTicket(org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket) KrbConfig(org.apache.kerby.kerberos.kerb.client.KrbConfig) SgtTicket(org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket) KrbClient(org.apache.kerby.kerberos.kerb.client.KrbClient) File(java.io.File) KrbException(org.apache.kerby.kerberos.kerb.KrbException) GSSException(org.ietf.jgss.GSSException)

Example 4 with KrbConfig

use of org.apache.kerby.kerberos.kerb.client.KrbConfig in project calcite-avatica by apache.

the class HttpServerSpnegoWithoutJaasTest 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, HttpServerSpnegoWithoutJaasTest.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, HttpServerSpnegoWithoutJaasTest.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);
    // Kerby sets "java.security.krb5.conf" for us!
    System.clearProperty("java.security.auth.login.config");
    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 use `withAutomaticLogin(File)` here which should invalidate the need to do JAAS config
    httpServer = new HttpServer.Builder().withPort(0).withAutomaticLogin(serverKeytab).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);
}
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)

Aggregations

File (java.io.File)4 KrbConfig (org.apache.kerby.kerberos.kerb.client.KrbConfig)4 SimpleKdcServer (org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)3 URL (java.net.URL)2 SpnegoTestUtil (org.apache.calcite.avatica.SpnegoTestUtil)2 BeforeClass (org.junit.BeforeClass)2 KrbException (org.apache.kerby.kerberos.kerb.KrbException)1 KrbClient (org.apache.kerby.kerberos.kerb.client.KrbClient)1 SgtTicket (org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket)1 TgtTicket (org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket)1 GSSException (org.ietf.jgss.GSSException)1