本文整理了Java中com.networknt.config.Config.getInputStreamFromFile()
方法的一些代码示例,展示了Config.getInputStreamFromFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.getInputStreamFromFile()
方法的具体详情如下:
包路径:com.networknt.config.Config
类名称:Config
方法名:getInputStreamFromFile
暂无
代码示例来源:origin: networknt/light-4j
private static KeyStore loadKeyStore() {
String name = config.getKeystoreName();
try (InputStream stream = Config.getInstance().getInputStreamFromFile(name)) {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, ((String) secret.get(SecretConstants.SERVER_KEYSTORE_PASS)).toCharArray());
return loadedKeystore;
} catch (Exception e) {
logger.error("Unable to load keystore " + name, e);
throw new RuntimeException("Unable to load keystore " + name, e);
}
}
代码示例来源:origin: networknt/light-4j
protected static KeyStore loadTrustStore() {
String name = config.getTruststoreName();
try (InputStream stream = Config.getInstance().getInputStreamFromFile(name)) {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, ((String) secret.get(SecretConstants.SERVER_TRUSTSTORE_PASS)).toCharArray());
return loadedKeystore;
} catch (Exception e) {
logger.error("Unable to load truststore " + name, e);
throw new RuntimeException("Unable to load truststore " + name, e);
}
}
代码示例来源:origin: networknt/light-4j
private static KeyStore loadKeyStore(final String name, final char[] password) throws IOException {
final InputStream stream = Config.getInstance().getInputStreamFromFile(name);
if(stream == null) {
throw new RuntimeException("Could not load keystore");
}
try {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, password);
return loadedKeystore;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
throw new IOException(String.format("Unable to load KeyStore %s", name), e);
} finally {
IoUtils.safeClose(stream);
}
}
代码示例来源:origin: networknt/light-4j
/**
* Get private key from java key store
*
* @param filename Key store file name
* @param password Key store password
* @param key key name in keystore
* @return A PrivateKey object
*/
private static PrivateKey getPrivateKey(String filename, String password, String key) {
if(logger.isDebugEnabled()) logger.debug("filename = " + filename + " key = " + key);
PrivateKey privateKey = null;
try {
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(Config.getInstance().getInputStreamFromFile(filename),
password.toCharArray());
privateKey = (PrivateKey) keystore.getKey(key,
password.toCharArray());
} catch (Exception e) {
logger.error("Exception:", e);
}
if (privateKey == null) {
logger.error("Failed to retrieve private key from keystore");
}
return privateKey;
}
代码示例来源:origin: networknt/light-4j
X509Certificate cert = null;
try {
inStream = Config.getInstance().getInputStreamFromFile(filename);
if (inStream != null) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
代码示例来源:origin: networknt/light-4j
/**
* We can get it from server module but we don't want mutual dependency. So
* get it from config and keystore directly
*
* @return String TLS server certificate finger print
*/
private String getServerTlsFingerPrint() {
String fingerPrint = null;
Map<String, Object> serverConfig = Config.getInstance().getJsonMapConfigNoCache("server");
Map<String, Object> secretConfig = Config.getInstance().getJsonMapConfigNoCache("secret");
// load keystore here based on server config and secret config
String keystoreName = (String)serverConfig.get("keystoreName");
String serverKeystorePass = (String)secretConfig.get("serverKeystorePass");
if(keystoreName != null) {
try (InputStream stream = Config.getInstance().getInputStreamFromFile(keystoreName)) {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, serverKeystorePass.toCharArray());
X509Certificate cert = (X509Certificate)loadedKeystore.getCertificate("server");
if(cert != null) {
fingerPrint = FingerPrintUtil.getCertFingerPrint(cert);
} else {
logger.error("Unable to find the certificate with alias name as server in the keystore");
}
} catch (Exception e) {
logger.error("Unable to load server keystore ", e);
}
}
return fingerPrint;
}
}
代码示例来源:origin: com.networknt/client
private static KeyStore loadKeyStore(final String name, final char[] password) throws IOException {
final InputStream stream = Config.getInstance().getInputStreamFromFile(name);
if(stream == null) {
throw new RuntimeException("Could not load keystore");
}
try {
KeyStore loadedKeystore = KeyStore.getInstance("JKS");
loadedKeystore.load(stream, password);
return loadedKeystore;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
throw new IOException(String.format("Unable to load KeyStore %s", name), e);
} finally {
IoUtils.safeClose(stream);
}
}
代码示例来源:origin: com.networknt/security
/**
* Get private key from java key store
*
* @param filename Key store file name
* @param password Key store password
* @param key key name in keystore
* @return A PrivateKey object
*/
private static PrivateKey getPrivateKey(String filename, String password, String key) {
if(logger.isDebugEnabled()) logger.debug("filename = " + filename + " key = " + key);
PrivateKey privateKey = null;
try {
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(Config.getInstance().getInputStreamFromFile(filename),
password.toCharArray());
privateKey = (PrivateKey) keystore.getKey(key,
password.toCharArray());
} catch (Exception e) {
logger.error("Exception:", e);
}
if (privateKey == null) {
logger.error("Failed to retrieve private key from keystore");
}
return privateKey;
}
代码示例来源:origin: com.networknt/security
X509Certificate cert = null;
try {
inStream = Config.getInstance().getInputStreamFromFile(filename);
if (inStream != null) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
代码示例来源:origin: networknt/light-oauth2
@Override
public void onStartup() {
InputStream is = com.networknt.config.Config.getInstance().getInputStreamFromFile(CONFIG_NAME);
Config config = null;
if(is != null) {
内容来源于网络,如有侵权,请联系作者删除!