private void resetDefaultRealm() throws IOException { InputStream templateResource = new FileInputStream( getKrb5conf().getAbsolutePath()); String content = IOUtil.readInput(templateResource); content = content.replaceAll("default_realm = .*\n", "default_realm = " + getRealm() + "\n"); IOUtil.writeFile(content, getKrb5conf()); }
private void persistToFile() throws KrbException { String newJsonContent = gson.toJson(identities); try { File newJsonKdbFile = File.createTempFile("kerby-kdb", ".json", jsonKdbFile.getParentFile()); IOUtil.writeFile(newJsonContent, newJsonKdbFile); boolean delete = jsonKdbFile.delete(); if (!delete) { throw new RuntimeException("File delete error!"); } boolean rename = newJsonKdbFile.renameTo(jsonKdbFile); if (!rename) { throw new RuntimeException("File rename error!"); } kdbFileUpdateTime = jsonKdbFile.lastModified(); } catch (IOException e) { LOG.error("Error occurred while writing identities to file: " + jsonKdbFile); throw new KrbException("Failed to write file", e); } }
private File createClientSSLConfig(String trustStorePath, String trustStorePassword, String keyStorePassword) throws HasException { String resourcePath = "/ssl-client.conf.template"; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { File sslConfigFile = new File("ssl-client.conf"); String content = IOUtil.readInput(templateResource); content = content.replaceAll("_location_", trustStorePath); content = content.replaceAll("_password_", trustStorePassword); content = content.replaceAll("_keyPassword_", keyStorePassword); IOUtil.writeFile(content, sslConfigFile); return sslConfigFile; } catch (IOException e) { throw new HasException("Failed to create client ssl configuration file", e); } }
private void persistToFile() throws KrbException { String newJsonContent = gson.toJson(identities); try { File newJsonKdbFile = File.createTempFile("kerby-kdb", ".json", jsonKdbFile.getParentFile()); IOUtil.writeFile(newJsonContent, newJsonKdbFile); boolean delete = jsonKdbFile.delete(); if (!delete) { throw new RuntimeException("File delete error!"); } boolean rename = newJsonKdbFile.renameTo(jsonKdbFile); if (!rename) { throw new RuntimeException("File rename error!"); } kdbFileUpdateTime = jsonKdbFile.lastModified(); } catch (IOException e) { LOG.error("Error occurred while writing identities to file: " + jsonKdbFile); throw new KrbException("Failed to write file", e); } }
private File createClientSSLConfig(String trustStorePath, String trustStorePassword, String keyStorePassword) throws HasException { String resourcePath = "/ssl-client.conf.template"; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { File sslConfigFile = new File("ssl-client.conf"); String content = IOUtil.readInput(templateResource); content = content.replaceAll("_location_", trustStorePath); content = content.replaceAll("_password_", trustStorePassword); content = content.replaceAll("_keyPassword_", keyStorePassword); IOUtil.writeFile(content, sslConfigFile); return sslConfigFile; } catch (IOException e) { throw new HasException("Failed to create client ssl configuration file", e); } }
/** * Create ssl configuration file for client. * */ private void createClientSSLConfig(String password) throws HasException { String resourcePath = "/ssl-client.conf.template"; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { String content = IOUtil.readInput(templateResource); content = content.replaceAll("_location_", clientConfigFolder.getAbsolutePath() + "/truststore.jks"); content = content.replaceAll("_password_", password); IOUtil.writeFile(content, new File(clientConfigFolder + "/ssl-client.conf")); } catch (IOException e) { throw new HasException("Failed to create client ssl configuration file. " + e.getMessage()); } } }
/** * Create ssl configuration file for client. * */ private void createClientSSLConfig(String password) throws HasException { String resourcePath = "/ssl-client.conf.template"; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { String content = IOUtil.readInput(templateResource); content = content.replaceAll("_location_", clientConfigFolder.getAbsolutePath() + "/truststore.jks"); content = content.replaceAll("_password_", password); IOUtil.writeFile(content, new File(clientConfigFolder + "/ssl-client.conf")); } catch (IOException e) { throw new HasException("Failed to create client ssl configuration file. " + e.getMessage()); } } }
IOUtil.writeFile(content, confFile); } catch (IOException e) { throw new HasException("Write content to conf file failed. " + e.getMessage());
IOUtil.writeFile(content, confFile); } else { throw new HasException("Conf file: " + confName + " not found.");
IOUtil.writeFile(content, confFile); } else { throw new HasException("Conf file: " + confName + " not found.");
IOUtil.writeFile(content, confFile); } catch (IOException e) { throw new HasException("Write content to conf file failed. " + e.getMessage());
/** * Read in has-server.conf and create has-client.conf. * * @return has conf file * @throws IOException e * @throws HasException e */ public File generateHasConf() throws HasException, IOException { Map<String, String> kdcConf = getKdcConf(); String servers = kdcConf.get("servers"); File confFile = new File(getConfDir().getAbsolutePath(), "has-server.conf"); HasConfig hasConfig = HasUtil.getHasConfig(confFile); if (hasConfig != null) { String defaultValue = hasConfig.getHttpsHost(); String content; try (InputStream templateResource = new FileInputStream(confFile)) { content = IOUtil.readInput(templateResource); } content = content.replaceFirst(Pattern.quote(defaultValue), servers); File hasFile = new File(confDir, "has-client.conf"); IOUtil.writeFile(content, hasFile); return hasFile; } else { throw new HasException("has-server.conf not found. "); } }
/** * Read in has-server.conf and create has-client.conf. * * @return has conf file * @throws IOException e * @throws HasException e */ public File generateHasConf() throws HasException, IOException { Map<String, String> kdcConf = getKdcConf(); String servers = kdcConf.get("servers"); File confFile = new File(getConfDir().getAbsolutePath(), "has-server.conf"); HasConfig hasConfig = HasUtil.getHasConfig(confFile); if (hasConfig != null) { String defaultValue = hasConfig.getHttpsHost(); String content; try (InputStream templateResource = new FileInputStream(confFile)) { content = IOUtil.readInput(templateResource); } content = content.replaceFirst(Pattern.quote(defaultValue), servers); File hasFile = new File(confDir, "has-client.conf"); IOUtil.writeFile(content, hasFile); return hasFile; } else { throw new HasException("has-server.conf not found. "); } }
@BeforeClass public static void setup() throws IOException { KRB5_CONF_ROOT_DIR.mkdir(); File krb5ConfFile = new File(KRB5_CONF_ROOT_DIR, "krb5.conf"); krb5ConfFile.createNewFile(); String content = "[libdefaults]\n" + " default_realm = APACHE.ORG\n" + " udp_preference_limit = 1\n"+ " extra_addresses = 127.0.0.1\n" + "[realms]\n" + " APACHE.ORG = {\n" + " admin_server = localhost:88\n" + " kdc = localhost:88\n}\n" + "[domain_realm]\n" + " localhost = APACHE.ORG"; IOUtil.writeFile(content, krb5ConfFile); System.setProperty(KRB5_CONF, krb5ConfFile.getAbsolutePath()); }
IOUtil.writeFile(content, confFile);
IOUtil.writeFile(content, confFile);
IOUtil.writeFile(content, confFile);
private File generateConfFile() throws IOException { KdcSetting setting = kdcServer.getKdcSetting(); String resourcePath = setting.allowUdp() ? "/krb5_udp-template.conf" : "/krb5-template.conf"; String templateContent; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { templateContent = IOUtil.readInput(templateResource); } String content = templateContent; content = content.replaceAll("_REALM_", "" + setting.getKdcRealm()); int kdcPort = setting.allowUdp() ? setting.getKdcUdpPort() : setting.getKdcTcpPort(); content = content.replaceAll("_KDC_PORT_", String.valueOf(kdcPort)); if (setting.allowTcp()) { content = content.replaceAll("#_KDC_TCP_PORT_", "kdc_tcp_port = " + setting.getKdcTcpPort()); } if (setting.allowUdp()) { content = content.replaceAll("#_KDC_UDP_PORT_", "kdc_udp_port = " + setting.getKdcUdpPort()); } int udpLimit = setting.allowUdp() ? 4096 : 1; content = content.replaceAll("_UDP_LIMIT_", String.valueOf(udpLimit)); this.confFile = new File(kdcServer.getWorkDir(), KRB5_CONF_FILE); IOUtil.writeFile(content, confFile); return confFile; }
private File generateConfFile() throws IOException { KdcSetting setting = kdcServer.getKdcSetting(); String resourcePath = setting.allowUdp() ? "/krb5_udp-template.conf" : "/krb5-template.conf"; String templateContent; try (InputStream templateResource = getClass().getResourceAsStream(resourcePath)) { templateContent = IOUtil.readInput(templateResource); } String content = templateContent; content = content.replaceAll("_REALM_", "" + setting.getKdcRealm()); int kdcPort = setting.allowUdp() ? setting.getKdcUdpPort() : setting.getKdcTcpPort(); content = content.replaceAll("_KDC_PORT_", String.valueOf(kdcPort)); if (setting.allowTcp()) { content = content.replaceAll("#_KDC_TCP_PORT_", "kdc_tcp_port = " + setting.getKdcTcpPort()); } if (setting.allowUdp()) { content = content.replaceAll("#_KDC_UDP_PORT_", "kdc_udp_port = " + setting.getKdcUdpPort()); } int udpLimit = setting.allowUdp() ? 4096 : 1; content = content.replaceAll("_UDP_LIMIT_", String.valueOf(udpLimit)); this.confFile = new File(kdcServer.getWorkDir(), KRB5_CONF_FILE); IOUtil.writeFile(content, confFile); return confFile; }