Java Code Examples for org.apache.solr.client.solrj.impl.HttpClientUtil#setSocketFactoryRegistryProvider()

The following examples show how to use org.apache.solr.client.solrj.impl.HttpClientUtil#setSocketFactoryRegistryProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNoSsl() throws Exception {
  final SSLTestConfig sslConfig = new SSLTestConfig(false, false);
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "http");
  checkClusterWithNodeReplacement(sslConfig);
}
 
Example 2
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNoSslButSillyClientAuth() throws Exception {
  // this combination doesn't really make sense, since ssl==false the clientauth option will be ignored
  // but we test it anyway for completeness of sanity checking the behavior of code that looks at those
  // options.
  final SSLTestConfig sslConfig = new SSLTestConfig(false, true);
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "http");
  checkClusterWithNodeReplacement(sslConfig);
}
 
Example 3
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testSslAndNoClientAuth() throws Exception {
  final SSLTestConfig sslConfig = new SSLTestConfig(true, false);
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "https");
  checkClusterWithNodeReplacement(sslConfig);
}
 
Example 4
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testSslAndClientAuth() throws Exception {
  assumeFalse("SOLR-9039: SSL w/clientAuth does not work on MAC_OS_X", Constants.MAC_OS_X);
  
  final SSLTestConfig sslConfig = new SSLTestConfig(true, true);

  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "https");
  checkClusterWithNodeReplacement(sslConfig);
}
 
Example 5
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testSslWithCheckPeerName() throws Exception {
  final SSLTestConfig sslConfig = new SSLTestConfig(true, false, true);
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "https");
  checkClusterWithNodeReplacement(sslConfig);
}
 
Example 6
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupTestCases() {
  initialRootLogLevel = StartupLoggingUtils.getLogLevelString();
  initClassLogLevels();
  resetExceptionIgnores();
  
  testExecutor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
      15L, TimeUnit.SECONDS,
      new SynchronousQueue<>(),
      new SolrNamedThreadFactory("testExecutor"),
      true);

  // set solr.install.dir needed by some test configs outside of the test sandbox (!)
  System.setProperty("solr.install.dir", ExternalPaths.SOURCE_HOME);
  // not strictly needed by this class at this point in the control lifecycle, but for
  // backcompat create it now in case any third party tests expect initCoreDataDir to be
  // non-null after calling setupTestCases()
  initAndGetDataDir();

  System.setProperty("solr.zkclienttimeout", "90000"); 
  
  System.setProperty("solr.httpclient.retries", "1");
  System.setProperty("solr.retries.on.forward", "1");
  System.setProperty("solr.retries.to.followers", "1");

  System.setProperty("solr.v2RealPath", "true");
  System.setProperty("zookeeper.forceSync", "no");
  System.setProperty("jetty.testMode", "true");
  System.setProperty("enable.update.log", usually() ? "true" : "false");
  System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
  System.setProperty("solr.clustering.enabled", "false");
  System.setProperty("solr.peerSync.useRangeVersions", String.valueOf(random().nextBoolean()));
  System.setProperty("solr.cloud.wait-for-updates-with-stale-state-pause", "500");

  System.setProperty("pkiHandlerPrivateKeyPath", SolrTestCaseJ4.class.getClassLoader().getResource("cryptokeys/priv_key512_pkcs8.pem").toExternalForm());
  System.setProperty("pkiHandlerPublicKeyPath", SolrTestCaseJ4.class.getClassLoader().getResource("cryptokeys/pub_key512.der").toExternalForm());

  System.setProperty(ZK_WHITELIST_PROPERTY, "*");
  startTrackingSearchers();
  ignoreException("ignore_exception");
  newRandomConfig();

  sslConfig = buildSSLConfig();
  // based on randomized SSL config, set SocketFactoryRegistryProvider appropriately
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  if(isSSLMode()) {
    // SolrCloud tests should usually clear this
    System.setProperty("urlScheme", "https");
  }
}
 
Example 7
Source File: TestMiniSolrCloudClusterSSL.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Sanity check that our test scaffolding for validating SSL peer names fails when it should */
public void testSslWithInvalidPeerName() throws Exception {
  // NOTE: first initialize the cluster w/o peer name checks, which means our server will use
  // certs with a bogus hostname/ip and clients shouldn't care...
  final SSLTestConfig sslConfig = new SSLTestConfig(true, false, false);
  HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
  Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
  System.setProperty(ZkStateReader.URL_SCHEME, "https");
  final JettyConfig config = JettyConfig.builder().withSSLConfig(sslConfig.buildServerSSLConfig()).build();
  final MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), config);
  try {
    checkClusterWithCollectionCreations(cluster, sslConfig);
    
    // now initialize a client that still uses the existing SSLContext/Provider, so it will accept
    // our existing certificate, but *does* care about validating the peer name
    System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true");
    HttpClientUtil.resetHttpClientBuilder();
    Http2SolrClient.resetSslContextFactory();

    // and validate we get failures when trying to talk to our cluster...
    final List<JettySolrRunner> jettys = cluster.getJettySolrRunners();
    for (JettySolrRunner jetty : jettys) {
      final String baseURL = jetty.getBaseUrl().toString();
      // verify new solr clients validate peer name and can't talk to this server
      Exception ex = expectThrows(SolrServerException.class, () -> {
          try (HttpSolrClient client = getRandomizedHttpSolrClient(baseURL)) {
            CoreAdminRequest req = new CoreAdminRequest();
            req.setAction( CoreAdminAction.STATUS );
            client.request(req);
          }
        });
      assertTrue("Expected an root cause SSL Exception, got: " + ex.toString(),
                 ex.getCause() instanceof SSLException);
    }
  } finally {
    cluster.shutdown();
  }


  
}