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();
}
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");
}
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();
}
}
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);
}
Aggregations