当前位置: 首页>>代码示例>>Java>>正文


Java NoopHostnameVerifier.INSTANCE属性代码示例

本文整理汇总了Java中org.apache.http.conn.ssl.NoopHostnameVerifier.INSTANCE属性的典型用法代码示例。如果您正苦于以下问题:Java NoopHostnameVerifier.INSTANCE属性的具体用法?Java NoopHostnameVerifier.INSTANCE怎么用?Java NoopHostnameVerifier.INSTANCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.http.conn.ssl.NoopHostnameVerifier的用法示例。


在下文中一共展示了NoopHostnameVerifier.INSTANCE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restTemplate

@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
开发者ID:borysfan,项目名称:websocket-poc,代码行数:19,代码来源:App.java

示例2: configureInsecureSSL

/**
 * Allow SSL connections to utilize untrusted certificates
 * 
 * @param httpClientBuilder
 * @throws MojoExecutionException
 */
private void configureInsecureSSL(HttpClientBuilder httpClientBuilder) throws MojoExecutionException {
    try {
        SSLContextBuilder sslBuilder = new SSLContextBuilder();

        // Accept all Certificates
        sslBuilder.loadTrustMaterial(null, AcceptAllTrustStrategy.INSTANCE);

        SSLContext sslContext = sslBuilder.build();

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
                NoopHostnameVerifier.INSTANCE);
        httpClientBuilder.setSSLSocketFactory(sslsf);
    } catch (Exception e) {
        throw new MojoExecutionException("Error setting insecure SSL configuration", e);
    }
}
 
开发者ID:sabre1041,项目名称:jenkinsfile-maven-plugin,代码行数:22,代码来源:ValidateJenkinsfileMojo.java

示例3: TankHttpClient4

/**
 * no-arg constructor for client
 */
public TankHttpClient4() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
    } catch (Exception e) {
        LOG.error("Error setting accept all: " + e, e);
    }

    httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
    requestConfig = RequestConfig.custom().setSocketTimeout(30000)
    		.setConnectTimeout(30000)
    		.setCircularRedirectsAllowed(true)
    		.setAuthenticationEnabled(true)
    		.setRedirectsEnabled(true)
    		.setCookieSpec(CookieSpecs.STANDARD)
            .setMaxRedirects(100).build();

    // Make sure the same context is used to execute logically related
    // requests
    context = HttpClientContext.create();
    context.setCredentialsProvider(new BasicCredentialsProvider());
    context.setCookieStore(new BasicCookieStore());
    context.setRequestConfig(requestConfig);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:28,代码来源:TankHttpClient4.java

示例4: getHostnameVerifier

/**
 * Creates the {@code HostnameVerifier} given the provided {@code verification}.
 *
 * @param verification The intended hostname verification action.
 * @return A verifier for the request verification.
 * @throws IllegalArgumentException if the provided verification cannot be handled.
 */
