kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Krb5Conf.java [32:86]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class Krb5Conf {
    public static final String KRB5_CONF = "java.security.krb5.conf";
    private static final String KRB5_CONF_FILE = "krb5.conf";
    private File confDir;
    private KdcConfig kdcConfig;

    public Krb5Conf(File confDir, KdcConfig kdcConfig) {
        this.confDir = confDir;
        this.kdcConfig = kdcConfig;
    }

    public void initKrb5conf() throws IOException {
        File confFile = generateConfFile();
        System.setProperty(KRB5_CONF, confFile.getAbsolutePath());
    }

    // Read in krb5.conf and substitute in the correct port
    private File generateConfFile() throws IOException {

        String resourcePath = kdcConfig.allowUdp() ? "/krb5_udp.conf" : "/krb5.conf";
        String templateContent;
        try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) {
            templateContent = IOUtil.readInput(templateResource);
        }

        String content = templateContent;

        content = content.replaceAll("_REALM_", "" + kdcConfig.getKdcRealm());
        content = content.replaceAll("_KDC_HOST_", "" + kdcConfig.getKdcHost());

        int kdcPort = kdcConfig.allowUdp() ? kdcConfig.getKdcUdpPort()
                : kdcConfig.getKdcTcpPort();
        content = content.replaceAll("_KDC_PORT_",
                String.valueOf(kdcPort));

        if (kdcConfig.allowTcp()) {
            content = content.replaceAll("#_KDC_TCP_PORT_", "kdc_tcp_port = " + kdcConfig.getKdcTcpPort());
        }
        if (kdcConfig.allowUdp()) {
            content = content.replaceAll("#_KDC_UDP_PORT_", "kdc_udp_port = " + kdcConfig.getKdcUdpPort());
        }

        int udpLimit = kdcConfig.allowUdp() ? 4096 : 1;
        content = content.replaceAll("_UDP_LIMIT_", String.valueOf(udpLimit));

        File confFile = new File(confDir, KRB5_CONF_FILE);
        if (confFile.exists()) {
            boolean delete = confFile.delete();
            if (!delete) {
                throw new RuntimeException("File delete error!");
            }
        }
        IOUtil.writeFile(content, confFile);

        return confFile;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Krb5Conf.java [32:86]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class Krb5Conf {
    public static final String KRB5_CONF = "java.security.krb5.conf";
    private static final String KRB5_CONF_FILE = "krb5.conf";
    private File confDir;
    private KdcConfig kdcConfig;

    public Krb5Conf(File confDir, KdcConfig kdcConfig) {
        this.confDir = confDir;
        this.kdcConfig = kdcConfig;
    }

    public void initKrb5conf() throws IOException {
        File confFile = generateConfFile();
        System.setProperty(KRB5_CONF, confFile.getAbsolutePath());
    }

    // Read in krb5.conf and substitute in the correct port
    private File generateConfFile() throws IOException {

        String resourcePath = kdcConfig.allowUdp() ? "/krb5_udp.conf" : "/krb5.conf";
        String templateContent;
        try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) {
            templateContent = IOUtil.readInput(templateResource);
        }

        String content = templateContent;

        content = content.replaceAll("_REALM_", "" + kdcConfig.getKdcRealm());
        content = content.replaceAll("_KDC_HOST_", "" + kdcConfig.getKdcHost());

        int kdcPort = kdcConfig.allowUdp() ? kdcConfig.getKdcUdpPort()
                : kdcConfig.getKdcTcpPort();
        content = content.replaceAll("_KDC_PORT_",
                String.valueOf(kdcPort));

        if (kdcConfig.allowTcp()) {
            content = content.replaceAll("#_KDC_TCP_PORT_", "kdc_tcp_port = " + kdcConfig.getKdcTcpPort());
        }
        if (kdcConfig.allowUdp()) {
            content = content.replaceAll("#_KDC_UDP_PORT_", "kdc_udp_port = " + kdcConfig.getKdcUdpPort());
        }

        int udpLimit = kdcConfig.allowUdp() ? 4096 : 1;
        content = content.replaceAll("_UDP_LIMIT_", String.valueOf(udpLimit));

        File confFile = new File(confDir, KRB5_CONF_FILE);
        if (confFile.exists()) {
            boolean delete = confFile.delete();
            if (!delete) {
                throw new RuntimeException("File delete error!");
            }
        }
        IOUtil.writeFile(content, confFile);

        return confFile;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



