Example usage for org.apache.http.conn.util PublicSuffixMatcherLoader getDefault

List of usage examples for org.apache.http.conn.util PublicSuffixMatcherLoader getDefault

Introduction

In this page you can find the example usage for org.apache.http.conn.util PublicSuffixMatcherLoader getDefault.

Prototype

public static PublicSuffixMatcher getDefault() 

Source Link

Usage

From source file:org.aevans.goat.net.SSLStrategyGetter.java

public static SchemeIOSessionStrategy getSchemeIOSessionStrategy() {
    DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(
            PublicSuffixMatcherLoader.getDefault());
    SchemeIOSessionStrategy sioss = new SchemeIOSessionStrategy() {

        @Override//from   w  w w  .j  ava2 s. c om
        public boolean isLayeringRequired() {
            return true;
        }

        @Override
        public IOSession upgrade(final HttpHost host, final IOSession iosession) throws IOException {

            SSLSetupHandler handler = new SSLSetupHandler() {

                @Override
                public void initalize(SSLEngine sslengine) throws SSLException {
                }

                @Override
                public void verify(IOSession iosession, SSLSession sslsession) throws SSLException {
                    if (!hostnameVerifier.verify(host.getHostName(), sslsession)) {
                        final java.security.cert.Certificate[] certs = sslsession.getPeerCertificates();
                        final X509Certificate x509 = (X509Certificate) certs[0];
                        final X500Principal x500Principal = x509.getSubjectX500Principal();
                        throw new SSLPeerUnverifiedException("Host name '" + host.getHostName()
                                + "' does not match " + "the certificate subject provided by the peer ("
                                + x500Principal.toString() + ")");
                    }
                }

            };
            SSLBufferManagementStrategy sslbm = new ReleasableSSLBufferManagementStrategy();
            SSLIOSession ssio = new SSLIOSession(iosession, SSLMode.CLIENT, host, SSLContexts.createDefault(),
                    handler, sslbm);
            iosession.setAttribute(SSLIOSession.SESSION_KEY, ssio);
            ssio.initialize();
            return ssio;
        }

    };

    return sioss;
}

From source file:com.mirth.connect.util.HttpUtil.java

/**
 * Applies global settings to any Apache HttpComponents HttpClientBuilder.<br/>
 * <br/>/*from ww  w.  java2s .c  o  m*/
 * As of version 4.5, the default cookie specifications used by Apache HttpClient are more
 * strict in order to abide by RFC 6265. As part of this change, domain parameters in cookies
 * are checked against a public ICANN suffix matcher before they are allowed to be added to
 * outgoing requests. However this may cause clients to fail to connect if they are using custom
 * hostnames like "mycustomhost". To prevent that, we're building our own CookieSpecProvider
 * registry, and setting that on the client. Look at CookieSpecRegistries to see how the default
 * registry is built. The only difference now is that DefaultCookieSpecProvider is being
 * constructed without a PublicSuffixMatcher.
 */
public static void configureClientBuilder(HttpClientBuilder clientBuilder) {
    PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault();
    clientBuilder.setPublicSuffixMatcher(publicSuffixMatcher);
    RegistryBuilder<CookieSpecProvider> cookieSpecBuilder = RegistryBuilder.<CookieSpecProvider>create();
    CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider();
    CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
    CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
    cookieSpecBuilder.register(CookieSpecs.DEFAULT, defaultProvider);
    cookieSpecBuilder.register("best-match", defaultProvider);
    cookieSpecBuilder.register("compatibility", defaultProvider);
    cookieSpecBuilder.register(CookieSpecs.STANDARD, laxStandardProvider);
    cookieSpecBuilder.register(CookieSpecs.STANDARD_STRICT, strictStandardProvider);
    cookieSpecBuilder.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider());
    cookieSpecBuilder.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
    clientBuilder.setDefaultCookieSpecRegistry(cookieSpecBuilder.build());
}

From source file:com.machinepublishers.jbrowserdriver.LaxCookieSpecProvider.java