HostnameVerifier getHostnameVerifier(HostnameVerification verification) {
  // Normally, the configuration logic would give us a default of STRICT if it was not
  // provided by the user. It's easy for us to do a double-check.
  if (verification == null) {
    verification = HostnameVerification.STRICT;
  }
  switch (verification) {
  case STRICT:
    return SSLConnectionSocketFactory.getDefaultHostnameVerifier();
  case NONE:
    return NoopHostnameVerifier.INSTANCE;
  default:
    throw new IllegalArgumentException("Unhandled HostnameVerification: "
        + hostnameVerification);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:AvaticaCommonsHttpClientImpl.java

示例5: getHttpsClient

private CloseableHttpClient getHttpsClient()
{
    try
    {
        RequestConfig config = RequestConfig.custom().setSocketTimeout( 5000 ).setConnectTimeout( 5000 ).build();

        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial( null, ( TrustStrategy ) ( x509Certificates, s ) -> true );
        SSLConnectionSocketFactory sslSocketFactory =
                new SSLConnectionSocketFactory( sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE );

        return HttpClients.custom().setDefaultRequestConfig( config ).setSSLSocketFactory( sslSocketFactory )
                          .build();
    }
    catch ( Exception e )
    {
        LOGGER.error( e.getMessage() );
    }

    return HttpClients.createDefault();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:21,代码来源:RestServiceImpl.java

示例6: createHttpClient

/**
 * Create the HTTP clean with basic authentication mechanism using specified
 * credentials
 * 
 * @param username
 *            Authentication username
 * @param password
 *            Authentication password
 * @return
 */
protected static CloseableHttpClient createHttpClient(String username, String password) {
	SSLContext sslContext = createSslContext();
	HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
	SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);

	CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

	Header header = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");
	List<Header> headers = Arrays.asList(header);

	return HttpClients.custom()
			.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
			.setSSLSocketFactory(sslSocketFactory)
			.setDefaultCredentialsProvider(credentialsProvider)
			.setDefaultHeaders(headers)
			.build();
}
 
开发者ID:device42,项目名称:rundeck-device42-nodes-plugin,代码行数:28,代码来源:AbstractAsynchronousRestClient.java

示例7: getRestTemplateAllowingSelfSigned

private RestTemplate getRestTemplateAllowingSelfSigned() {
    try {
        final SSLContext allowSelfSignedSslContext = SSLContexts
                .custom()
                .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                .build();
        final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                allowSelfSignedSslContext,
                NoopHostnameVerifier.INSTANCE
        );
        final CloseableHttpClient httpClient = HttpClientBuilder
                .create()
                .setSSLSocketFactory(sslsf)
                .build();
        return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
    } catch (final Exception exception) {
        throw new SQCompanionException("Can't initialize RestTemplate with Self Signed https support", exception);
    }
}
 
开发者ID:Consdata,项目名称:sonarqube-companion,代码行数:19,代码来源:RestTemplateConfiguration.java

示例8: getAuthenticatedClient

public CloseableHttpClient getAuthenticatedClient() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(new TrustSelfSignedStrategy());
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                builder.build(), NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom()
                .setSSLSocketFactory(sslsf)
                .setDefaultCredentialsProvider(getCredentialsProvider())
                .build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
        Logger.getLogger(AuthHandler.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:curly,代码行数:16,代码来源:AuthHandler.java

示例9: createHttpClient

private static CloseableHttpClient createHttpClient(String host, int port, String username, String password) {
    SSLContext sslContext = org.apache.http.ssl.SSLContexts.createDefault();
                SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);

    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", sslConnectionSocketFactory)
                    .build();
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, port, MANAGEMENT_REALM, AuthSchemes.DIGEST),
                    new UsernamePasswordCredentials(username, password));

    return HttpClientBuilder.create()
                    .setConnectionManager(new PoolingHttpClientConnectionManager(registry))
                    .setRetryHandler(new StandardHttpRequestRetryHandler(5, true))
                    .setDefaultCredentialsProvider(credentialsProvider)
                    .build();
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:18,代码来源:HttpManagementInterface.java

示例10: createHttpClient

private static CloseableHttpClient createHttpClient(String host, int port, String username, String password) {
    try {
        SSLContext sslContext = SSLContexts.createDefault();
        SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("https", sslConnectionSocketFactory)
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .build();
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(host, port, MANAGEMENT_REALM, AuthSchemes.DIGEST),
                new UsernamePasswordCredentials(username, password));
        PoolingHttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager(registry);
        HttpClientBuilder.create().setConnectionManager(connectionPool).build();
        return HttpClientBuilder.create()
                .setConnectionManager(connectionPool)
                .setRetryHandler(new StandardHttpRequestRetryHandler(5, true))
                .setDefaultCredentialsProvider(credsProvider).build();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:HttpGenericOperationUnitTestCase.java

示例11: httpClient

@Bean
public CloseableHttpClient httpClient() {
    try {
        //new ClassPathResource("").getURL()
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(keyStore, keyPassword.toCharArray(),
                        new TrustSelfSignedStrategy())
                .build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                sslcontext, NoopHostnameVerifier.INSTANCE);

        return HttpClients.custom()
                .setSSLSocketFactory(sslSocketFactory)
                .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                .build();
    } catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        throw new BeanCreationException("Failed to create http client for ssl connection", e);
    }
}
 
开发者ID:christophd,项目名称:citrus-simulator,代码行数:20,代码来源:HttpClientConfig.java

示例12: hostnameVerifier

