Search in sources :

Example 11 with SimpleKdcServer

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

the class StormKerbyTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    System.setProperty("sun.security.krb5.debug", "true");
    // System.setProperty("java.security.auth.login.config", basedir + "/target/test-classes/kerberos/kerberos.jaas");
    kerbyServer = new SimpleKdcServer();
    kerbyServer.getKdcConfig().setBoolean(KrbConfigKey.PREAUTH_REQUIRED, false);
    kerbyServer.setKdcRealm("storm.apache.org");
    kerbyServer.setAllowUdp(false);
    kerbyServer.setWorkDir(new File(basedir + "/target"));
    // kerbyServer.setInnerKdcImpl(new NettyKdcServerImpl(kerbyServer.getKdcSetting()));
    kerbyServer.init();
    // Create principals
    String zookeeper = "zookeeper/localhost@storm.apache.org";
    String zookeeper_client = "zookeeper-client@storm.apache.org";
    String storm = "storm/localhost@storm.apache.org";
    String storm_client = "storm-client@storm.apache.org";
    String alice = "alice@storm.apache.org";
    String http = "HTTP/localhost@storm.apache.org";
    kerbyServer.createPrincipal(zookeeper, "zookeeper");
    File keytabFile = new File(basedir + "/target/zookeeper.keytab");
    kerbyServer.exportPrincipal(zookeeper, keytabFile);
    kerbyServer.createPrincipal(zookeeper_client, "zookeeper-client");
    keytabFile = new File(basedir + "/target/zookeeper_client.keytab");
    kerbyServer.exportPrincipal(zookeeper_client, keytabFile);
    kerbyServer.createPrincipal(storm, "storm");
    keytabFile = new File(basedir + "/target/storm.keytab");
    kerbyServer.exportPrincipal(storm, keytabFile);
    kerbyServer.createPrincipal(storm_client, "storm-client");
    keytabFile = new File(basedir + "/target/storm_client.keytab");
    kerbyServer.exportPrincipal(storm_client, keytabFile);
    kerbyServer.createPrincipal(alice, "alice");
    keytabFile = new File(basedir + "/target/alice.keytab");
    kerbyServer.exportPrincipal(alice, keytabFile);
    kerbyServer.createPrincipal(http, "http");
    keytabFile = new File(basedir + "/target/http.keytab");
    kerbyServer.exportPrincipal(http, keytabFile);
    kerbyServer.start();
}
Also used : File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer) BeforeClass(org.junit.BeforeClass)

Example 12 with SimpleKdcServer

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

the class AnonymousPKInitTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    WSSConfig.init();
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    System.setProperty("sun.security.krb5.debug", "true");
    System.setProperty("java.security.auth.login.config", basedir + "/target/test-classes/kerberos/kerberos.jaas");
    kerbyServer = new SimpleKdcServer();
    kerbyServer.setKdcRealm("service.ws.apache.org");
    kerbyServer.setAllowUdp(true);
    kerbyServer.setWorkDir(new File(basedir + "/target"));
    kerbyServer.setInnerKdcImpl(new NettyKdcServerImpl(kerbyServer.getKdcSetting()));
    // kerbyServer.getKdcConfig().setString(KdcConfigKey.PKINIT_IDENTITY, "myclient.cer");
    String pkinitIdentity = AnonymousPKInitTest.class.getResource("/kdccerttest.pem").getPath();
    // TODO private key should be required?+ AnonymousPKInitTest.class.getResource("/kdckey.pem").getPath();
    kerbyServer.getKdcConfig().setString(KdcConfigKey.PKINIT_IDENTITY, pkinitIdentity);
    kerbyServer.getKdcConfig().setBoolean(KdcConfigKey.PREAUTH_REQUIRED, Boolean.TRUE);
    kerbyServer.init();
    // Create principals
    String alice = "alice@service.ws.apache.org";
    String bob = "bob/service.ws.apache.org@service.ws.apache.org";
    kerbyServer.createPrincipal(alice, "alice");
    kerbyServer.createPrincipal(bob, "bob");
    kerbyServer.createPrincipal(KrbConstant.ANONYMOUS_PRINCIPAL + "@service.ws.apache.org");
    kerbyServer.start();
    System.setProperty("java.security.krb5.conf", basedir + "/target/krb5.conf");
}
Also used : NettyKdcServerImpl(org.apache.kerby.kerberos.kdc.impl.NettyKdcServerImpl) File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer) BeforeClass(org.junit.BeforeClass)

Example 13 with SimpleKdcServer

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

the class TokenPreAuthTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    WSSConfig.init();
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    System.setProperty("sun.security.krb5.debug", "true");
    System.setProperty("java.security.auth.login.config", basedir + "/target/test-classes/kerberos/kerberos.jaas");
    KrbRuntime.setTokenProvider(new JwtTokenProvider());
    kerbyServer = new SimpleKdcServer();
    kerbyServer.setKdcRealm("service.ws.apache.org");
    kerbyServer.setAllowUdp(true);
    kerbyServer.setWorkDir(new File(basedir + "/target"));
    kerbyServer.setInnerKdcImpl(new NettyKdcServerImpl(kerbyServer.getKdcSetting()));
    kerbyServer.getKdcConfig().setString(KdcConfigKey.TOKEN_ISSUERS, "DoubleItSTSIssuer");
    kerbyServer.getKdcConfig().setString(KdcConfigKey.TOKEN_VERIFY_KEYS, "myclient.cer");
    kerbyServer.init();
    // Create principals
    String alice = "alice@service.ws.apache.org";
    String bob = "bob/service.ws.apache.org@service.ws.apache.org";
    kerbyServer.createPrincipal(alice, "alice");
    kerbyServer.createPrincipal(bob, "bob");
    kerbyServer.start();
    System.setProperty("java.security.krb5.conf", basedir + "/target/krb5.conf");
}
Also used : JwtTokenProvider(org.apache.kerby.kerberos.provider.token.JwtTokenProvider) NettyKdcServerImpl(org.apache.kerby.kerberos.kdc.impl.NettyKdcServerImpl) File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer) BeforeClass(org.junit.BeforeClass)

Example 14 with SimpleKdcServer

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

the class TestSpnegoHttpServer method buildMiniKdc.

private static SimpleKdcServer buildMiniKdc() throws Exception {
    SimpleKdcServer kdc = new SimpleKdcServer();
    final File target = new File(System.getProperty("user.dir"), "target");
    File kdcDir = new File(target, TestSpnegoHttpServer.class.getSimpleName());
    if (kdcDir.exists()) {
        deleteRecursively(kdcDir);
    }
    kdcDir.mkdirs();
    kdc.setWorkDir(kdcDir);
    kdc.setKdcHost(KDC_SERVER_HOST);
    int kdcPort = getFreePort();
    kdc.setAllowTcp(true);
    kdc.setAllowUdp(false);
    kdc.setKdcTcpPort(kdcPort);
    LOG.info("Starting KDC server at " + KDC_SERVER_HOST + ":" + kdcPort);
    kdc.init();
    return kdc;
}
Also used : File(java.io.File) SimpleKdcServer(org.apache.kerby.kerberos.kerb.server.SimpleKdcServer)

Example 15 with SimpleKdcServer

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

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