@Override
public CookieSpec create(final HttpContext context) {
    if (cookieSpec == null) {
        synchronized (this) {
            if (cookieSpec == null) {
                try {
                    Constructor constructor = RFC2965Spec.class.getDeclaredConstructor(boolean.class,
                            CommonCookieAttributeHandler[].class);
                    constructor.setAccessible(true);
                    final RFC2965Spec strict = (RFC2965Spec) constructor.newInstance(false,
                            (Object) new CommonCookieAttributeHandler[] { new RFC2965VersionAttributeHandler(),
                                    new BasicPathHandler() {
                                        @Override
                                        public void validate(final Cookie cookie, final CookieOrigin origin)
                                                throws MalformedCookieException {
                                            // No validation
                                        }
                                    }, new PublicSuffixFilter(PublicSuffixDomainFilter
                                            .decorate(new RFC2965DomainAttributeHandler() {
                                                @Override
                                                public void validate(Cookie cookie, CookieOrigin origin)
                                                        throws MalformedCookieException {
                                                    // No validation
                                                }
                                            }, PublicSuffixMatcherLoader.getDefault())),
                                    new RFC2965PortAttributeHandler(), new BasicMaxAgeHandler(),
                                    new BasicSecureHandler(), new BasicCommentHandler(),
                                    new RFC2965CommentUrlAttributeHandler(),
                                    new RFC2965DiscardAttributeHandler() });
                    constructor = RFC2109Spec.class.getDeclaredConstructor(boolean.class,
                            CommonCookieAttributeHandler[].class);
                    constructor.setAccessible(true);
                    final RFC2109Spec obsoleteStrict = (RFC2109Spec) constructor.newInstance(false,
                            (Object) new CommonCookieAttributeHandler[] { new RFC2109VersionHandler(),
                                    new BasicPathHandler() {
                                        @Override
                                        public void validate(final Cookie cookie, final CookieOrigin origin)
                                                throws MalformedCookieException {
                                            // No validation
                                        }
                                    }, new PublicSuffixFilter(
                                            PublicSuffixDomainFilter.decorate(new RFC2109DomainHandler() {
                                                @Override
                                                public void validate(Cookie cookie, CookieOrigin origin)
                                                        throws MalformedCookieException {
                                                    // No validation
                                                }
                                            }, PublicSuffixMatcherLoader.getDefault())),
                                    new BasicMaxAgeHandler(), new BasicSecureHandler(),
                                    new BasicCommentHandler() });
                    constructor = NetscapeDraftSpec.class
                            .getDeclaredConstructor(CommonCookieAttributeHandler[].class);
                    constructor.setAccessible(true);
                    final NetscapeDraftSpec netscapeDraft = (NetscapeDraftSpec) constructor
                            .newInstance((Object) new CommonCookieAttributeHandler[] { new PublicSuffixFilter(
                                    PublicSuffixDomainFilter.decorate(new BasicDomainHandler() {
                                        @Override
                                        public void validate(Cookie cookie, CookieOrigin origin)
                                                throws MalformedCookieException {
                                            // No validation 
                                        }
                                    }, PublicSuffixMatcherLoader.getDefault())), new BasicPathHandler() {
                                        @Override
                                        public void validate(final Cookie cookie, final CookieOrigin origin)
                                                throws MalformedCookieException {
                                            // No validation
                                        }
                                    }, new BasicSecureHandler(), new BasicCommentHandler(),
                                    new BasicExpiresHandler(DATE_PATTERNS) });
                    constructor = DefaultCookieSpec.class.getDeclaredConstructor(RFC2965Spec.class,
                            RFC2109Spec.class, NetscapeDraftSpec.class);
                    constructor.setAccessible(true);
                    this.cookieSpec = (DefaultCookieSpec) constructor.newInstance(strict, obsoleteStrict,
                            netscapeDraft);
                } catch (Throwable t) {
                    Util.handleException(t);
                }/* w w  w  . j  a  v a  2s  . c  o  m*/
            }
        }
    }
    return this.cookieSpec;
}

From source file:com.ibm.og.client.ApacheClient.java

private ConnectionSocketFactory createSslConnectionSocketFactory() {
    final SSLSocketFactory sslSocketFactory = createSSLSocketFactory();
    String[] configuredProtocols = null;
    String[] configuredCipherSuites = null;
    if (this.protocols != null) {
        configuredProtocols = Iterables.toArray(this.protocols, String.class);
    }//ww  w . j a v  a2  s  .c o  m
    if (this.cipherSuites != null) {
        final List<String> supportedCipherSuites = ImmutableList
                .copyOf(sslSocketFactory.getSupportedCipherSuites());
        for (final String cipherSuite : this.cipherSuites) {
            checkArgument(supportedCipherSuites.contains(cipherSuite), "Unsupported cipher suite [%s]",
                    cipherSuite);
        }

        configuredCipherSuites = Iterables.toArray(this.cipherSuites, String.class);
    }
    final PublicSuffixMatcher suffixMatcher = PublicSuffixMatcherLoader.getDefault();
    final HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;

    return new SSLConnectionSocketFactory(sslSocketFactory, configuredProtocols, configuredCipherSuites,
            hostnameVerifier);

}

From source file:org.apache.http.conn.ssl.SSLConnectionSocketFactory.java

/**
 * @since 4.4/*from w ww.j av  a 2s .  co  m*/
 */
public static HostnameVerifier getDefaultHostnameVerifier() {
    return new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault());
}