use of org.infinispan.cli.impl.SSLContextSettings in project infinispan by infinispan.
the class CLI method exec.
@Override
public CommandResult exec(ContextAwareCommandInvocation invocation) {
if (help) {
invocation.println(invocation.getHelpInfo());
return CommandResult.SUCCESS;
}
if (version) {
invocation.printf("%s CLI %s\n", org.infinispan.commons.util.Version.getBrandName(), org.infinispan.commons.util.Version.getBrandVersion());
invocation.printf("Copyright (C) Red Hat Inc. and/or its affiliates and other contributors\n");
invocation.printf("License Apache License, v. 2.0. http://www.apache.org/licenses/LICENSE-2.0\n");
return CommandResult.SUCCESS;
}
context = invocation.getContext();
if (propertyMap != null) {
propertyMap.forEach(context.getProperties()::putIfAbsent);
}
if (properties != null) {
try (Reader r = Files.newBufferedReader(Paths.get(properties))) {
Properties loaded = new Properties();
loaded.load(r);
loaded.forEach(context.getProperties()::putIfAbsent);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
String sslTrustStore = truststore != null ? truststore.getAbsolutePath() : context.getProperty(Context.Property.TRUSTSTORE);
if (sslTrustStore != null) {
String sslTrustStorePassword = truststorePassword != null ? truststorePassword : context.getProperty(Context.Property.TRUSTSTORE_PASSWORD);
try (FileInputStream f = new FileInputStream(sslTrustStore)) {
KeyStore keyStore = KeyStoreUtil.loadKeyStore(ProviderUtil.INSTALLED_PROVIDERS, null, f, sslTrustStore, sslTrustStorePassword != null ? sslTrustStorePassword.toCharArray() : null);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
HostnameVerifier verifier = hostnameVerifier != null ? new RegexHostnameVerifier(hostnameVerifier) : null;
SSLContextSettings sslContext = SSLContextSettings.getInstance("TLS", null, trustManagerFactory.getTrustManagers(), null, verifier);
context.setSslContext(sslContext);
} catch (Exception e) {
invocation.getShell().writeln(MSG.keyStoreError(sslTrustStore, e));
return CommandResult.FAILURE;
}
} else if (trustAll || Boolean.parseBoolean(context.getProperty(Context.Property.TRUSTALL))) {
SSLContextSettings sslContext = SSLContextSettings.getInstance("TLS", null, new TrustManager[] { new ZeroSecurityTrustManager() }, null, new ZeroSecurityHostnameVerifier());
context.setSslContext(sslContext);
}
String connectionString = connect != null ? connect : context.getProperty(Context.Property.AUTOCONNECT_URL);
if (connectionString != null) {
context.connect(null, connectionString);
}
if (file != null) {
return batch(file.getAbsolutePath(), invocation.getShell());
} else {
if (context.getProperty(Context.Property.AUTOEXEC) != null) {
batch(context.getProperty(Context.Property.AUTOEXEC), invocation.getShell());
}
return interactive(invocation.getShell());
}
}
Aggregations