@ConditionalOnMissingBean(name = "hostnameVerifier")
@Bean
public HostnameVerifier hostnameVerifier() {
    if (casProperties.getHttpClient().getHostNameVerifier().equalsIgnoreCase("none")) {
        return NoopHostnameVerifier.INSTANCE;
    }
    return new DefaultHostnameVerifier();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:8,代码来源:CasCoreHttpConfiguration.java

示例13: sslSocketFactory

@Bean(name = "sslSocketFactory")
public SSLConnectionSocketFactory sslSocketFactory() {
    final String keystoreLocation = environment.getRequiredProperty("keystore.location");
    final String trustStoreLocation = environment.getRequiredProperty("trust.store.location");
    final String keystorePassword = environment.getRequiredProperty("keystore.password");
    final String trustStorePassword = environment.getRequiredProperty("trust.store.password");

    try {
        KeyStore clientStore = KeyStore.getInstance("JKS");
        clientStore.load(new FileInputStream(keystoreLocation), keystorePassword.toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(clientStore, keystorePassword.toCharArray());

        KeyStore trustStore = KeyStore.getInstance("JKS");
        trustStore.load(new FileInputStream(trustStoreLocation), trustStorePassword.toCharArray());
        trustStore.getCertificate("orchestrator");

        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);

        Certificate cert = trustStore.getCertificate("orchestrator");

        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(cert.getEncoded()));

        SSLContext context = SSLContext.getInstance("TLSv1");
        context.init(new KeyManager[] { new FilteredKeyManager((X509KeyManager)kmf.getKeyManagers()[0], x509Certificate, "orchestrator") },
                trustManagerFactory.getTrustManagers(), new SecureRandom());

        SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);

        return socketFactory;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:39,代码来源:ApiWrapperConfig.java

示例14: createSession

public void createSession(String alias, String url, Map<String, String> headers, Authentication auth, String verify,
		Boolean debug, String loggerClass, String password, boolean verifyHost, boolean selfSigned, Proxy proxy) {

	HostnameVerifier defaultHostnameVerifier = verifyHost ? null : NoopHostnameVerifier.INSTANCE;
	TrustStrategy trustStrategy = selfSigned ? new TrustSelfSignedStrategy() : null;

	if (!loggerClass.isEmpty()) {
		System.setProperty("org.apache.commons.logging.Log", loggerClass);
		System.setProperty("org.apache.commons.logging.robotlogger.log.org.apache.http", debug ? "DEBUG" : "INFO");
	}
	HttpHost target;
	try {
		target = URIUtils.extractHost(new URI(url));
	} catch (URISyntaxException e) {
		throw new RuntimeException("Parsing of URL failed. Error message: " + e.getMessage());
	}
	Session session = new Session();
	session.setProxy(proxy);
	session.setContext(this.createContext(auth, target));
	session.setClient(this.createHttpClient(auth, verify, target, false, password, null, null, proxy));
	session.setUrl(url);
	session.setHeaders(headers);
	session.setHttpHost(target);
	session.setVerify(verify);
	session.setAuthentication(auth);
	session.setPassword(password);
	session.setHostnameVerifier(defaultHostnameVerifier);
	session.setTrustStrategy(trustStrategy);
	sessions.put(alias, session);
}
 
开发者ID:Hi-Fi,项目名称:httpclient,代码行数:30,代码来源:RestClient.java

示例15: createHttpClient

private CloseableHttpClient createHttpClient(boolean ignoreCert) {
    try {
        RequestConfig requestConfig = RequestConfig.custom()
                .setCookieSpec(CookieSpecs.STANDARD)
                .build();

        CloseableHttpClient client;

        if (ignoreCert) {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(new KeyManager[0], new TrustManager[]{new NoopTrustManager()}, new SecureRandom());
            SSLContext.setDefault(sslContext);

            SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                    sslContext, NoopHostnameVerifier.INSTANCE);
            client = HttpClients.custom()
                    .disableRedirectHandling()
                    .setDefaultRequestConfig(requestConfig)
                    .setSSLSocketFactory(sslSocketFactory)
                    .build();
        } else {
            client = HttpClientBuilder.create()
                    .disableRedirectHandling()
                    .setDefaultRequestConfig(requestConfig)
                    .build();
        }

        return client;
    } catch (Throwable ex) {
        throw new RuntimeException(String.format(
                "Failed to create http client (ignoreCert = %s)",
                ignoreCert), ex);
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:34,代码来源:HttpRequest.java


注:本文中的org.apache.http.conn.ssl.NoopHostnameVerifier.INSTANCE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。