當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。