org.springframework.security.kerberos.test.MiniKdc 不提供 MiniKdc

MiniKdc not available from org.springframework.security.kerberos.test.MiniKdc

我正在尝试在我的代码实现中使用“MiniKdc”,例如“MiniKdc.main(config)”,但出现错误“无法解析符号 'MiniKdc'”。

我正在学习这个例子https://www.baeldung.com/spring-security-kerberos-integration

我已经在我的 build.gradle 中添加了这个依赖项 实施 'org.springframework.security.kerberos:spring-security-kerberos-test:1.0.1.RELEASE'

我试图从 maven central/repository 中搜索依赖项,但我找不到它。

这是我正在处理的 class,我希望能够在第二个导入语句中导入 Minikdc。

import org.apache.commons.io.FileUtils;
import org.springframework.security.kerberos.test.MiniKdc;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

class KerberosMiniKdc {

    private static final String KRB_WORK_DIR = ".\spring-security-sso\spring-security-sso-kerberos\krb-test-workdir";

    public static void main(String[] args) throws Exception {

        String[] config = MiniKdcConfigBuilder.builder()
                .workDir(prepareWorkDir())
                .confDir("minikdc-krb5.conf")
                .keytabName("example.keytab")
                .principals("client/localhost", "HTTP/localhost")
                .build();

        MiniKdc.main(config);
    }

    private static String prepareWorkDir() throws IOException {
        Path dir = Paths.get(KRB_WORK_DIR);
        File directory = dir.normalize().toFile();

        FileUtils.deleteQuietly(directory);
        FileUtils.forceMkdir(directory);
        return dir.toString();
    }
}

有什么地方做错了吗?

截至 2021 年,spring-security-kerberos is not well maintained

我建议使用 Apache Kerby instead, either directly or via other library like Kerb4J. See an example here

package com.kerb4j;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.kerby.kerberos.kerb.client.KrbConfig;
import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

import java.io.File;

public class KerberosSecurityTestcase {

    private static final Log log = LogFactory.getLog(KerberosSecurityTestcase.class);
    private static int i = 10000;
    protected int kdcPort;
    private SimpleKdcServer kdc;
    private File workDir;
    private KrbConfig conf;

    @BeforeAll
    public static void debugKerberos() {
        System.setProperty("sun.security.krb5.debug", "true");
    }

    @BeforeEach
    public void startMiniKdc() throws Exception {

        kdcPort = i++;

        createTestDir();
        createMiniKdcConf();

        log.info("Starting Simple KDC server on port " + kdcPort);

        kdc = new SimpleKdcServer(workDir, conf);
        kdc.setKdcPort(kdcPort);
        kdc.setAllowUdp(false);
        kdc.init();
        kdc.start();
    }

    @AfterEach
    public void stopMiniKdc() throws Exception {
        log.info("Stopping Simple KDC server on port " + kdcPort);
        if (kdc != null) {
            kdc.stop();
            log.info("Stopped Simple KDC server on port " + kdcPort);
        }
    }

    public void createTestDir() {
        workDir = new File(System.getProperty("test.dir", "target"));
    }

    public void createMiniKdcConf() {
        conf = new KrbConfig();
    }

    public SimpleKdcServer getKdc() {
        return kdc;
    }

    public File getWorkDir() {
        return workDir;
    }

    public KrbConfig getConf() {
        return conf;
    }

}

免责声明:我是 Kerb4J

的作者